mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-18 10:05:51 +00:00
Per XLS-0095, we are taking steps to rename ripple(d) to xrpl(d). This change specifically removes all copyright notices referencing Ripple, XRPLF, and certain affiliated contributors upon mutual agreement, so the notice in the LICENSE.md file applies throughout. Copyright notices referencing external contributions remain as-is. Duplicate verbiage is also removed.
100 lines
2.0 KiB
C++
100 lines
2.0 KiB
C++
#ifndef BEAST_MODULE_CORE_DIAGNOSTIC_SEMANTICVERSION_H_INCLUDED
|
|
#define BEAST_MODULE_CORE_DIAGNOSTIC_SEMANTICVERSION_H_INCLUDED
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace beast {
|
|
|
|
/** A Semantic Version number.
|
|
|
|
Identifies the build of a particular version of software using
|
|
the Semantic Versioning Specification described here:
|
|
|
|
http://semver.org/
|
|
*/
|
|
class SemanticVersion
|
|
{
|
|
public:
|
|
using identifier_list = std::vector<std::string>;
|
|
|
|
int majorVersion;
|
|
int minorVersion;
|
|
int patchVersion;
|
|
|
|
identifier_list preReleaseIdentifiers;
|
|
identifier_list metaData;
|
|
|
|
SemanticVersion();
|
|
|
|
SemanticVersion(std::string const& version);
|
|
|
|
/** Parse a semantic version string.
|
|
The parsing is as strict as possible.
|
|
@return `true` if the string was parsed.
|
|
*/
|
|
bool
|
|
parse(std::string const& input);
|
|
|
|
/** Produce a string from semantic version components. */
|
|
std::string
|
|
print() const;
|
|
|
|
inline bool
|
|
isRelease() const noexcept
|
|
{
|
|
return preReleaseIdentifiers.empty();
|
|
}
|
|
inline bool
|
|
isPreRelease() const noexcept
|
|
{
|
|
return !isRelease();
|
|
}
|
|
};
|
|
|
|
/** Compare two SemanticVersions against each other.
|
|
The comparison follows the rules as per the specification.
|
|
*/
|
|
int
|
|
compare(SemanticVersion const& lhs, SemanticVersion const& rhs);
|
|
|
|
inline bool
|
|
operator==(SemanticVersion const& lhs, SemanticVersion const& rhs)
|
|
{
|
|
return compare(lhs, rhs) == 0;
|
|
}
|
|
|
|
inline bool
|
|
operator!=(SemanticVersion const& lhs, SemanticVersion const& rhs)
|
|
{
|
|
return compare(lhs, rhs) != 0;
|
|
}
|
|
|
|
inline bool
|
|
operator>=(SemanticVersion const& lhs, SemanticVersion const& rhs)
|
|
{
|
|
return compare(lhs, rhs) >= 0;
|
|
}
|
|
|
|
inline bool
|
|
operator<=(SemanticVersion const& lhs, SemanticVersion const& rhs)
|
|
{
|
|
return compare(lhs, rhs) <= 0;
|
|
}
|
|
|
|
inline bool
|
|
operator>(SemanticVersion const& lhs, SemanticVersion const& rhs)
|
|
{
|
|
return compare(lhs, rhs) > 0;
|
|
}
|
|
|
|
inline bool
|
|
operator<(SemanticVersion const& lhs, SemanticVersion const& rhs)
|
|
{
|
|
return compare(lhs, rhs) < 0;
|
|
}
|
|
|
|
} // namespace beast
|
|
|
|
#endif
|