Files
rippled/include/xrpl/beast/core/SemanticVersion.h
Ayaz Salikhov c69091bded chore: Add Git information compile-time info to only one file (#6464)
The existing code added the git commit info (`GIT_COMMIT_HASH` and `GIT_BRANCH`) to every file, which was a problem for leveraging `ccache` to cache build objects. This change adds a separate C++ file from where these compile-time variables are propagated to wherever they are needed. A new CMake file is added to set the commit info if the `git` binary is available.
2026-03-04 19:45:28 +00:00

98 lines
1.9 KiB
C++

#pragma once
#include <string>
#include <string_view>
#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_view version);
/** Parse a semantic version string.
The parsing is as strict as possible.
@return `true` if the string was parsed.
*/
bool
parse(std::string_view 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