aboutsummaryrefslogtreecommitdiff
path: root/include/Version.hpp
blob: 57a53f5de81703f20cf5753f6b647386bb3de101 (plain)
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
#pragma once

#include <string>

namespace sibs
{
    enum class VersionOperation
    {
        NONE,
        LESS,
        LESS_EQUAL,
        EQUAL,
        GREATER,
        GREATER_EQUAL
    };
    
    const char* asString(VersionOperation operation);

    struct PackageVersion
    {
        int major;
        int minor;
        int patch;

        bool operator < (const PackageVersion &other) const
        {
            if(major < other.major) return true;
            if(major == other.major && minor < other.minor) return true;
            if(major == other.major && minor == other.minor && patch < other.patch) return true;
            return false;
        }

        bool operator == (const PackageVersion &other) const
        {
            return (major == other.major) && (minor == other.minor) && (patch == other.patch);
        }

        bool operator <= (const PackageVersion &other) const
        {
            return *this < other || *this == other;
        }

        std::string toString() const;
    };
    static_assert(sizeof(PackageVersion) == sizeof(int) * 3, "Expected PackageVersion to be the same size as 3 ints");

    struct PackageVersionRange
    {
        PackageVersionRange()
        {
            start = { 0, 0, 0 };
            end = { 0, 0, 0 };
            startDefined = false;
            endDefined = false;
            startOperation = VersionOperation::LESS;
            endOperation = VersionOperation::LESS;
        }

        bool isInRange(const PackageVersion &version) const;
        std::string toString() const;

        PackageVersion start;
        PackageVersion end;
        bool startDefined;
        bool endDefined;
        VersionOperation startOperation;
        VersionOperation endOperation;
    };
}