32 const char ModuleVersion::SEPARATOR =
'.';
36 return !(std::isalnum(c) || c ==
'_' || c ==
'-');
53 majorVersion = v.majorVersion;
54 minorVersion = v.minorVersion;
55 microVersion = v.microVersion;
56 qualifier = v.qualifier;
57 undefined = v.undefined;
61 ModuleVersion::ModuleVersion(
bool undefined)
62 : majorVersion(0), minorVersion(0), microVersion(0), qualifier(
""), undefined(undefined)
67 void ModuleVersion::Validate()
69 if (std::find_if(qualifier.begin(), qualifier.end(),
IsInvalidQualifier) != qualifier.end())
70 throw std::invalid_argument(std::string(
"invalid qualifier: ") + qualifier);
75 ModuleVersion::ModuleVersion(
unsigned int majorVersion,
unsigned int minorVersion,
unsigned int microVersion)
76 : majorVersion(majorVersion), minorVersion(minorVersion), microVersion(microVersion), qualifier(
""),
82 ModuleVersion::ModuleVersion(
unsigned int majorVersion,
unsigned int minorVersion,
unsigned int microVersion,
const std::string& qualifier)
83 : majorVersion(majorVersion), minorVersion(minorVersion), microVersion(microVersion), qualifier(qualifier),
89 ModuleVersion::ModuleVersion(
const std::string& version)
90 : majorVersion(0), minorVersion(0), microVersion(0), undefined(true)
97 std::vector<std::string> st;
98 std::stringstream ss(version);
100 while(std::getline(ss, token, SEPARATOR))
105 if (st.empty())
return;
136 if (!ok)
throw std::invalid_argument(
"invalid format");
146 : majorVersion(version.majorVersion), minorVersion(version.minorVersion),
147 microVersion(version.microVersion), qualifier(version.qualifier),
148 undefined(version.undefined)
160 std::string version2(version);
161 version2.erase(0, version2.find_first_not_of(
' '));
162 version2.erase(version2.find_last_not_of(
' ')+1);
163 if (version2.empty())
178 if (undefined)
throw std::logic_error(
"Version undefined");
184 if (undefined)
throw std::logic_error(
"Version undefined");
190 if (undefined)
throw std::logic_error(
"Version undefined");
196 if (undefined)
throw std::logic_error(
"Version undefined");
202 if (undefined)
return "undefined";
204 std::stringstream ss;
205 ss << majorVersion << SEPARATOR << minorVersion << SEPARATOR << microVersion;
206 if (!qualifier.empty())
208 ss << SEPARATOR << qualifier;
220 if (other.undefined && this->undefined)
return true;
221 if (this->undefined)
throw std::logic_error(
"Version undefined");
222 if (other.undefined)
return false;
224 return (majorVersion == other.majorVersion) && (minorVersion == other.minorVersion) && (microVersion
225 == other.microVersion) && qualifier == other.qualifier;
235 if (this->undefined || other.undefined)
236 throw std::logic_error(
"Cannot compare undefined version");
238 if (majorVersion < other.majorVersion)
243 if (majorVersion == other.majorVersion)
246 if (minorVersion < other.minorVersion)
251 if (minorVersion == other.minorVersion)
254 if (microVersion < other.microVersion)
259 if (microVersion == other.microVersion)
261 return qualifier.compare(other.qualifier);
272 std::ostream&
operator<<(std::ostream& os,
const ModuleVersion& v)
274 return os << v.ToString();
int Compare(const ModuleVersion &object) const
unsigned int GetMicro() const
bool operator==(const ModuleVersion &object) const
unsigned int GetMinor() const
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
bool IsInvalidQualifier(char c)
std::string ToString() const
std::string GetQualifier() const
static ModuleVersion EmptyVersion()
unsigned int GetMajor() const
static ModuleVersion ParseVersion(const std::string &version)