omw  0.2.0
version.h
1 /*
2 author Oliver Blaser
3 date 22.01.2022
4 copyright MIT - Copyright (c) 2022 Oliver Blaser
5 */
6 
7 #ifndef IG_OMW_VERSION_H
8 #define IG_OMW_VERSION_H
9 
10 #include <cstdint>
11 #include <string>
12 
13 #include "../omw/string.h"
14 
15 namespace omw
16 {
21  class Version
22  {
23  public:
24  Version();
25  Version(int32_t major, int32_t minor, int32_t patch, const char* preRelease, const char* build = nullptr);
26  Version(int32_t major, int32_t minor, int32_t patch, const std::string& preRelease = "", const std::string& build = "");
27  Version(const char* str);
28  Version(const std::string& str);
29  virtual ~Version() {}
30 
31  void set(int32_t major, int32_t minor, int32_t patch, const char* preRelease, const char* build = nullptr);
32  void set(int32_t major, int32_t minor, int32_t patch, const std::string& preRelease = "", const std::string& build = "");
33  void set(const char* str);
34  void set(const std::string& str);
35 
36  int32_t major() const;
37  int32_t minor() const;
38  int32_t patch() const;
39  omw::string preRelease() const;
40  const omw::stringVector_t& preReleaseIdentifiers() const;
41  omw::string build() const;
42  const omw::stringVector_t& buildIdentifiers() const;
43 
44  int compare(const omw::Version& b) const;
45 
46  omw::string toString() const;
47 
48  bool hasBuild() const;
49  bool isPreRelease() const;
50  bool isValid() const;
52  protected:
53  int32_t m_maj;
54  int32_t m_min;
55  int32_t m_pat;
56  omw::stringVector_t m_preRelease;
57  omw::stringVector_t m_build;
58 
59  void parse(const omw::string& str);
60  void parseBuild(const omw::string& identifiers);
61  void parsePreRelease(const omw::string& identifiers);
62  void parseVersion(const omw::string& identifiers);
63  };
64 
67  bool operator==(const omw::Version& a, const omw::Version& b);
68  bool operator!=(const omw::Version& a, const omw::Version& b);
69  bool operator<(const omw::Version& a, const omw::Version& b);
70  bool operator>(const omw::Version& a, const omw::Version& b);
71  bool operator<=(const omw::Version& a, const omw::Version& b);
72  bool operator>=(const omw::Version& a, const omw::Version& b);
74 
76 }
77 
78 #endif // IG_OMW_VERSION_H
std::string
C++ standard string. See std::basic_string.
Definition: linkToStd.dox:19
omw::Version::hasBuild
bool hasBuild() const
Definition: version.cpp:298
omw::operator!=
bool operator!=(const omw::Color &lhs, const omw::Color &rhs)
Definition: color.cpp:451
omw::operator==
bool operator==(const omw::Color &lhs, const omw::Color &rhs)
Definition: color.cpp:443
omw::Version::isValid
bool isValid() const
Definition: version.cpp:311
omw::Version
Compliant to semver.
Definition: version.h:22
omw::Version::Version
Version()
Definition: version.cpp:103
omw::Version::isPreRelease
bool isPreRelease() const
Definition: version.cpp:306
omw::string
Definition: string.h:85
omw
Main namespace.
omw::Version::compare
int compare(const omw::Version &b) const
Definition: version.cpp:222