stmm-games-doc  0.32.0
Static Public Member Functions | Static Public Attributes | List of all members
stmg::XmlCommonParser Class Reference

Static Public Member Functions

static bool validateName (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::string &sName, bool bAllowAny)
 Tells whether a string is a valid name. More...
 
static const xmlpp::Element * parseUniqueElement (ParserCtx &oCtx, const xmlpp::Element *p0Parent, const std::string &sName, bool bMandatory)
 
static std::pair< bool, std::string > getAttributeValue (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttr0)
 
static std::pair< bool, std::string > getAttributeValue (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttr0, const std::string &sAttr1)
 
static std::string parseSeparator (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sSeparatorAttr)
 Parse for value separator string. More...
 
static std::pair< bool, IntSetparseIntSetAttrs (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sSingleAttr, const std::string &sFromAttr, const std::string &sToAttr, const std::string &sStepAttr, const std::string &sMultiAttr, const std::string &sSeparatorAttr, bool bMin, int32_t nMin, bool bMax, int32_t nMax)
 Parse IntSet attributes. More...
 
template<typename T >
static bool parseAttrFromTo (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sSingleAttr, const std::string &sFromAttr, const std::string &sToAttr, bool bMandatory, bool bMin, T oMin, bool bMax, T oMax, T &oFrom, T &oTo)
 Parse from to attributes. More...
 
template<typename T >
static bool parseAttrFromToClamp (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sSingleAttr, const std::string &sFromAttr, const std::string &sToAttr, bool bMandatory, bool bMin, T oMin, bool bMax, T oMax, T &oFrom, T &oTo)
 
template<class ChildVisitor >
static void visitNamedElementChildren (ParserCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sName, ChildVisitor oChildVisitor)
 Visits all child elements of a node that have a certain name. More...
 
template<class ChildVisitor >
static void visitElementChildren (ParserCtx &oCtx, const xmlpp::Element *p0Element, ChildVisitor oChildVisitor)
 Visits all child elements of a node. More...
 
template<class P >
static void checkAllChildElementsName (ParserCtx &oCtx, const xmlpp::Node *p0Parent, P oP)
 Checks whether the names of all the child elements of a node satisfy a predicate. More...
 
template<class P >
static void checkAllAttributesNames (ParserCtx &oCtx, const xmlpp::Element *p0Element, P oP)
 Checks whether all the attributes of an element have a name that satisfies a predicate. More...
 

Static Public Attributes

static const std::string s_sAttrNameIgnorePrefix
 
static const std::string s_sElementNameIgnorePrefix
 

Member Function Documentation

◆ checkAllAttributesNames()

template<class P >
static void stmg::XmlCommonParser::checkAllAttributesNames ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
oP 
)
inlinestatic

Checks whether all the attributes of an element have a name that satisfies a predicate.

The function object must define bool operator()(const std::string& sName).

Attributes that start with s_sAttrNameIgnorePrefix ("_ign_") are ignored. This can be useful for testing purposes.

If one predicate call returns false an invalid attribute exception is thrown.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
oPThe function object (predicate).

◆ checkAllChildElementsName()

template<class P >
static void stmg::XmlCommonParser::checkAllChildElementsName ( ParserCtx oCtx,
const xmlpp::Node *  p0Parent,
oP 
)
inlinestatic

Checks whether the names of all the child elements of a node satisfy a predicate.

The function object must define bool operator()(const std::string& sName). If one predicate call returns false an invalid element exception is thrown. Ignored elements are skipped.

Parameters
oCtxThe context.
p0ParentThe parent node. Cannot be null.
oPThe function object (predicate).

◆ getAttributeValue() [1/2]

static std::pair<bool, std::string> stmg::XmlCommonParser::getAttributeValue ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttr0 
)
static

◆ getAttributeValue() [2/2]

static std::pair<bool, std::string> stmg::XmlCommonParser::getAttributeValue ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttr0,
const std::string &  sAttr1 
)
static

◆ parseAttrFromTo()

template<typename T >
static bool stmg::XmlCommonParser::parseAttrFromTo ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sSingleAttr,
const std::string &  sFromAttr,
const std::string &  sToAttr,
bool  bMandatory,
bool  bMin,
oMin,
bool  bMax,
oMax,
T &  oFrom,
T &  oTo 
)
inlinestatic

Parse from to attributes.

If bMin is false oMin is overridden to std::numeric_limits<T>::lowest(). If bMax is false oMax is overridden to std::numeric_limits<T>::max(). If both true, oMin must not be smaller than oMin.

If no attribute is defined, the values oFrom and oTo are untouched if their current value satisfies the optional min and max conditions. Otherwise they are clamped to (oMin, oMax).

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sSingleAttrThe single attribute name.
sFromAttrThe 'from' attribute name.
sToAttrThe 'to' attribute name.
bMandatoryWhether one of the attributes must be defined.
bMinWhether the range has a minimum.
oMinThe minimum value, if bMin is true.
bMaxWhether the range has a maximum.
oMaxThe maximum value, if bMax is true.
oFromThe resulting 'from' value. Untouched if no attribute defined.
oToThe resulting 'to' value. Untouched if no attribute defined.
Returns
Whether one of the attributes was defined.

◆ parseAttrFromToClamp()

template<typename T >
static bool stmg::XmlCommonParser::parseAttrFromToClamp ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sSingleAttr,
const std::string &  sFromAttr,
const std::string &  sToAttr,
bool  bMandatory,
bool  bMin,
oMin,
bool  bMax,
oMax,
T &  oFrom,
T &  oTo 
)
inlinestatic

◆ parseIntSetAttrs()

static std::pair<bool, IntSet> stmg::XmlCommonParser::parseIntSetAttrs ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sSingleAttr,
const std::string &  sFromAttr,
const std::string &  sToAttr,
const std::string &  sStepAttr,
const std::string &  sMultiAttr,
const std::string &  sSeparatorAttr,
bool  bMin,
int32_t  nMin,
bool  bMax,
int32_t  nMax 
)
static

Parse IntSet attributes.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sSingleAttrThe single attribute name.
sFromAttrThe 'from' range attribute name.
sToAttrThe 'to' range attribute name.
sStepAttrThe 'step' attribute name.
sMultiAttrThe attribute name containing (usually) comma separated values.
sSeparatorAttrThe separator string. Cannot contain spaces. If empty comma is used.
bMinWhether the range has a minimum.
nMinThe minimum value, if bMin is true.
bMaxWhether the range has a maximum.
nMaxThe maximum value, if bMax is true.
Returns
Whether one of the attributes was defined and the resulting IntSet.

◆ parseSeparator()

static std::string stmg::XmlCommonParser::parseSeparator ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sSeparatorAttr 
)
static

Parse for value separator string.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sSeparatorAttrThe separator attribute. If empty the default separator is returned.
Returns
The separator string. Is not empty.

◆ parseUniqueElement()

static const xmlpp::Element* stmg::XmlCommonParser::parseUniqueElement ( ParserCtx oCtx,
const xmlpp::Element *  p0Parent,
const std::string &  sName,
bool  bMandatory 
)
static

◆ validateName()

static bool stmg::XmlCommonParser::validateName ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::string &  sName,
bool  bAllowAny 
)
static

Tells whether a string is a valid name.

Parameters
oCtxThe parser context. Used to throw.
p0ElementThe element. Can be null.
sAttrNameThe attribute name the value of which is checked.
sNameThe UTF8 name.
bAllowAnyWhether to allow "*" (any) name.
Returns
Whether it is the "*" (any) name.
Exceptions
Ifname not valid.

◆ visitElementChildren()

template<class ChildVisitor >
static void stmg::XmlCommonParser::visitElementChildren ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
ChildVisitor  oChildVisitor 
)
inlinestatic

Visits all child elements of a node.

The function object must define operator()(const xmlpp::Element* p0ChildElement).

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
oChildVisitorThe function object taking a (child) element as parameter.

◆ visitNamedElementChildren()

template<class ChildVisitor >
static void stmg::XmlCommonParser::visitNamedElementChildren ( ParserCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sName,
ChildVisitor  oChildVisitor 
)
inlinestatic

Visits all child elements of a node that have a certain name.

The function object must define operator()(const xmlpp::Element* p0ChildElement). If sName is empty, ignored elements are skipped.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sNameThe name. If empty all children are visited.
oChildVisitorThe function object taking a (child) element as parameter.

Member Data Documentation

◆ s_sAttrNameIgnorePrefix

const std::string stmg::XmlCommonParser::s_sAttrNameIgnorePrefix
static

◆ s_sElementNameIgnorePrefix

const std::string stmg::XmlCommonParser::s_sElementNameIgnorePrefix
static