The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Attributes | List of all members
version_info Class Reference

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::stringspecial_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 intnums_
 
std::string special_
 
char special_separator_
 

Detailed Description

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.

Constructor & Destructor Documentation

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

Member Function Documentation

const std::vector<unsigned int>& version_info::components ( ) const
inline

Read-only access to all numeric components.

Definition at line 171 of file version.hpp.

References nums_.

unsigned int version_info::get_component ( size_t  index) const
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().

Exceptions
std::out_of_rangeIf 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().

version_info::operator std::string ( ) const
inline

Syntactic shortcut for str().

Definition at line 74 of file version.hpp.

References str().

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

void version_info::set_component ( size_t  index,
unsigned int  value 
)
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().

Exceptions
std::out_of_rangeIf the number of components is less than index - 1.

Definition at line 163 of file version.hpp.

References nums_.

void version_info::set_major_version ( unsigned int  v)

Sets the major version number.

Definition at line 114 of file version.cpp.

References nums_.

void version_info::set_minor_version ( unsigned int  v)

Sets the minor version number.

Definition at line 118 of file version.cpp.

References nums_.

void version_info::set_revision_level ( unsigned int  v)

Sets the revision level.

Definition at line 122 of file version.cpp.

References nums_.

void version_info::set_special_version ( const std::string str)
inline

Sets the special version suffix.

Definition at line 135 of file version.hpp.

References special_, and str().

const std::string& version_info::special_version ( ) const
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>().

char version_info::special_version_separator ( ) const
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().

Member Data Documentation

std::vector<unsigned int> version_info::nums_
private
std::string version_info::special_
private

Definition at line 178 of file version.hpp.

Referenced by set_special_version(), special_version(), str(), and version_info().

char version_info::special_separator_
private

Definition at line 179 of file version.hpp.

Referenced by special_version_separator(), str(), and version_info().


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