The Battle for Wesnoth  1.15.1+dev
Public Member Functions | Private Attributes | List of all members
version_info Class Reference

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 (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 (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_
 

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 43 of file game_version.hpp.

Constructor & Destructor Documentation

◆ version_info() [1/4]

version_info::version_info ( )

Default constructor.

Definition at line 47 of file game_version.cpp.

◆ version_info() [2/4]

version_info::version_info ( const std::string &  str)

String constructor.

Definition at line 66 of file game_version.cpp.

References components(), i, nums_, s, special_, special_separator_, utils::split(), and str().

◆ version_info() [3/4]

version_info::version_info ( const char *  str)

Definition at line 52 of file game_version.cpp.

◆ version_info() [4/4]

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 57 of file game_version.cpp.

References nums_, and revision_level().

Member Function Documentation

◆ components()

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

Read-only access to all numeric components.

Definition at line 171 of file game_version.hpp.

References nums_.

Referenced by is_canonical(), and version_info().

◆ get_component()

unsigned int version_info::get_component ( std::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 game_version.hpp.

References nums_.

◆ is_canonical()

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 168 of file game_version.cpp.

References components(), nums_, and special_version().

Referenced by BOOST_AUTO_TEST_CASE().

◆ major_version()

unsigned int version_info::major_version ( ) const

Retrieves the major version number (x1 in "x1.x2.x3").

Definition at line 156 of file game_version.cpp.

References nums_.

Referenced by BOOST_AUTO_TEST_CASE(), savegame::loadgame::check_version_compatibility(), filesystem::get_version_path_suffix(), and operator std::string().

◆ minor_version()

unsigned int version_info::minor_version ( ) const

Retrieves the minor version number (x2 in "x1.x2.x3").

Definition at line 160 of file game_version.cpp.

References nums_.

Referenced by BOOST_AUTO_TEST_CASE(), savegame::loadgame::check_version_compatibility(), filesystem::get_version_path_suffix(), and operator std::string().

◆ operator std::string()

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

Syntactic shortcut for str().

Definition at line 74 of file game_version.hpp.

References major_version(), minor_version(), revision_level(), and str().

◆ revision_level()

unsigned int version_info::revision_level ( ) const

Retrieves the revision level (x3 in "x1.x2.x3").

Definition at line 164 of file game_version.cpp.

References nums_.

Referenced by BOOST_AUTO_TEST_CASE(), operator std::string(), and version_info().

◆ set_component()

void version_info::set_component ( std::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 game_version.hpp.

References nums_.

◆ set_major_version()

void version_info::set_major_version ( unsigned int  v)

Sets the major version number.

Definition at line 144 of file game_version.cpp.

References nums_.

Referenced by special_version().

◆ set_minor_version()

void version_info::set_minor_version ( unsigned int  v)

Sets the minor version number.

Definition at line 148 of file game_version.cpp.

References nums_.

Referenced by special_version().

◆ set_revision_level()

void version_info::set_revision_level ( unsigned int  v)

Sets the revision level.

Definition at line 152 of file game_version.cpp.

References nums_.

Referenced by special_version().

◆ set_special_version()

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

Sets the special version suffix.

Definition at line 135 of file game_version.hpp.

References special_, and str().

◆ special_version()

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

References set_major_version(), set_minor_version(), set_revision_level(), and special_.

Referenced by BOOST_AUTO_TEST_CASE(), and is_canonical().

◆ special_version_separator()

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

References special_separator_.

Referenced by BOOST_AUTO_TEST_CASE().

◆ str()

std::string version_info::str ( ) const

Member Data Documentation

◆ nums_

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

◆ special_

std::string version_info::special_
private

Definition at line 178 of file game_version.hpp.

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

◆ special_separator_

char version_info::special_separator_
private

Definition at line 179 of file game_version.hpp.

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


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