The Battle for Wesnoth  1.19.5+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 (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_
 

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

Constructor & Destructor Documentation

◆ version_info() [1/5]

version_info::version_info ( )

Default constructor.

Definition at line 49 of file game_version.cpp.

◆ version_info() [2/5]

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() [3/5]

version_info::version_info ( const char *  str)

Definition at line 54 of file game_version.cpp.

◆ version_info() [4/5]

version_info::version_info ( std::nullptr_t  )
delete

◆ version_info() [5/5]

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

Member Function Documentation

◆ components()

const std::vector<unsigned int>& version_info::components ( ) const
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().

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

References utf8::index(), and 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 170 of file game_version.cpp.

References nums_.

Referenced by BOOST_AUTO_TEST_CASE(), and impl_version_get().

◆ is_dev_version()

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

◆ major_version()

unsigned int version_info::major_version ( ) const

◆ minor_version()

unsigned int version_info::minor_version ( ) const

◆ operator std::string()

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

Syntactic shortcut for str().

Definition at line 81 of file game_version.hpp.

References str().

◆ revision_level()

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

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

References utf8::index(), and nums_.

◆ set_major_version()

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

◆ set_minor_version()

void version_info::set_minor_version ( unsigned int  v)

Sets the minor version number.

Definition at line 150 of file game_version.cpp.

References nums_.

◆ set_revision_level()

void version_info::set_revision_level ( unsigned int  v)

Sets the revision level.

Definition at line 154 of file game_version.cpp.

References nums_.

◆ set_special_version()

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

Sets the special version suffix.

Definition at line 142 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 119 of file game_version.hpp.

References special_.

Referenced by BOOST_AUTO_TEST_CASE(), and impl_version_get().

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

References special_separator_.

Referenced by BOOST_AUTO_TEST_CASE(), and impl_version_get().

◆ 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 185 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 186 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: