semver-utils
1.0.1
|
Class that represents a version number. More...
#include <version.hpp>
Public Member Functions | |
version (const std::vector< unsigned int > versions, const std::string prerelease="", const std::string metadata="") | |
Constructs a semver::version instance with the specified parameters. The parameters must comply with Semantic Versioning 2.0.0. More... | |
std::string | str () const |
Converts a version to its string representation. More... | |
std::vector< unsigned int > | get_version () const |
Gets the version components. More... | |
unsigned int | get_version (unsigned int index) const |
Gets the specified version component. More... | |
std::string | get_prerelease () const |
Gets the prerelease string. More... | |
std::string | get_metadata () const |
Gets the metadata string. More... | |
version | bump_major () const |
Bumps the major version component. More... | |
version | bump_minor () const |
Bumps the minor version component. More... | |
version | bump_patch () const |
Bumps the patch version component. More... | |
version | bump (unsigned int index) const |
Bumps the specified version component. More... | |
version | strip_prerelease () const |
Strips the prerelease component. More... | |
version | strip_metadata () const |
Strips the metadata component. More... | |
bool | is_release () const |
Checks whether the instance is a release version. More... | |
bool | operator== (const version &rh) const |
Checks two instances for equality. More... | |
bool | operator< (const version &rh) const |
Compares two instances. More... | |
bool | operator> (const version &rh) const |
Compares two instances. More... | |
Static Public Member Functions | |
static version | from_string (std::string v) |
Constructs a semver::version instance from a std::string. More... | |
Class that represents a version number.
This class represents a version number complying with _Semantic Versioning 2.0.0 (http://semver.org/). As a supported extension this class allows version numbers to contain any number of components greater than 2.
Instances of this class are designed to be immutable.
semver::version::version | ( | const std::vector< unsigned int > | versions, |
const std::string | prerelease = "" , |
||
const std::string | metadata = "" |
||
) |
Constructs a semver::version instance with the specified parameters. The parameters must comply with Semantic Versioning 2.0.0.
versions | The version components. As a supported extension this class allows versions numbers to contain any number of components greater than 2. |
prerelease | An optional prerelease string. |
metadata | An optional metadata string. |
std::invalid_argument | if the parameters do not comply with Semantic Versioning 2.0.0. |
version semver::version::bump | ( | unsigned int | index | ) | const |
Bumps the specified version component.
The component index
is bumped and all components whose index is grater than index
are set to 0. If index
is greater than the current size s
of the version number, then index + 1 - s
components are added and set to 0.
version semver::version::bump_major | ( | ) | const |
Bumps the major version component.
This method uses ::bump();
version semver::version::bump_minor | ( | ) | const |
Bumps the minor version component.
This method uses ::bump();
version semver::version::bump_patch | ( | ) | const |
Bumps the patch version component.
This method uses ::bump();
|
static |
Constructs a semver::version instance from a std::string.
The version number v
must comply with Semantic Versioning 2.0.0. As a supported extension this class allows version numbers to contain any number of components greater than 2.
v | The version number to parse. |
std::invalid_argument | if v is not a valid version number. |
std::string semver::version::get_metadata | ( | ) | const |
Gets the metadata string.
std::string semver::version::get_prerelease | ( | ) | const |
Gets the prerelease string.
std::vector< unsigned int > semver::version::get_version | ( | ) | const |
Gets the version components.
unsigned int semver::version::get_version | ( | unsigned int | index | ) | const |
Gets the specified version component.
index
does not exist. bool semver::version::is_release | ( | ) | const |
Checks whether the instance is a release version.
true
if the instance represents a release version, false
otherwise. bool semver::version::operator< | ( | const version & | rh | ) | const |
Compares two instances.
An instance is less than another if its version number is less than the other's. Components are compared one by one, starting from the first. If the two components are equal, then the following component is considered. If the first component is less than the second, then true
is returned, otherwise false
is returned.
v | The instance to be compared with. |
true
if this instance is less than rh
, false
otherwise. bool semver::version::operator== | ( | const version & | rh | ) | const |
Checks two instances for equality.
Two instances are equal if and only if all its components are equal.
v | The instance to be compared with. |
true
if rh
is equal to this instance, false
otherwise. bool semver::version::operator> | ( | const version & | rh | ) | const |
Compares two instances.
An instance is greater than another if its version number is less than the other's. Components are compared one by one, starting from the first. If the two components are equal, then the following component is considered. If the first component is greater than the second, then true
is returned, otherwise false
is returned.
v | The instance to be compared with. |
true
if this instance is greater than rh
, false
otherwise. std::string semver::version::str | ( | ) | const |
Converts a version to its string representation.
version semver::version::strip_metadata | ( | ) | const |
Strips the metadata component.
version semver::version::strip_prerelease | ( | ) | const |
Strips the prerelease component.