PGE API 0.4
PR00F's Game Engine full documentation
Loading...
Searching...
No Matches
PGEcfgVariable Class Reference

PR00F's Game Engine cfg variable (cvar) class. More...

Detailed Description

PR00F's Game Engine cfg variable (cvar) class.

This class can hold a value of an arbitrary type.

Definition at line 44 of file PGEcfgVariable.h.

#include <PGEcfgVariable.h>

Public Member Functions

 PGEcfgVariable ()
 Constructs a string-typed cvar.
 
 PGEcfgVariable (const int &value)
 Constructs an integer-typed cvar.
 
 PGEcfgVariable (const unsigned int &value)
 Constructs an unsigned integer-typed cvar.
 
 PGEcfgVariable (const float &value)
 Constructs a floating point-typed cvar.
 
 PGEcfgVariable (const bool &value)
 Constructs a boolean-typed cvar.
 
 PGEcfgVariable (const char *value)
 Constructs a string-typed cvar.
 
 PGEcfgVariable (const std::string &value)
 Constructs a string-typed cvar.
 
virtual ~PGEcfgVariable ()
 
int getAsInt () const noexcept(true)
 Tries to return the value of the cvar as an integer.
 
unsigned int getAsUInt () const noexcept(true)
 Tries to return the value of the cvar as an unsigned integer.
 
float getAsFloat () const noexcept(true)
 Tries to return the value of the cvar as a floating point number.
 
bool getAsBool () const noexcept(true)
 Returns the value of the cvar as a boolean.
 
const std::string & getAsString () const noexcept(true)
 Returns the value of the cvar as a string.
 
const TPGE_CFG_VARIABLE_TYPEgetType () const noexcept(true)
 Returns the type of the cvar.
 
void Set (const int &value)
 
void Set (const unsigned int &value)
 
void Set (const float &value)
 
void Set (const bool &value)
 
void Set (const char *value)
 
void Set (const std::string &value)
 
std::string & getShortHint ()
 Get/Set for a short one-liner description of this CVAR.
 
const std::string & getShortHint () const
 Getter for a short one-liner description of this CVAR.
 
std::vector< std::string > & getLongHint ()
 Get/Set for a longer description of this CVAR.
 
const std::vector< std::string > & getLongHint () const
 Getter for a longer description of this CVAR.
 
bool operator== (const int &other) const
 Equals to.
 
bool operator== (const unsigned int &other) const
 Equals to.
 
bool operator== (const float &other) const
 Equals to.
 
bool operator== (const bool &other) const
 Equals to.
 
bool operator== (const std::string &other) const
 Equals to.
 
bool operator== (const PGEcfgVariable &other) const
 Equals to.
 
bool operator!= (const int &other) const
 Not equals to.
 
bool operator!= (const unsigned int &other) const
 Not equals to.
 
bool operator!= (const float &other) const
 Not equals to.
 
bool operator!= (const bool &other) const
 Not equals to.
 
bool operator!= (const std::string &other) const
 Not equals to.
 
bool operator!= (const PGEcfgVariable &other) const
 Not equals to.
 
PGEcfgVariableoperator= (const PGEcfgVariable &other)
 Assignment.
 
PGEcfgVariable operator+ (const PGEcfgVariable &other) const
 Addition.
 
PGEcfgVariableoperator+= (const PGEcfgVariable &other)
 Addition assignment.
 
PGEcfgVariable operator- (const PGEcfgVariable &other) const
 Subtraction.
 
PGEcfgVariableoperator-= (const PGEcfgVariable &other)
 Subtraction assignment.
 
PGEcfgVariable operator* (const PGEcfgVariable &other) const
 Multiplication by scalar.
 
PGEcfgVariableoperator*= (const PGEcfgVariable &other)
 Multiplication assignment.
 
PGEcfgVariable operator/ (const PGEcfgVariable &other) const
 Division by scalar.
 
PGEcfgVariableoperator/= (const PGEcfgVariable &other)
 Division assignment.
 
PGEcfgVariable operator% (const PGEcfgVariable &other) const
 Modulo division by scalar.
 
PGEcfgVariableoperator%= (const PGEcfgVariable &other)
 Modulo division assignment.
 
PGEcfgVariableoperator++ ()
 Prefix increment.
 
PGEcfgVariable operator++ (int)
 Postfix increment.
 
PGEcfgVariableoperator-- ()
 Prefix decrement.
 
PGEcfgVariable operator-- (int)
 Postfix decrement.
 

Private Attributes

std::string sValue
 
TPGE_CFG_VARIABLE_TYPE type
 
std::string sShortHint
 
std::vector< std::string > vsLongHint
 

Constructor & Destructor Documentation

◆ PGEcfgVariable() [1/7]

PGEcfgVariable::PGEcfgVariable ( )

Constructs a string-typed cvar.

Definition at line 37 of file PGEcfgVariable.cpp.

◆ PGEcfgVariable() [2/7]

PGEcfgVariable::PGEcfgVariable ( const int & value)

Constructs an integer-typed cvar.

Definition at line 45 of file PGEcfgVariable.cpp.

◆ PGEcfgVariable() [3/7]

PGEcfgVariable::PGEcfgVariable ( const unsigned int & value)

Constructs an unsigned integer-typed cvar.

Definition at line 53 of file PGEcfgVariable.cpp.

◆ PGEcfgVariable() [4/7]

PGEcfgVariable::PGEcfgVariable ( const float & value)

Constructs a floating point-typed cvar.

Definition at line 61 of file PGEcfgVariable.cpp.

◆ PGEcfgVariable() [5/7]

PGEcfgVariable::PGEcfgVariable ( const bool & value)

Constructs a boolean-typed cvar.

Definition at line 69 of file PGEcfgVariable.cpp.

◆ PGEcfgVariable() [6/7]

PGEcfgVariable::PGEcfgVariable ( const char * value)

Constructs a string-typed cvar.

Definition at line 77 of file PGEcfgVariable.cpp.

◆ PGEcfgVariable() [7/7]

PGEcfgVariable::PGEcfgVariable ( const std::string & value)

Constructs a string-typed cvar.

Definition at line 85 of file PGEcfgVariable.cpp.

◆ ~PGEcfgVariable()

PGEcfgVariable::~PGEcfgVariable ( )
virtual

Definition at line 90 of file PGEcfgVariable.cpp.

Member Function Documentation

◆ getAsBool()

bool PGEcfgVariable::getAsBool ( ) const
noexcept

Returns the value of the cvar as a boolean.

Returns
True in the following cases:
  • type of cvar is string and value is "true" (not case-sensitive)
  • type of cvar is string and can be converted to a non-null numeric value
  • type of cvar is int or float and value is not 0
  • type of cvar is bool and value is true (trivial case) False in any other cases.

Definition at line 174 of file PGEcfgVariable.cpp.

◆ getAsFloat()

float PGEcfgVariable::getAsFloat ( ) const
noexcept

Tries to return the value of the cvar as a floating point number.

Returns
If the type of the cvar is bool or the cvar can be converted to bool, true value results in 1.f, and false value results in 0.f. If the type of the cvar is float or string, the result will be the same as calling std::stof() with the float or string, except that this function doesn't throw exception but silently returns 0.f in case of error.

Definition at line 149 of file PGEcfgVariable.cpp.

◆ getAsInt()

int PGEcfgVariable::getAsInt ( ) const
noexcept

Tries to return the value of the cvar as an integer.

Returns
If the type of the cvar is bool or the cvar can be converted to bool, true value results in 1, and false value results in 0. If the type of the cvar is float or string, the result will be the same as calling std::stol() with the float or string, except that this function doesn't throw exception but silently returns 0 in case of error.

Definition at line 103 of file PGEcfgVariable.cpp.

◆ getAsString()

const std::string & PGEcfgVariable::getAsString ( ) const
noexcept

Returns the value of the cvar as a string.

Returns
The value of the cvar as it is as a string.

Definition at line 205 of file PGEcfgVariable.cpp.

◆ getAsUInt()

unsigned int PGEcfgVariable::getAsUInt ( ) const
noexcept

Tries to return the value of the cvar as an unsigned integer.

Returns
If the type of the cvar is bool or the cvar can be converted to bool, true value results in 1, and false value results in 0. If the type of the cvar is float or string, the result will be the same as calling std::stoul() with the float or string, except that this function doesn't throw exception but silently returns 0 in case of error.

Definition at line 126 of file PGEcfgVariable.cpp.

◆ getLongHint() [1/2]

std::vector< std::string > & PGEcfgVariable::getLongHint ( )

Get/Set for a longer description of this CVAR.

This text will appear in the configuration file right below the CVAR definition, it can explain the purpose and effects of this CVAR in more details, even in multiple lines. You can wrap this text into multiple lines: one element of the vector represent one line. Just make sure a single line is no longer than 80-120 characters so no "word wrap" is needed to be enabled in a text editor for properly viewing the configuration file. Neither the short- nor the long hint text is mandatory.

Returns
Reference to the long text description of this CVAR.

Definition at line 300 of file PGEcfgVariable.cpp.

◆ getLongHint() [2/2]

const std::vector< std::string > & PGEcfgVariable::getLongHint ( ) const

Getter for a longer description of this CVAR.

This text will appear in the configuration file right below the CVAR definition, it can explain the purpose and effects of this CVAR in more details, even in multiple lines. You can wrap this text into multiple lines: one element of the vector represent one line. Just make sure a single line is no longer than 80-120 characters so no "word wrap" is needed to be enabled in a text editor for properly viewing the configuration file. Neither the short- nor the long hint text is mandatory.

Returns
Reference to the long text description of this CVAR.

Definition at line 316 of file PGEcfgVariable.cpp.

◆ getShortHint() [1/2]

std::string & PGEcfgVariable::getShortHint ( )

Get/Set for a short one-liner description of this CVAR.

This one-liner will appear in the configuration file right above the CVAR definition, so it should not be longer than 80-120 characters. Neither the short- nor the long hint string is mandatory.

Returns
Reference to the short one-liner string description of this CVAR.

Definition at line 271 of file PGEcfgVariable.cpp.

◆ getShortHint() [2/2]

const std::string & PGEcfgVariable::getShortHint ( ) const

Getter for a short one-liner description of this CVAR.

This one-liner will appear in the configuration file right above the CVAR definition, so it should not be longer than 80-120 characters. Neither the short- nor the long hint string is mandatory.

Returns
Reference to the short one-liner string description of this CVAR.

Definition at line 284 of file PGEcfgVariable.cpp.

◆ getType()

const TPGE_CFG_VARIABLE_TYPE & PGEcfgVariable::getType ( ) const
noexcept

Returns the type of the cvar.

Returns
The type of the cvar. See detailed description at the description of TPGE_CFG_VARIABLE_TYPE.

Definition at line 216 of file PGEcfgVariable.cpp.

◆ operator!=() [1/6]

bool PGEcfgVariable::operator!= ( const bool & other) const

Not equals to.

Definition at line 429 of file PGEcfgVariable.cpp.

◆ operator!=() [2/6]

bool PGEcfgVariable::operator!= ( const float & other) const

Not equals to.

Definition at line 421 of file PGEcfgVariable.cpp.

◆ operator!=() [3/6]

bool PGEcfgVariable::operator!= ( const int & other) const

Not equals to.

Definition at line 405 of file PGEcfgVariable.cpp.

◆ operator!=() [4/6]

bool PGEcfgVariable::operator!= ( const PGEcfgVariable & other) const

Not equals to.

Definition at line 445 of file PGEcfgVariable.cpp.

◆ operator!=() [5/6]

bool PGEcfgVariable::operator!= ( const std::string & other) const

Not equals to.

Definition at line 437 of file PGEcfgVariable.cpp.

◆ operator!=() [6/6]

bool PGEcfgVariable::operator!= ( const unsigned int & other) const

Not equals to.

Definition at line 413 of file PGEcfgVariable.cpp.

◆ operator%()

PGEcfgVariable PGEcfgVariable::operator% ( const PGEcfgVariable & other) const

Modulo division by scalar.

Modulo division is supported for int-typed and unsigned int-typed cvars only.

Returns
The returned cvar highly depends on the type of the operands and is determined in the following order: If the type of at least one of the operands is not int or unsigned int, the result will be a copy of the first cvar. If the divider is 0, the result will be a copy of the first cvar. If any of the operands is unsigned int, the result will be unsigned int-typed. Otherwise, the result will be int-typed.

Definition at line 630 of file PGEcfgVariable.cpp.

◆ operator%=()

PGEcfgVariable & PGEcfgVariable::operator%= ( const PGEcfgVariable & other)

Modulo division assignment.

Definition at line 664 of file PGEcfgVariable.cpp.

◆ operator*()

PGEcfgVariable PGEcfgVariable::operator* ( const PGEcfgVariable & other) const

Multiplication by scalar.

Multiplication of bool-typed and string-typed cvars is not supported. Multiplication is supported for int-, unsigned int- and float-typed cvars.

Returns
The returned cvar highly depends on the type of the operands and is determined in the following order: If the type of at least one of the cvars is bool or string, the result will be a copy of the first cvar. If the type of at least one of the cvars is float, the result will be float-typed. If the type of at least one of the cvars is unsigned int, the result will be unsigned int-typed. Otherwise, the result will be int-typed.

Definition at line 551 of file PGEcfgVariable.cpp.

◆ operator*=()

PGEcfgVariable & PGEcfgVariable::operator*= ( const PGEcfgVariable & other)

Multiplication assignment.

Definition at line 571 of file PGEcfgVariable.cpp.

◆ operator+()

PGEcfgVariable PGEcfgVariable::operator+ ( const PGEcfgVariable & other) const

Addition.

Addition of bool-typed cvars is not supported. Addition is supported for int-, unsigned int-, float- and string-typed cvars.

Returns
The returned cvar highly depends on the type of the operands and is determined in the following order: If the type of at least one of the cvars is bool, the result will be a copy of the first cvar. If the type of at least one of the cvars is string, the result will be a concatenated string form of the 2 cvars. If the type of at least one of the cvars is float, the result will be float-typed. If the type of at least one of the cvars is unsigned int, the result will be unsigned int-typed. Otherwise, the result will be int-typed.

Definition at line 475 of file PGEcfgVariable.cpp.

◆ operator++() [1/2]

PGEcfgVariable & PGEcfgVariable::operator++ ( )

Prefix increment.

This only works if the type of the cvar is int or unsigned int.

Definition at line 675 of file PGEcfgVariable.cpp.

◆ operator++() [2/2]

PGEcfgVariable PGEcfgVariable::operator++ ( int )

Postfix increment.

This only works if the type of the cvar is int or unsigned int.

Definition at line 692 of file PGEcfgVariable.cpp.

◆ operator+=()

PGEcfgVariable & PGEcfgVariable::operator+= ( const PGEcfgVariable & other)

Addition assignment.

Definition at line 495 of file PGEcfgVariable.cpp.

◆ operator-()

PGEcfgVariable PGEcfgVariable::operator- ( const PGEcfgVariable & other) const

Subtraction.

Subtraction of bool-typed and string-typed cvars is not supported. Subtraction is supported for int-, unsigned int- and float-typed cvars.

Returns
The returned cvar highly depends on the type of the operands and is determined in the following order: If the type of at least one of the cvars is bool or string, the result will be a copy of the first cvar. If the type of at least one of the cvars is float, the result will be float-typed. If the type of at least one of the cvars is unsigned int, the result will be unsigned int-typed. Otherwise, the result will be int-typed.

Definition at line 513 of file PGEcfgVariable.cpp.

◆ operator--() [1/2]

PGEcfgVariable & PGEcfgVariable::operator-- ( )

Prefix decrement.

This only works if the type of the cvar is int or unsigned int.

Definition at line 713 of file PGEcfgVariable.cpp.

◆ operator--() [2/2]

PGEcfgVariable PGEcfgVariable::operator-- ( int )

Postfix decrement.

This only works if the type of the cvar is int or unsigned int.

Definition at line 730 of file PGEcfgVariable.cpp.

◆ operator-=()

PGEcfgVariable & PGEcfgVariable::operator-= ( const PGEcfgVariable & other)

Subtraction assignment.

Definition at line 533 of file PGEcfgVariable.cpp.

◆ operator/()

PGEcfgVariable PGEcfgVariable::operator/ ( const PGEcfgVariable & other) const

Division by scalar.

Division of bool-typed and string-typed cvars is not supported. Division is supported for int-, unsigned int- and float-typed cvars.

Returns
The returned cvar highly depends on the type of the operands and is determined in the following order: If the type of at least one of the cvars is bool or string, the result will be a copy of the first cvar. If the divider is 0, the result will be a copy of the first cvar. If the type of at least one of the cvars is float, the result will be float-typed. If the type of at least one of the cvars is unsigned int, the result will be unsigned int-typed. Otherwise, the result will be int-typed.

Definition at line 590 of file PGEcfgVariable.cpp.

◆ operator/=()

PGEcfgVariable & PGEcfgVariable::operator/= ( const PGEcfgVariable & other)

Division assignment.

Definition at line 613 of file PGEcfgVariable.cpp.

◆ operator=()

PGEcfgVariable & PGEcfgVariable::operator= ( const PGEcfgVariable & other)

Assignment.

Definition at line 454 of file PGEcfgVariable.cpp.

◆ operator==() [1/6]

bool PGEcfgVariable::operator== ( const bool & other) const

Equals to.

Returns
True if the cvar can be interpreted as the same bool as the given bool, false otherwise.

Definition at line 373 of file PGEcfgVariable.cpp.

◆ operator==() [2/6]

bool PGEcfgVariable::operator== ( const float & other) const

Equals to.

Returns
True if the cvar can be interpreted as the same float as the given float, false otherwise. If the cvar is bool-typed, the result will depend on whether value is true or false and the float is 0 or non-0.

Definition at line 358 of file PGEcfgVariable.cpp.

◆ operator==() [3/6]

bool PGEcfgVariable::operator== ( const int & other) const

Equals to.

Returns
True if the cvar can be interpreted as the same int as the given int, false otherwise. If the cvar is bool-typed, the result will depend on whether value is true or false and the int is 0 or non-0.

Definition at line 326 of file PGEcfgVariable.cpp.

◆ operator==() [4/6]

bool PGEcfgVariable::operator== ( const PGEcfgVariable & other) const

Equals to.

Returns
True if not only the value but also the type of the cvars are equal, false otherwise.

Definition at line 397 of file PGEcfgVariable.cpp.

◆ operator==() [5/6]

bool PGEcfgVariable::operator== ( const std::string & other) const

Equals to.

Returns
True if the cvar can be interpreted as the same string as the given string, false otherwise. If the cvar is bool-typed, the result will depend on whether the given string can be interpreted as the same bool.

Definition at line 383 of file PGEcfgVariable.cpp.

◆ operator==() [6/6]

bool PGEcfgVariable::operator== ( const unsigned int & other) const

Equals to.

Returns
True if the cvar can be interpreted as the same unsigned int as the given unsigned int, false otherwise. If the cvar is bool-typed, the result will depend on whether value is true or false and the unsigned int is 0u or non-0u.

Definition at line 342 of file PGEcfgVariable.cpp.

◆ Set() [1/6]

void PGEcfgVariable::Set ( const bool & value)

Definition at line 245 of file PGEcfgVariable.cpp.

◆ Set() [2/6]

void PGEcfgVariable::Set ( const char * value)

Definition at line 251 of file PGEcfgVariable.cpp.

◆ Set() [3/6]

void PGEcfgVariable::Set ( const float & value)

Definition at line 237 of file PGEcfgVariable.cpp.

◆ Set() [4/6]

void PGEcfgVariable::Set ( const int & value)

Definition at line 221 of file PGEcfgVariable.cpp.

◆ Set() [5/6]

void PGEcfgVariable::Set ( const std::string & value)

Definition at line 257 of file PGEcfgVariable.cpp.

◆ Set() [6/6]

void PGEcfgVariable::Set ( const unsigned int & value)

Definition at line 229 of file PGEcfgVariable.cpp.

Member Data Documentation

◆ sShortHint

std::string PGEcfgVariable::sShortHint
private

Definition at line 115 of file PGEcfgVariable.h.

◆ sValue

std::string PGEcfgVariable::sValue
private

Definition at line 113 of file PGEcfgVariable.h.

◆ type

TPGE_CFG_VARIABLE_TYPE PGEcfgVariable::type
private

Definition at line 114 of file PGEcfgVariable.h.

◆ vsLongHint

std::vector<std::string> PGEcfgVariable::vsLongHint
private

Definition at line 116 of file PGEcfgVariable.h.


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