File: Version.h

package info (click to toggle)
pbbam 2.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 14,144 kB
  • sloc: cpp: 60,214; xml: 2,908; ansic: 660; sh: 275; python: 203; makefile: 187
file content (125 lines) | stat: -rw-r--r-- 3,159 bytes parent folder | download | duplicates (3)
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
115
116
117
118
119
120
121
122
123
124
125
#ifndef PBBAM_VERSION_H
#define PBBAM_VERSION_H

#include <pbbam/Config.h>

#include <iosfwd>
#include <stdexcept>
#include <string>
#include <tuple>

namespace PacBio {
namespace BAM {

class Version
{
public:
    static const Version Current;
    static const Version Minimum;

    constexpr Version() = default;

    Version(int major, int minor, int revision);

    // string must be "<major>.<minor>.<version>"
    explicit Version(const std::string& v);

    Version(const Version&) = default;
    Version(Version&&) noexcept = default;
    Version& operator=(const Version&) = default;
    Version& operator=(Version&&) noexcept = default;
    ~Version() = default;

    bool operator==(const Version& other) const noexcept;
    bool operator!=(const Version& other) const noexcept;
    bool operator<(const Version& other) const noexcept;
    bool operator<=(const Version& other) const noexcept;
    bool operator>(const Version& other) const noexcept;
    bool operator>=(const Version& other) const noexcept;

    std::string ToString() const;
    explicit operator std::string() const;

    int Major() const;
    int Minor() const;
    int Revision() const;

    Version& Major(int major);
    Version& Minor(int minor);
    Version& Revision(int revision);

private:
    void Check() const;

    int major_ = 0;
    int minor_ = 0;
    int revision_ = 0;
};

std::ostream& operator<<(std::ostream& out, const Version& version);

inline Version::Version(int major, int minor, int revision)
    : major_{major}, minor_{minor}, revision_{revision}
{
    Check();
}

inline bool Version::operator==(const Version& other) const noexcept
{
    return std::tie(major_, minor_, revision_) ==
           std::tie(other.major_, other.minor_, other.revision_);
}

inline bool Version::operator!=(const Version& other) const noexcept { return !(*this == other); }

inline bool Version::operator<(const Version& other) const noexcept
{
    return std::tie(major_, minor_, revision_) <
           std::tie(other.major_, other.minor_, other.revision_);
}
inline bool Version::operator<=(const Version& other) const noexcept { return !(*this > other); }

inline bool Version::operator>(const Version& other) const noexcept { return other < *this; }

inline bool Version::operator>=(const Version& other) const noexcept { return !(*this < other); }

inline Version::operator std::string() const { return ToString(); }

inline void Version::Check() const
{
    if (major_ < 0 || minor_ < 0 || revision_ < 0) {
        throw std::runtime_error{"[pbbam] version string ERROR: cannot contain negative numbers"};
    }
}

inline int Version::Major() const { return major_; }

inline Version& Version::Major(int major)
{
    major_ = major;
    Check();
    return *this;
}

inline int Version::Minor() const { return minor_; }

inline Version& Version::Minor(int minor)
{
    minor_ = minor;
    Check();
    return *this;
}

inline int Version::Revision() const { return revision_; }

inline Version& Version::Revision(int revision)
{
    revision_ = revision;
    Check();
    return *this;
}

}  // namespace BAM
}  // namespace PacBio

#endif  // PBBAM_VERSION_H