Represents version numbers. More...
#include <game_version.hpp>
Public Member Functions | |
version_info () | |
Default constructor. More... | |
version_info (const std::string &) | |
String constructor. More... | |
version_info (const char *str) | |
version_info (std::nullptr_t)=delete | |
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... | |
bool | is_dev_version () const |
Whether this version represents a development version of Wesnoth aka whether the minor version odd. 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 (std::size_t index) const |
Returns any numeric component from a version number. More... | |
void | set_component (std::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 game_version.hpp.
version_info::version_info | ( | ) |
Default constructor.
Definition at line 49 of file game_version.cpp.
version_info::version_info | ( | const std::string & | str | ) |
String constructor.
Definition at line 68 of file game_version.cpp.
References components(), i, nums_, s, special_, special_separator_, utils::split(), str(), and utils::trim().
version_info::version_info | ( | const char * | str | ) |
Definition at line 54 of file game_version.cpp.
|
delete |
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 59 of file game_version.cpp.
References nums_, and revision_level().
|
inline |
Read-only access to all numeric components.
Definition at line 178 of file game_version.hpp.
References nums_.
Referenced by impl_version_get(), and version_info().
|
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 156 of file game_version.hpp.
References utf8::index(), and 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 170 of file game_version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), and impl_version_get().
bool version_info::is_dev_version | ( | ) | const |
Whether this version represents a development version of Wesnoth aka whether the minor version odd.
Definition at line 174 of file game_version.cpp.
References is_odd(), and minor_version().
unsigned int version_info::major_version | ( | ) | const |
Retrieves the major version number (x1 in "x1.x2.x3").
Definition at line 158 of file game_version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), savegame::loadgame::check_version_compatibility(), filesystem::get_version_path_suffix(), impl_version_get(), and gui2::dialogs::migrate_version_selection::migrate_version_selection().
unsigned int version_info::minor_version | ( | ) | const |
Retrieves the minor version number (x2 in "x1.x2.x3").
Definition at line 162 of file game_version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), savegame::loadgame::check_version_compatibility(), filesystem::get_version_path_suffix(), impl_version_get(), is_dev_version(), and gui2::dialogs::migrate_version_selection::migrate_version_selection().
|
inline |
unsigned int version_info::revision_level | ( | ) | const |
Retrieves the revision level (x3 in "x1.x2.x3").
Definition at line 166 of file game_version.cpp.
References nums_.
Referenced by BOOST_AUTO_TEST_CASE(), impl_version_get(), and version_info().
|
inline |
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 170 of file game_version.hpp.
References utf8::index(), and nums_.
void version_info::set_major_version | ( | unsigned int | v | ) |
Sets the major version number.
Definition at line 146 of file game_version.cpp.
References nums_.
Referenced by filesystem::find_other_version_saves_dirs().
void version_info::set_minor_version | ( | unsigned int | v | ) |
void version_info::set_revision_level | ( | unsigned int | v | ) |
|
inline |
Sets the special version suffix.
Definition at line 142 of file game_version.hpp.
|
inline |
Retrieves the special version suffix (e.g.
"dev" in "0.1+dev").
Definition at line 119 of file game_version.hpp.
References special_.
Referenced by BOOST_AUTO_TEST_CASE(), and impl_version_get().
|
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 111 of file game_version.hpp.
References special_separator_.
Referenced by BOOST_AUTO_TEST_CASE(), and impl_version_get().
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 122 of file game_version.cpp.
References nums_, s, special_, and special_separator_.
Referenced by BOOST_AUTO_TEST_CASE(), mp::game_info::check_addon_version_compatibility(), saved_game::check_require_scenario(), savegame::loadgame::check_version_compatibility(), deprecated_message(), gui2::dialogs::describe_status_verbose(), addons_client::download_addon(), preprocessor_data::get_chunk(), wesnothd::server::handle_player(), campaignd::server::handle_upload(), impl_version_tostring(), mp::initial_level_config(), intf_deprecated_message(), game_config_manager::load_addons_cfg(), saved_game::load_non_scenario(), main(), operator std::string(), process_command_args(), preproc_define::read(), gui2::addon_list::set_addons(), set_special_version(), game_classification::to_config(), campaignd::server::validate_addon(), wesnothd::server::version_handler(), version_info(), addon_info::write(), preproc_define::write(), and addon_info::write_minimal().
|
private |
Definition at line 184 of file game_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 185 of file game_version.hpp.
Referenced by set_special_version(), special_version(), str(), and version_info().
|
private |
Definition at line 186 of file game_version.hpp.
Referenced by special_version_separator(), str(), and version_info().