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

Public Member Functions

 XmlConditionalParser (XmlVariantSetParser &oXmlVariantSetParser)
 Constructor. More...
 
template<class ChildVisitor >
void visitNamedElementChildren (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sName, ChildVisitor oChildVisitor) const
 Visit children elements with a given name applying nested ExistIf conditions. More...
 
template<class ChildVisitor >
void visitElementChildren (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, ChildVisitor oChildVisitor) const
 Visit all children applying nested ExistIf conditions. More...
 
const xmlpp::Element * parseUniqueElement (ConditionalCtx &oCtx, const xmlpp::Element *p0Parent, const std::string &sName, bool bMandatory) const
 Parse at most one child element with given name. More...
 
template<class P >
void checkAllChildElementsName (ConditionalCtx &oCtx, const xmlpp::Node *p0Parent, P oP) const
 Checks whether the names of all the child elements of a node satisfy a predicate. More...
 
std::pair< bool, std::string > getAttributeValue (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sName) const
 Get attribute applying nested AttrIf conditions. More...
 
template<class AttrVisitor >
void visitLayoutConfigNamedAttributes (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, int32_t nTotLayoutConfigs, AttrVisitor oAttrVisitor) const
 Visit layout config dependant attributes applying nested ExistIf conditions. More...
 
int32_t getEnumAttributeValue (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, const std::vector< char const *> &aValues) const
 Get enumeration attribute applying nested AttrIf conditions. More...
 
template<class AttrVisitor >
void visitLayoutConfigNamedEnumAttributes (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName, int32_t nTotLayoutConfigs, const std::vector< char const *> &aValues, AttrVisitor oAttrVisitor) const
 Visit layout config dependant attributes applying nested ExistIf conditions. More...
 
std::pair< bool, int32_t > parseTeamExists (ConditionalCtx &oCtx, const xmlpp::Element *p0Element) const
 Gets the team attribute. More...
 
std::tuple< bool, int32_t, int32_t > parseOwnerExists (ConditionalCtx &oCtx, const xmlpp::Element *p0Element) const
 Parse the owner of an element. More...
 
std::pair< int32_t, int32_t > parseOwner (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, OwnerType eRequireOwnerType) const
 The owner of an element (for a required owner type). More...
 
std::pair< int32_t, int32_t > parseOwner (ConditionalCtx &oCtx, const xmlpp::Element *p0Element) const
 The owner of an element. More...
 
std::pair< bool, OwnerTypeparseOwnerType (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttrName) const
 The owner type. More...
 
std::pair< bool, IntSetparseIntSetAttributes (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sSingleAttr, const std::string &sFromAttr, const std::string &sToAttr, const std::string &sMultiAttr, const std::string &sSeparatorAttr, bool bMin, int32_t nMin, bool bMax, int32_t nMax) const
 Parse int set attribute(s). More...
 
template<typename T >
bool parseAttributeFromTo (ConditionalCtx &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) const
 Parse single or from-to pair attribute. More...
 

Static Public Attributes

static const std::string s_sConditionalExistIfNode
 
static const std::string s_sConditionalPassthroughIfNode
 
static const std::string s_sConditionalAttrIfNode
 
static const std::string s_sConditionalAttrIfUndefAttr
 
static const std::string s_sConditionalAttrIfUndefAttrSeparator
 
static const std::string s_sConditionalOwnerTeamAttr
 
static const std::string s_sConditionalOwnerMateAttr
 
static const std::string s_sConditionalOwnerPlayerAttr
 

Constructor & Destructor Documentation

◆ XmlConditionalParser()

stmg::XmlConditionalParser::XmlConditionalParser ( XmlVariantSetParser oXmlVariantSetParser)

Constructor.

Member Function Documentation

◆ checkAllChildElementsName()

template<class P >
void stmg::XmlConditionalParser::checkAllChildElementsName ( ConditionalCtx oCtx,
const xmlpp::Node *  p0Parent,
oP 
) const
inline

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). The ExistIf and AttrIf subelements are skipped. Ignored elements are skipped. If one predicate call returns false an invalid element exception is thrown.

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

◆ getAttributeValue()

std::pair<bool, std::string> stmg::XmlConditionalParser::getAttributeValue ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sName 
) const

Get attribute applying nested AttrIf conditions.

Parameters
oCtxThe context.
p0ElementThe element the attribute of which should be retrieved. Cannot be null.
sNameThe attribute name. Cannot be empty.
Returns
Whether the attribute is defined and its value.

◆ getEnumAttributeValue()

int32_t stmg::XmlConditionalParser::getEnumAttributeValue ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const std::vector< char const *> &  aValues 
) const

Get enumeration attribute applying nested AttrIf conditions.

Parameters
oCtxThe context.
p0ElementThe element the attribute of which should be retrieved. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.
aValuesThe valid enum strings.
Returns
The chosen enum as an index into aValues or -1 if the attribute is not defined.

◆ parseAttributeFromTo()

template<typename T >
bool stmg::XmlConditionalParser::parseAttributeFromTo ( ConditionalCtx 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 
) const
inline

Parse single or from-to pair attribute.

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, oMax 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.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sSingleAttrThe single value attribute. Cannot be empty.
sFromAttrThe from value attribute. Cannot be empty.
sToAttrThe to value attribute. Cannot be empty.
bMandatoryIf true and no attribute is defined throws exception.
bMinIf true any of the values is smaller than oMin throws an exception. If false it is as if std::numeric_limits<T>::lowest() was passed to oMin.
oMinThe minimum value. Only is considered if bMin is set.
bMaxIf true any of the values is bigger than oMax throws an exception. If false it is as if std::numeric_limits<T>::max() was passed to oMax.
oMaxThe maximum value. Only is considered if bMax is set.
oFromThe resulting 'from' value of the range. If single attribute is defined equals oTo.
oToThe resulting 'to' value of the range. If single attribute is defined equals oFrom.
Returns
Whether any of attributes is defined.

◆ parseIntSetAttributes()

std::pair<bool, IntSet> stmg::XmlConditionalParser::parseIntSetAttributes ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sSingleAttr,
const std::string &  sFromAttr,
const std::string &  sToAttr,
const std::string &  sMultiAttr,
const std::string &  sSeparatorAttr,
bool  bMin,
int32_t  nMin,
bool  bMax,
int32_t  nMax 
) const

Parse int set attribute(s).

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sSingleAttrThe single value attribute. Cannot be empty.
sFromAttrThe from value attribute. Cannot be empty.
sToAttrThe to value attribute. Cannot be empty.
sMultiAttrThe multi value attribute. Cannot be empty.
sSeparatorAttrThe separator within the multi value. Can be empty (default is used).
bMinWhether the value(s) have a minimum.
nMinThe minimum for each int value. Only applied if bMin is true.
bMaxWhether the value(s) have a maximum.
nMaxThe maximum for each int value. Only applied if bMax is true.
Returns
Whether the set is defined and the int set itself.

◆ parseOwner() [1/2]

std::pair<int32_t, int32_t> stmg::XmlConditionalParser::parseOwner ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
OwnerType  eRequireOwnerType 
) const

The owner of an element (for a required owner type).

If the owner doesn't exist this function throws.

If the required owner type is OwnerType::PLAYER but the player isn't defined either directly or by the context the function throws.

If the required owner type is OwnerType::TEAM but the team isn't defined either directly or by the context the function throws. Note that if the element belongs to a player the function succeeds and also sets the mate value.

If the required owner type is OwnerType::GAME the owner (whatever it is) is returned.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
eRequireOwnerTypeThe owner type.
Returns
The team and mate.

◆ parseOwner() [2/2]

std::pair<int32_t, int32_t> stmg::XmlConditionalParser::parseOwner ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element 
) const

The owner of an element.

Same as parseOwner(oCtx, p0Element, OwnerType::GAME).

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
Returns
The team and mate.

◆ parseOwnerExists()

std::tuple<bool, int32_t, int32_t> stmg::XmlConditionalParser::parseOwnerExists ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element 
) const

Parse the owner of an element.

If the owner is the game, returns (true, -1, -1). If the owner is a team, returns (true, nTeam, -1) or (false, nTeam, -1) if the team doesn't exist. If the owner is a player, returns (true, nTeam, nMate) or (false, nTeam, nMate) if the player doesn't exist.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
Returns
Whether the owner exists, the owning team and the owning mate (bExists, nTeam, nMate).

◆ parseOwnerType()

std::pair<bool, OwnerType> stmg::XmlConditionalParser::parseOwnerType ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName 
) const

The owner type.

Parameters
oCtxThe context.
p0ElementThe element. Cannot be null.
sAttrNameThe attribute name containing the type. If empty the default attribute name ("ownerType") is used.
Returns
Whether the attribute exists and the owner type value ("GAME", "TEAM" or "PLAYER").

◆ parseTeamExists()

std::pair<bool, int32_t> stmg::XmlConditionalParser::parseTeamExists ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element 
) const

Gets the team attribute.

If the team is not defined as attribute the context team is returned.

Parameters
oCtxThe context.
p0ElementThe element
Returns
Pair(Whether the team exists according to the preferences, the team).
Exceptions
Ifthe team cannot be determined.

◆ parseUniqueElement()

const xmlpp::Element* stmg::XmlConditionalParser::parseUniqueElement ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Parent,
const std::string &  sName,
bool  bMandatory 
) const

Parse at most one child element with given name.

Parameters
oCtxThe context.
p0ParentThe parent element. Cannot be null.
sNameThe name of the child element. Cannot be empty.
bMandatoryWhether the child element must be present.
Returns
The child element or null if not present.

◆ visitElementChildren()

template<class ChildVisitor >
void stmg::XmlConditionalParser::visitElementChildren ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
ChildVisitor  oChildVisitor 
) const
inline

Visit all children applying nested ExistIf conditions.

Ignored elements are skipped.

Parameters
oCtxThe context.
p0ElementThe element the children of which should be visited.
oChildVisitorThe visitor. Takes const xmlpp::Element* p0Element as parameter.

◆ visitLayoutConfigNamedAttributes()

template<class AttrVisitor >
void stmg::XmlConditionalParser::visitLayoutConfigNamedAttributes ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
int32_t  nTotLayoutConfigs,
AttrVisitor  oAttrVisitor 
) const
inline

Visit layout config dependant attributes applying nested ExistIf conditions.

Layout config attributes are named by appending a '_' and the layout config number (>= 0 and < g_nTotLayoutConfigs).

The first attribute to be tried is the one in sAttrName. After that sAttrName + '_0', sAttrName + '_1', and so on.

The function object must define void operator()(const std::string& sLCAttrName, const std::string& sValue, int32_t nLayoutConfig). Parameter nLayoutConfig can be -1 (which means attribute without '_N' is defined). Parameter sLCAttrName is sAttrName with possibly suffix '_N' (N is nLayoutConfig).

Parameters
oCtxThe context.
p0ElementThe element the attribute(s) of which should be visited.
sAttrNameThe base name of the attribute. Cannot be empty.
nTotLayoutConfigsThe number of layout configurations (suffixes).
oAttrVisitorThe visitor.

◆ visitLayoutConfigNamedEnumAttributes()

template<class AttrVisitor >
void stmg::XmlConditionalParser::visitLayoutConfigNamedEnumAttributes ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
int32_t  nTotLayoutConfigs,
const std::vector< char const *> &  aValues,
AttrVisitor  oAttrVisitor 
) const
inline

Visit layout config dependant attributes applying nested ExistIf conditions.

Layout config attributes are named by appending a '_' and the layout config number (>= 0 and < g_nTotLayoutConfigs).

The first attribute to be tried is the one in sAttrName. After that sAttrName + '_0', sAttrName + '_1', and so on.

The function object must define void operator()(const std::string& sLCAttrName, int32_t nEnum, int32_t nLayoutConfig). Parameter nLayoutConfig can be -1 (which means attribute without '_N' is defined). Parameter sLCAttrName is sAttrName with possibly suffix '_N' (N is nLayoutConfig). Parameter nEnum is the index into aValues.

Parameters
oCtxThe context.
p0ElementThe element the attribute(s) of which should be visited.
sAttrNameThe base name of the attribute. Cannot be empty.
nTotLayoutConfigsThe number of layout configurations (suffixes).
aValuesThe valid enum strings.
oAttrVisitorThe visitor.

◆ visitNamedElementChildren()

template<class ChildVisitor >
void stmg::XmlConditionalParser::visitNamedElementChildren ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sName,
ChildVisitor  oChildVisitor 
) const
inline

Visit children elements with a given name applying nested ExistIf conditions.

If sName is empty, ignored elements are skipped.

Parameters
oCtxThe context.
p0ElementThe element the children of which should be visited.
sNameThe name of the child elements. If empty all are visited.
oChildVisitorThe visitor. Takes const xmlpp::Element* p0Element as parameter.

Member Data Documentation

◆ s_sConditionalAttrIfNode

const std::string stmg::XmlConditionalParser::s_sConditionalAttrIfNode
static

◆ s_sConditionalAttrIfUndefAttr

const std::string stmg::XmlConditionalParser::s_sConditionalAttrIfUndefAttr
static

◆ s_sConditionalAttrIfUndefAttrSeparator

const std::string stmg::XmlConditionalParser::s_sConditionalAttrIfUndefAttrSeparator
static

◆ s_sConditionalExistIfNode

const std::string stmg::XmlConditionalParser::s_sConditionalExistIfNode
static

◆ s_sConditionalOwnerMateAttr

const std::string stmg::XmlConditionalParser::s_sConditionalOwnerMateAttr
static

◆ s_sConditionalOwnerPlayerAttr

const std::string stmg::XmlConditionalParser::s_sConditionalOwnerPlayerAttr
static

◆ s_sConditionalOwnerTeamAttr

const std::string stmg::XmlConditionalParser::s_sConditionalOwnerTeamAttr
static

◆ s_sConditionalPassthroughIfNode

const std::string stmg::XmlConditionalParser::s_sConditionalPassthroughIfNode
static