Represents version numbers. More...
#include <version.hpp>
Public Member Functions | |
version_info () | |
Default constructor. More... | |
version_info (const std::string &) | |
String constructor. More... | |
version_info (unsigned int major, unsigned int minor, unsigned int revision_level, char special_separator='\0', const std::string &special=std::string()) | |
Simple list constructor. More... | |
bool | is_canonical () const |
Whether the version number is considered canonical for mainline Wesnoth. More... | |
std::string | str () const |
Serializes the version number into string form. More... | |
operator std::string () const | |
Syntactic shortcut for str(). More... | |
unsigned int | major_version () const |
Retrieves the major version number (x1 in "x1.x2.x3"). More... | |
unsigned int | minor_version () const |
Retrieves the minor version number (x2 in "x1.x2.x3"). More... | |
unsigned int | revision_level () const |
Retrieves the revision level (x3 in "x1.x2.x3"). More... | |
char | special_version_separator () const |
Retrieves the special version separator (e.g. More... | |
const std::string & | special_version () const |
Retrieves the special version suffix (e.g. More... | |
void | set_major_version (unsigned int) |
Sets the major version number. More... | |
void | set_minor_version (unsigned int) |
Sets the minor version number. More... | |
void | set_revision_level (unsigned int) |
Sets the revision level. More... | |
void | set_special_version (const std::string &str) |
Sets the special version suffix. More... | |
unsigned int | get_component (size_t index) const |
Returns any numeric component from a version number. More... | |
void | set_component (size_t index, unsigned int value) |
Sets any numeric component from a version number. More... | |
const std::vector< unsigned int > & | components () const |
Read-only access to all numeric components. More... | |
Private Attributes | |
std::vector< unsigned int > | nums_ |
std::string | special_ |
char | special_separator_ |
Represents version numbers.
Versions are expected to be in the format x1.x2.x3[.x4[.x5[...]]]
, with an optional trailing special version suffix and suffix separator.
When parsing a version string, the first three components are optional and default to zero if absent. The serialized form will always have all first three components, making deserialization and serialization an asymmetric process in those cases (e.g. "0.1" becomes "0.1.0").
The optional trailing suffix starts after the last digit, and may be preceded by a non-alphanumeric separator character (e.g. "0.1a" has "a" as its suffix and the null character as its separator, but in "0.1+dev" the separator is '+' and the suffix is "dev"). Both are preserved during serialization ("0.1+dev" becomes "0.1.0+dev").
Definition at line 44 of file version.hpp.
version_info::version_info | ( | ) |
Default constructor.
Definition at line 22 of file version.cpp.
version_info::version_info | ( | const std::string & | str | ) |
String constructor.
Definition at line 36 of file version.cpp.
References i, nums_, special_, special_separator_, utils::split(), str(), and utils::strip().
version_info::version_info | ( | unsigned int | major, |
unsigned int | minor, | ||
unsigned int | revision_level, | ||
char | special_separator = '\0' , |
||
const std::string & | special = std::string() |
||
) |
Simple list constructor.
Definition at line 27 of file version.cpp.
References nums_, and revision_level().
|
inline |
Read-only access to all numeric components.
Definition at line 171 of file version.hpp.
References nums_.
|
inline |
Returns any numeric component from a version number.
The index may be in the [0,3) range, yielding the same results as major_version(), minor_version(), and revision_level().
std::out_of_range | If the number of components is less than index - 1 . |
Definition at line 149 of file version.hpp.
References nums_.
bool version_info::is_canonical | ( | ) | const |
Whether the version number is considered canonical for mainline Wesnoth.
Mainline Wesnoth version numbers have at most three components, so this check is equivalent to components() >= 3
.
Definition at line 138 of file version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE().
unsigned int version_info::major_version | ( | ) | const |
Retrieves the major version number (x1 in "x1.x2.x3").
Definition at line 126 of file version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), savegame::loadgame::check_version_compatibility(), and filesystem::get_version_path_suffix().
unsigned int version_info::minor_version | ( | ) | const |
Retrieves the minor version number (x2 in "x1.x2.x3").
Definition at line 130 of file version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), savegame::loadgame::check_version_compatibility(), and filesystem::get_version_path_suffix().
|
inline |
unsigned int version_info::revision_level | ( | ) | const |
Retrieves the revision level (x3 in "x1.x2.x3").
Definition at line 134 of file version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), and version_info().
Sets any numeric component from a version number.
The index may be in the [0,3) range, resulting in the same effect as set_major_version(), set_minor_version(), and set_revision_level().
std::out_of_range | If the number of components is less than index - 1 . |
Definition at line 163 of file version.hpp.
References nums_.
|
inline |
Sets the special version suffix.
Definition at line 135 of file version.hpp.
|
inline |
Retrieves the special version suffix (e.g.
"dev" in "0.1+dev").
Definition at line 112 of file version.hpp.
References special_.
Referenced by BOOST_AUTO_TEST_CASE(), operator!=(), operator<(), operator==(), and operator>().
|
inline |
Retrieves the special version separator (e.g.
'+' in "0.1+dev").
The special version separator is the first non-alphanumerical character preceding the special version suffix and following the last numeric component. If missing, the null character is returned instead.
Definition at line 104 of file version.hpp.
References special_separator_.
Referenced by BOOST_AUTO_TEST_CASE().
std::string version_info::str | ( | ) | const |
Serializes the version number into string form.
The result is in the format x1.x2.x3[.x4[.x5[...]]]
, followed by the special version suffix separator (if not null) and the suffix itself (if not empty).
Definition at line 90 of file version.cpp.
References nums_, special_, and special_separator_.
Referenced by BOOST_AUTO_TEST_CASE(), mp::check_addon_version_compatibility(), savegame::loadgame::check_version_compatibility(), gui2::describe_status_verbose(), preprocessor_data::get_chunk(), gui2::taddon_list::on_addon_select(), operator std::string(), gui2::taddon_list::pre_show(), set_special_version(), version_info(), addon_info::write(), and addon_info::write_minimal().
|
private |
Definition at line 177 of file version.hpp.
Referenced by components(), get_component(), is_canonical(), major_version(), minor_version(), revision_level(), set_component(), set_major_version(), set_minor_version(), set_revision_level(), str(), and version_info().
|
private |
Definition at line 178 of file version.hpp.
Referenced by set_special_version(), special_version(), str(), and version_info().
|
private |
Definition at line 179 of file version.hpp.
Referenced by special_version_separator(), str(), and version_info().