stmm-games-doc  0.32.0
Functions
stmg::XmlUtil Namespace Reference

Functions

void assertTrue (bool bCond)
 Non ODR breaking assert. More...
 
template<typename T >
strToNumber (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sNr, bool bAllowPerc, bool bMin, T oMin, bool bMax, T oMax)
 Convert a string to a number. More...
 
template<typename T >
strToRangeNumber (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sNr, T oMin, T oMax)
 Convert a string to a number in a range. More...
 
bool strToBool (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sTF)
 Converts a string to a boolean value. More...
 
uint32_t strToUint32 (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sUint, bool bMin, uint32_t nMin, bool bMax, uint32_t nMax)
 Converts a string to an unsigned integer. More...
 
TileChar strToTileChar (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sChar)
 
TileColor strToTileColor (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sColor)
 Convert string to tile color. More...
 
RgbColor strHexToRGB (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sHexNr)
 
template<class TokenHandler >
void tokenizer (const std::string &sStr, const std::string &sSeparator, TokenHandler oTokenHandler)
 Separates a string into tokens and passes them to a handler. More...
 

Function Documentation

◆ assertTrue()

void stmg::XmlUtil::assertTrue ( bool  bCond)

Non ODR breaking assert.

Use this instead of the assert macro in header files (usually templates).

Parameters
bCondThe condition to assert.

◆ strHexToRGB()

RgbColor stmg::XmlUtil::strHexToRGB ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sHexNr 
)

◆ strToBool()

bool stmg::XmlUtil::strToBool ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sTF 
)

Converts a string to a boolean value.

The string can be "t", "T", "true", "True", "TRUE", "y", "Y", "yes", "Yes", "YES" or "f", "F", "false", "False", "FALSE", "n", "N", "no", "No", "NO".

Parameters
oCtxThe parser context.
p0ElementThe element of the attribute. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.
sTFThe string value.
Returns
The result value.
Exceptions
Ifstring not valid.

◆ strToNumber()

template<typename T >
T stmg::XmlUtil::strToNumber ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sNr,
bool  bAllowPerc,
bool  bMin,
oMin,
bool  bMax,
oMax 
)

Convert a string to a number.

Parameters
oCtxThe parser context.
p0ElementThe element of the attribute. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.
sNrThe string value.
bAllowPercWhether to allow a trailing '' character, in which case the preceding number is divided by 100.
bMinWhether the result must be bigger or equal oMin.
oMinThe minimum value. Only used if bMin is true.
bMaxWhether the result must be smaller or equal oMax.
oMaxThe maximum value. Only used if bMax is true.
Returns
The result value.
Exceptions
Ifnumber incorrect or not in the specified range.

◆ strToRangeNumber()

template<typename T >
T stmg::XmlUtil::strToRangeNumber ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sNr,
oMin,
oMax 
)

Convert a string to a number in a range.

If the number has a trailing '' it is parsed as a double and must be >= 0 and <= 100. In this case the result is oMin + fPerc * (oMax - oMin).

Parameters
oCtxThe parser context.
p0ElementThe element of the attribute. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.
sNrThe string value.
oMinThe minimum value.
oMaxThe maximum value.
Returns
The result value.
Exceptions
Ifnumber incorrect or not in the specified range.

◆ strToTileChar()

TileChar stmg::XmlUtil::strToTileChar ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sChar 
)

◆ strToTileColor()

TileColor stmg::XmlUtil::strToTileColor ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sColor 
)

Convert string to tile color.

Expects the string to be stripped of leading and trailing whitespace.

Parameters
oCtxThe parsing context.
p0ElementThe element. Can be null.
sAttrNameThe attribute name.
sColorThe string. Cannot be empty.
Returns
The tile color.
Exceptions
Iferror.

◆ strToUint32()

uint32_t stmg::XmlUtil::strToUint32 ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sUint,
bool  bMin,
uint32_t  nMin,
bool  bMax,
uint32_t  nMax 
)

Converts a string to an unsigned integer.

The string can contain the hexadecimal representation, in which case the string must have leading characters "0x". No whitespace is allowed.

Examples: valid strings "42", "0xA6C". Invalid strings: " 0xA6C", "0x A6C"

Parameters
oCtxThe parser context.
p0ElementThe element of the attribute. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.
sUintThe string value.
bMinWhether the result must be bigger or equal nMin.
nMinThe minimum value. Only used if bMin is true.
bMaxWhether the result must be smaller or equal nMax.
nMaxThe maximum value. Only used if bMax is true.
Returns
The result value.
Exceptions
Ifnumber incorrect or not in the specified range.

◆ tokenizer()

template<class TokenHandler >
void stmg::XmlUtil::tokenizer ( const std::string &  sStr,
const std::string &  sSeparator,
TokenHandler  oTokenHandler 
)

Separates a string into tokens and passes them to a handler.

The tokens are stripped of leading and trailing spaces and can be empty.

Parameters
sStrThe string to tokenize.
sSeparatorThe separator string. Cannot be empty.
oTokenHandlerThe function object taking a string as parameter.