summaryrefslogtreecommitdiff
path: root/source/core/slang-semantic-version.h
blob: d33116de62059b244af5d4991fc21606a1af66ed (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
// slang-semantic-version.h
#ifndef SLANG_SEMANTIC_VERSION_H
#define SLANG_SEMANTIC_VERSION_H

#include "../core/slang-basic.h"

namespace Slang
{

struct SemanticVersion
{
    typedef SemanticVersion ThisType;

    typedef uint64_t IntegerType;

    SemanticVersion():m_major(0), m_minor(0), m_patch(0) {}
    SemanticVersion(int inMajor, int inMinor = 0, int inPatch = 0):
        m_major(uint32_t(inMajor)),
        m_minor(uint16_t(inMinor)),
        m_patch(uint16_t(inPatch))
    {}

    void reset()
    {
        m_major = 0;
        m_minor = 0;
        m_patch = 0;
    }

        /// All zeros means nothing is set
    bool isSet() const { return m_major || m_minor || m_patch; }

    IntegerType toInteger() const { return (IntegerType(m_major) << 32) | (uint32_t(m_minor) << 16) | m_patch; }
    void setFromInteger(IntegerType v)
    {
        set(int(v >> 32), int((v >> 16) & 0xffff), int(v & 0xffff));
    }
    void set(int major, int minor, int patch = 0)
    {
        SLANG_ASSERT(major >= 0 && minor >=0 && patch >= 0);

        m_major = uint32_t(major);
        m_minor = uint16_t(minor);
        m_patch = uint16_t(patch);
    }

    static SlangResult parse(const UnownedStringSlice& value, SemanticVersion& outVersion);
    static SlangResult parse(const UnownedStringSlice& value, char separatorChar, SemanticVersion& outVersion);

    void append(StringBuilder& buf) const;

    bool operator>(const ThisType& rhs) const { return toInteger() > rhs.toInteger(); }
    bool operator>=(const ThisType& rhs) const { return toInteger() >= rhs.toInteger(); }

    bool operator<(const ThisType& rhs) const { return toInteger() < rhs.toInteger(); }
    bool operator<=(const ThisType& rhs) const { return toInteger() <= rhs.toInteger(); }

    bool operator==(const ThisType& rhs) const { return toInteger() == rhs.toInteger(); }
    bool operator!=(const ThisType& rhs) const { return toInteger() != rhs.toInteger(); }

    uint32_t m_major;
    uint16_t m_minor;
    uint16_t m_patch;
};

}
#endif