Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
version.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <optional>
7#include <string_view>
8
9#include <nlohmann/json_fwd.hpp>
10
11namespace zrythm::utils
12{
13
17namespace version_keys
18{
19using namespace std::literals;
20inline constexpr auto kMajor = "major"sv;
21inline constexpr auto kMinor = "minor"sv;
22inline constexpr auto kPatch = "patch"sv;
23}
24
28struct Version
29{
30 int major;
31 int minor;
32 std::optional<int> patch;
33
34 [[nodiscard]] constexpr bool operator== (const Version &other) const
35 {
36 return major == other.major && minor == other.minor
37 && patch.value_or (0) == other.patch.value_or (0);
38 }
39
40 [[nodiscard]] constexpr bool operator!= (const Version &other) const
41 {
42 return !(*this == other);
43 }
44
45 [[nodiscard]] constexpr bool operator< (const Version &other) const
46 {
47 if (major != other.major)
48 return major < other.major;
49 if (minor != other.minor)
50 return minor < other.minor;
51 auto this_patch = patch.value_or (0);
52 auto other_patch = other.patch.value_or (0);
53 return this_patch < other_patch;
54 }
55
56 [[nodiscard]] constexpr bool operator> (const Version &other) const
57 {
58 return other < *this;
59 }
60
61 [[nodiscard]] constexpr bool operator<= (const Version &other) const
62 {
63 return !(other < *this);
64 }
65
66 [[nodiscard]] constexpr bool operator>= (const Version &other) const
67 {
68 return !(*this < other);
69 }
70};
71
72void
73to_json (nlohmann::json &j, const Version &v);
74void
75from_json (const nlohmann::json &j, Version &v);
76
77} // namespace zrythm::utils
Key constants for version JSON serialization.
Definition version.h:18
String utilities.
Represents a semantic version with major, minor, and optional patch.
Definition version.h:29