File: engine_version.hpp

package info (click to toggle)
libdjinterop 0.22.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,504 kB
  • sloc: cpp: 23,313; sql: 3,803; makefile: 3; sh: 2
file content (114 lines) | stat: -rw-r--r-- 3,189 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
    This file is part of libdjinterop.

    libdjinterop is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    libdjinterop is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with libdjinterop.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#ifndef DJINTEROP_ENGINE_ENGINE_VERSION_HPP
#define DJINTEROP_ENGINE_ENGINE_VERSION_HPP

#if __cplusplus < 201703L
#error This library needs at least a C++17 compliant compiler
#endif

#include <ostream>

#include <djinterop/config.hpp>
#include <djinterop/semantic_version.hpp>

namespace djinterop::engine
{
/// Enumeration of types of Engine database.
enum class engine_database_type
{
    /// Engine database for a desktop application, such as Engine Prime.
    desktop,

    /// Engine database for a hardware device, such as DJ players.
    os,
};

/// The `engine_version` struct represents a way to identify the version
/// of an Engine database.
struct DJINTEROP_PUBLIC engine_version
{
    /// Headline version.
    semantic_version version;

    /// Engine database type (Desktop or OS).
    engine_database_type database_type;

    /// Descriptive version name.
    const char* name;

    /// Database schema version.
    semantic_version schema_version;

    /// Test whether the version has a version 2 database schema.
    ///
    /// \return Returns `true` if the version has v2 schema, or `false` if not.
    [[nodiscard]] bool is_v2_schema() const noexcept
    {
        return schema_version.maj == 2;
    }
};

inline std::ostream& operator<<(std::ostream& os, const engine_version& v)
{
    os << v.name;
    return os;
}

inline bool operator==(const engine_version& a, const engine_version& b)
{
    return a.version == b.version && a.database_type == b.database_type;
}

inline bool operator!=(const engine_version& a, const engine_version& b)
{
    return !(a == b);
}

inline bool operator>=(const engine_version& a, const engine_version& b)
{
    if (a.version == b.version)
        return a.database_type >= b.database_type;
    return a.version >= b.version;
}

inline bool operator>(const engine_version& a, const engine_version& b)
{
    if (a.version == b.version)
        return a.database_type > b.database_type;
    return a.version > b.version;
}

inline bool operator<=(const engine_version& a, const engine_version& b)
{
    if (a.version == b.version)
        return a.database_type <= b.database_type;
    return a.version <= b.version;
}

inline bool operator<(const engine_version& a, const engine_version& b)
{
    if (a.version == b.version)
        return a.database_type < b.database_type;
    return a.version < b.version;
}

}  // namespace djinterop::engine

#endif  // DJINTEROP_ENGINE_ENGINE_VERSION_HPP