semver-utils  1.1.1
Public Member Functions | Static Public Member Functions | List of all members
semver::version Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
versionsThe version components. As a supported extension this class allows versions numbers to contain any number of components greater than 2.
prereleaseAn optional prerelease string.
metadataAn optional metadata string.
Returns
A semver::version instance.
Exceptions
std::invalid_argumentif the parameters do not comply with Semantic Versioning 2.0.0.

Member Function Documentation

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.

Returns
A semver::version object representing the bumped version.
version semver::version::bump_major ( ) const

Bumps the major version component.

This method uses ::bump();

Returns
A semver::version object containing the bumped version.
version semver::version::bump_minor ( ) const

Bumps the minor version component.

This method uses ::bump();

Returns
A semver::version object representing the bumped version.
version semver::version::bump_patch ( ) const

Bumps the patch version component.

This method uses ::bump();

Returns
A semver::version object representing the bumped version.
version semver::version::from_string ( std::string  v)
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.

Parameters
vThe version number to parse.
Returns
A semver::version instance.
Exceptions
std::invalid_argumentif v is not a valid version number.
std::string semver::version::get_metadata ( ) const

Gets the metadata string.

Returns
The metadata string.
std::string semver::version::get_prerelease ( ) const

Gets the prerelease string.

Returns
The prerelease string.
std::vector< unsigned int > semver::version::get_version ( ) const

Gets the version components.

Returns
The version components.
unsigned int semver::version::get_version ( unsigned int  index) const

Gets the specified version component.

Returns
The specified version component, or 0 if the specified index does not exist.
bool semver::version::is_release ( ) const

Checks whether the instance is a release version.

Returns
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.

Parameters
vThe instance to be compared with.
Returns
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.

Parameters
vThe instance to be compared with.
Returns
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.

Parameters
vThe instance to be compared with.
Returns
true if this instance is greater than rh, false otherwise.
std::string semver::version::str ( ) const

Converts a version to its string representation.

Returns
The string representation of this instance.
version semver::version::strip_metadata ( ) const

Strips the metadata component.

Returns
A semver::version object representing the modified version.
version semver::version::strip_prerelease ( ) const

Strips the prerelease component.

Returns
A semver::version object representing the modified version.

The documentation for this class was generated from the following files: