| LicenseSpring C++ SDK 7.32.0 Easily add Software Licensing to your application

Loading...
Searching...
No Matches
Version.h
Go to the documentation of this file.
1#ifndef LS_VERSION_H
2#define LS_VERSION_H
3
4#ifdef _MSC_VER
5#pragma once
6#pragma warning( push )
7#pragma warning( disable : 4251 )
8#endif
9
10#include <string>
11#include "APIDef.h"
12
13 namespace LicenseSpring
14{
19 class LS_API VersionBase
20 {
21 public:
22 static constexpr int INVALID_VERSION_NUMBER = -1;
23
24 VersionBase();
25 VersionBase( int major, int minor, char delimeter = '.' );
26 virtual ~VersionBase() = default;
27
28 int majorVersion() const { return m_major; }
29 int minorVersion() const { return m_minor; }
30
31 char delimeter() const { return m_delimeter; }
32 void setDelimeter( char delimeter ) { m_delimeter = delimeter; }
33
34 size_t size() const;
35 virtual size_t length() const;
36
37 virtual std::string toString() const;
38
39 operator std::string() const;
40
41 bool operator==( const VersionBase& version ) const;
42 bool operator!=( const VersionBase& version ) const;
43 bool operator<( const VersionBase& version ) const;
44 bool operator>( const VersionBase& version ) const;
45 bool operator<=( const VersionBase& version ) const;
46 bool operator>=( const VersionBase& version ) const;
47
48 virtual int compare( const VersionBase& version ) const;
49
50 static int compare( const VersionBase& left, const VersionBase& right );
51
52 protected:
53 int m_major;
54 int m_minor;
55 char m_delimeter;
56 };
57
58 LS_API std::ostream& operator<<( std::ostream& out, const VersionBase& version );
59
66 class LS_API Version : public VersionBase
67 {
68 public:
69 Version();
70 Version( int major, int minor, char delimeter = '.' );
71 Version( int major, int minor, int patch, char delimeter = '.' );
72 Version( int major, int minor, int patch, int build, char delimeter = '.' );
73 Version( const std::string& version, char delimeter = '.' );
74
75 int patchVersion() const { return m_patch; }
76 int buildVersion() const { return m_build; }
77 bool hasPatchVersion() const { return m_patch >= 0; }
78 bool hasBuildVersion() const { return m_build >= 0; }
79 void setPatchVersion( int number );
80 void setBuildVersion( int number );
81
82 size_t length() const override;
83
84 std::string toString() const override;
85
86 int compare( const VersionBase& baseVer ) const override;
87
88 static Version fromString( const std::string& input, char delimeter = '.' );
89
90 static Version InvalidVersion; //< Invalid Version 0.0.-1.-1
91
92 protected:
93 int m_patch;
94 int m_build;
95 };
96
103 class LS_API MSVersion : public VersionBase
104 {
105 public:
106 MSVersion();
107 MSVersion( int major, int minor, char delimeter = '.' );
108 MSVersion( int major, int minor, int build, char delimeter = '.' );
109 MSVersion( int major, int minor, int build, int revision, char delimeter = '.' );
110 MSVersion( const std::string& version, char delimeter = '.' );
111
112 int buildVersion() const { return m_build; }
113 int revisionVersion() const { return m_revision; }
114 bool hasBuildVersion() const { return m_build >= 0; }
115 bool hasRevisionVersion() const { return m_revision >= 0; }
116 void setBuildVersion( int number );
117 void setRevisionVersion( int number );
118
119 size_t length() const override;
120
121 std::string toString() const override;
122
123 int compare( const VersionBase& baseVer ) const override;
124
125 static MSVersion fromString( const std::string& input, char delimeter = '.' );
126
127 static MSVersion InvalidVersion; //< Invalid Version 0.0.-1.-1
128
129 private:
130 int m_build;
131 int m_revision;
132 };
133
134 enum class PrereleaseType : std::uint8_t
135 {
136 alpha = 0,
137 beta = 1,
138 rc = 2,
139 none = 3,
140 };
141
147 class LS_API VersionEx : public Version
148 {
149 public:
150 VersionEx();
151 VersionEx( int major, int minor, int patch, char delimeter = '.' );
152 VersionEx( int major, int minor, int patch, int build, char delimeter = '.' );
153 VersionEx( const std::string& version, char delimeter = '.' );
154
155 void setPrereleaseType( PrereleaseType type ) { m_prereleaseType = type; }
156 PrereleaseType prereleaseType() const { return m_prereleaseType; }
157 bool isPrerelease() const { return !m_prerelease.empty(); }
158
159 const std::string& prereleaseVersion() const { return m_prerelease; }
160 void setPrereleaseVersion( const std::string& version ) { m_prerelease = version; }
161
162 const std::string& buildMetadata() const { return m_buildMetadata; }
163 void setBuildMetadata( const std::string& data ) { m_buildMetadata = data; }
164
165 std::string toString() const override;
166
167 int compare( const VersionBase& baseVer ) const override;
168
169 static VersionEx fromString( const std::string& input, char delimeter = '.' );
170
171 private:
172 PrereleaseType m_prereleaseType;
173 std::string m_prerelease;
174 std::string m_buildMetadata;
175 };
176
177}
178
179#ifdef _MSC_VER
180#pragma warning( pop )
181#endif
182
183#endif // LS_CUSTOMER_H
APIDef.h
LS_API
#define LS_API
Macros that expands to dllexport, dllimport or nothing on non Windows platforms or in case of static ...
Definition APIDef.h:22
LicenseSpring::MSVersion
Simple class for handling app versions in Microsoft specific file and assembly version format....
Definition Version.h:104
LicenseSpring::MSVersion::length
size_t length() const override
LicenseSpring::MSVersion::MSVersion
MSVersion(int major, int minor, char delimeter='.')
LicenseSpring::MSVersion::MSVersion
MSVersion()
LicenseSpring::MSVersion::buildVersion
int buildVersion() const
Definition Version.h:112
LicenseSpring::MSVersion::revisionVersion
int revisionVersion() const
Definition Version.h:113
LicenseSpring::MSVersion::fromString
static MSVersion fromString(const std::string &input, char delimeter='.')
LicenseSpring::MSVersion::hasRevisionVersion
bool hasRevisionVersion() const
Definition Version.h:115
LicenseSpring::MSVersion::hasBuildVersion
bool hasBuildVersion() const
Definition Version.h:114
LicenseSpring::MSVersion::toString
std::string toString() const override
LicenseSpring::MSVersion::MSVersion
MSVersion(int major, int minor, int build, char delimeter='.')
LicenseSpring::MSVersion::MSVersion
MSVersion(const std::string &version, char delimeter='.')
LicenseSpring::MSVersion::setBuildVersion
void setBuildVersion(int number)
LicenseSpring::MSVersion::setRevisionVersion
void setRevisionVersion(int number)
LicenseSpring::MSVersion::compare
int compare(const VersionBase &baseVer) const override
LicenseSpring::MSVersion::MSVersion
MSVersion(int major, int minor, int build, int revision, char delimeter='.')
LicenseSpring::MSVersion::InvalidVersion
static MSVersion InvalidVersion
Definition Version.h:127
LicenseSpring::VersionBase
Base class for handling app versions. Contains common functionality for version classes hierarchy.
Definition Version.h:20
LicenseSpring::VersionBase::minorVersion
int minorVersion() const
Definition Version.h:29
LicenseSpring::VersionBase::m_delimeter
char m_delimeter
Definition Version.h:55
LicenseSpring::VersionBase::operator==
bool operator==(const VersionBase &version) const
LicenseSpring::VersionBase::m_major
int m_major
Definition Version.h:53
LicenseSpring::VersionBase::length
virtual size_t length() const
LicenseSpring::VersionBase::majorVersion
int majorVersion() const
Definition Version.h:28
LicenseSpring::VersionBase::compare
virtual int compare(const VersionBase &version) const
LicenseSpring::VersionBase::delimeter
char delimeter() const
Definition Version.h:31
LicenseSpring::VersionBase::operator<=
bool operator<=(const VersionBase &version) const
LicenseSpring::VersionBase::VersionBase
VersionBase()
LicenseSpring::VersionBase::compare
static int compare(const VersionBase &left, const VersionBase &right)
LicenseSpring::VersionBase::operator>
bool operator>(const VersionBase &version) const
LicenseSpring::VersionBase::VersionBase
VersionBase(int major, int minor, char delimeter='.')
LicenseSpring::VersionBase::setDelimeter
void setDelimeter(char delimeter)
Definition Version.h:32
LicenseSpring::VersionBase::operator<
bool operator<(const VersionBase &version) const
LicenseSpring::VersionBase::size
size_t size() const
LicenseSpring::VersionBase::m_minor
int m_minor
Definition Version.h:54
LicenseSpring::VersionBase::operator>=
bool operator>=(const VersionBase &version) const
LicenseSpring::VersionBase::toString
virtual std::string toString() const
LicenseSpring::VersionBase::operator!=
bool operator!=(const VersionBase &version) const
LicenseSpring::VersionBase::~VersionBase
virtual ~VersionBase()=default
LicenseSpring::VersionEx
Extended class for handling app versions, compliant with Semantic Versioning 2.0.0 Format: Major....
Definition Version.h:148
LicenseSpring::VersionEx::VersionEx
VersionEx(const std::string &version, char delimeter='.')
LicenseSpring::VersionEx::toString
std::string toString() const override
LicenseSpring::VersionEx::VersionEx
VersionEx(int major, int minor, int patch, char delimeter='.')
LicenseSpring::VersionEx::VersionEx
VersionEx()
LicenseSpring::VersionEx::prereleaseType
PrereleaseType prereleaseType() const
Definition Version.h:156
LicenseSpring::VersionEx::setBuildMetadata
void setBuildMetadata(const std::string &data)
Definition Version.h:163
LicenseSpring::VersionEx::setPrereleaseVersion
void setPrereleaseVersion(const std::string &version)
Definition Version.h:160
LicenseSpring::VersionEx::compare
int compare(const VersionBase &baseVer) const override
LicenseSpring::VersionEx::isPrerelease
bool isPrerelease() const
Definition Version.h:157
LicenseSpring::VersionEx::buildMetadata
const std::string & buildMetadata() const
Definition Version.h:162
LicenseSpring::VersionEx::prereleaseVersion
const std::string & prereleaseVersion() const
Definition Version.h:159
LicenseSpring::VersionEx::fromString
static VersionEx fromString(const std::string &input, char delimeter='.')
LicenseSpring::VersionEx::VersionEx
VersionEx(int major, int minor, int patch, int build, char delimeter='.')
LicenseSpring::VersionEx::setPrereleaseType
void setPrereleaseType(PrereleaseType type)
Definition Version.h:155
LicenseSpring::Version
Simple class for handling app versions. Format: Major.Minor.Patch.Build, where all parts are integer ...
Definition Version.h:67
LicenseSpring::Version::hasPatchVersion
bool hasPatchVersion() const
Definition Version.h:77
LicenseSpring::Version::fromString
static Version fromString(const std::string &input, char delimeter='.')
LicenseSpring::Version::setPatchVersion
void setPatchVersion(int number)
LicenseSpring::Version::length
size_t length() const override
LicenseSpring::Version::Version
Version(const std::string &version, char delimeter='.')
LicenseSpring::Version::Version
Version(int major, int minor, char delimeter='.')
LicenseSpring::Version::compare
int compare(const VersionBase &baseVer) const override
LicenseSpring::Version::hasBuildVersion
bool hasBuildVersion() const
Definition Version.h:78
LicenseSpring::Version::Version
Version()
LicenseSpring::Version::buildVersion
int buildVersion() const
Definition Version.h:76
LicenseSpring::Version::m_patch
int m_patch
Definition Version.h:93
LicenseSpring::Version::toString
std::string toString() const override
LicenseSpring::Version::m_build
int m_build
Definition Version.h:94
LicenseSpring::Version::setBuildVersion
void setBuildVersion(int number)
LicenseSpring::Version::InvalidVersion
static Version InvalidVersion
Definition Version.h:90
LicenseSpring::Version::Version
Version(int major, int minor, int patch, char delimeter='.')
LicenseSpring::Version::Version
Version(int major, int minor, int patch, int build, char delimeter='.')
LicenseSpring::Version::patchVersion
int patchVersion() const
Definition Version.h:75
LicenseSpring
Definition BaseManager.h:16
LicenseSpring::PrereleaseType
PrereleaseType
Definition Version.h:135
LicenseSpring::PrereleaseType::alpha
@ alpha
LicenseSpring::PrereleaseType::none
@ none
LicenseSpring::PrereleaseType::beta
@ beta
LicenseSpring::PrereleaseType::rc
@ rc
LicenseSpring::encrypt_character
constexpr Char encrypt_character(const Char character, int index)
Definition EncryptString.h:44
LicenseSpring::operator<<
LS_API std::ostream & operator<<(std::ostream &out, const VersionBase &version)