stmm-games-doc  0.32.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
stmg::ParserCtx Class Reference
Inheritance diagram for stmg::ParserCtx:
Inheritance graph
[legend]

Classes

struct  Checker
 

Public Member Functions

 ParserCtx (const shared_ptr< AppConfig > &refAppConfig, Named &oNamed)
 Constructor. More...
 
 ParserCtx (const shared_ptr< AppPreferences > &refAppPreferences, Named &oNamed)
 Constructor. More...
 
virtual ~ParserCtx ()
 
const shared_ptr< AppConfig > & appConfig ()
 The app config. More...
 
const shared_ptr< AppPreferences > & appPreferences ()
 The app preferences. More...
 
Namednamed ()
 The named assets. More...
 
void pushCtx (const std::string &sStr)
 Push a context. More...
 
void popCtx ()
 Pop a context. More...
 
virtual void addChecker (const xmlpp::Element *p0Element)
 Adds a checker for the element. More...
 
void addValidChildElementName (const xmlpp::Element *p0Element, const std::string &sChildElementName)
 Declares a child element name as valid. More...
 
void addValidChildElementNames (const xmlpp::Element *p0Element, const std::string &sChildElementName)
 Declares a child element name as valid. More...
 
template<typename ... Names>
void addValidChildElementNames (const xmlpp::Element *p0Element, const std::string &sChildElementName, const Names &... oNames)
 Declares multiple child element names as valid. More...
 
void addValidAttrName (const xmlpp::Element *p0Element, const std::string &sAttrName)
 Declares an attribute name as valid. More...
 
void addValidAttrNames (const xmlpp::Element *p0Element, const std::string &sAttrName)
 Declares an attribute name as valid. More...
 
template<typename ... Names>
void addValidAttrNames (const xmlpp::Element *p0Element, const std::string &sAttrName, const Names &... oNames)
 Declares attribute names as valid. More...
 
void removeChecker (const xmlpp::Element *p0Element, bool bCheck)
 Removes a checker for the element. More...
 
virtual void removeChecker (const xmlpp::Element *p0Element, bool bCheckChildElements, bool bCheckAttrs)
 Removes a checker for the element. More...
 
std::runtime_error error (const std::string &sErr)
 Creates an exception for the current context. More...
 
void dump () const
 

Static Public Member Functions

static int32_t getLine (const xmlpp::Element *p0Element, const std::string &sAttr)
 The line number within a document of an element or attribute. More...
 

Protected Member Functions

virtual std::string err (const std::string &s)
 Builds complete error string from context. More...
 
std::vector< Checker >::iterator getChecker (const xmlpp::Element *p0Element)
 

Protected Attributes

const shared_ptr< AppConfigm_refAppConfig
 
shared_ptr< AppPreferencesm_refAppPreferences
 
Namedm_oNamed
 
std::vector< std::string > m_oStack
 
std::vector< Checkerm_aCheckers
 

Constructor & Destructor Documentation

◆ ParserCtx() [1/2]

stmg::ParserCtx::ParserCtx ( const shared_ptr< AppConfig > &  refAppConfig,
Named oNamed 
)
inline

Constructor.

Used when parsing theme.

Parameters
refAppConfigThe app config. Cannot be null.
oNamedThe named.

◆ ParserCtx() [2/2]

stmg::ParserCtx::ParserCtx ( const shared_ptr< AppPreferences > &  refAppPreferences,
Named oNamed 
)
inline

Constructor.

Used when parsing game.

Parameters
refAppPreferencesThe app preferences. Cannot be null.
oNamedThe named.

◆ ~ParserCtx()

virtual stmg::ParserCtx::~ParserCtx ( )
virtual

Member Function Documentation

◆ addChecker()

virtual void stmg::ParserCtx::addChecker ( const xmlpp::Element *  p0Element)
virtual

Adds a checker for the element.

A checker is used to make sure all attributes and child elements of an element are expected.

If an element already has a checker a reference count is increased.

The check happens (if requested) in the corresponding removeChecker() function.

Parameters
p0ElementThe element. Cannot be null.

Reimplemented in stmg::ConditionalCtx.

◆ addValidAttrName()

void stmg::ParserCtx::addValidAttrName ( const xmlpp::Element *  p0Element,
const std::string &  sAttrName 
)

Declares an attribute name as valid.

Parameters
p0ElementThe element. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.

◆ addValidAttrNames() [1/2]

void stmg::ParserCtx::addValidAttrNames ( const xmlpp::Element *  p0Element,
const std::string &  sAttrName 
)
inline

Declares an attribute name as valid.

Parameters
p0ElementThe element. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.

◆ addValidAttrNames() [2/2]

template<typename ... Names>
void stmg::ParserCtx::addValidAttrNames ( const xmlpp::Element *  p0Element,
const std::string &  sAttrName,
const Names &...  oNames 
)
inline

Declares attribute names as valid.

Parameters
p0ElementThe element. Cannot be null.
sAttrNameThe attribute name. Cannot be empty.
oNamesFurther attribute names.

◆ addValidChildElementName()

void stmg::ParserCtx::addValidChildElementName ( const xmlpp::Element *  p0Element,
const std::string &  sChildElementName 
)

Declares a child element name as valid.

Parameters
p0ElementThe element. Cannot be null.
sChildElementNameThe child element name. Cannot be empty.

◆ addValidChildElementNames() [1/2]

void stmg::ParserCtx::addValidChildElementNames ( const xmlpp::Element *  p0Element,
const std::string &  sChildElementName 
)
inline

Declares a child element name as valid.

Parameters
p0ElementThe element. Cannot be null.
sChildElementNameThe child element name. Cannot be empty.

◆ addValidChildElementNames() [2/2]

template<typename ... Names>
void stmg::ParserCtx::addValidChildElementNames ( const xmlpp::Element *  p0Element,
const std::string &  sChildElementName,
const Names &...  oNames 
)
inline

Declares multiple child element names as valid.

Parameters
p0ElementThe element. Cannot be null.
sChildElementNameA child element name. Cannot be empty.
oNamesFurther child element names.

◆ appConfig()

const shared_ptr<AppConfig>& stmg::ParserCtx::appConfig ( )
inline

The app config.

Returns
The config. Is not null.

◆ appPreferences()

const shared_ptr<AppPreferences>& stmg::ParserCtx::appPreferences ( )
inline

The app preferences.

Not defined in a theme context.

Returns
The preferences or null if not relevant.

◆ dump()

void stmg::ParserCtx::dump ( ) const

◆ err()

virtual std::string stmg::ParserCtx::err ( const std::string &  s)
protectedvirtual

Builds complete error string from context.

The base implementation concatenates strings passed to pushCtx().

Parameters
sThe error without context.
Returns
The error string with context.

Reimplemented in stmg::GameInfoCtx, stmg::GameCtx, and stmg::ThemeCtx.

◆ error()

std::runtime_error stmg::ParserCtx::error ( const std::string &  sErr)

Creates an exception for the current context.

Parameters
sErrThe error string. Can be empty.
Returns
The exception.

◆ getChecker()

std::vector<Checker>::iterator stmg::ParserCtx::getChecker ( const xmlpp::Element *  p0Element)
protected

◆ getLine()

static int32_t stmg::ParserCtx::getLine ( const xmlpp::Element *  p0Element,
const std::string &  sAttr 
)
static

The line number within a document of an element or attribute.

Parameters
p0ElementThe element. Cannot be null.
sAttrThe attribute name. If empty or not found the element's line number is returned.
Returns
The line number or -1 if unknown.

◆ named()

Named& stmg::ParserCtx::named ( )
inline

The named assets.

Returns
The named of the game or theme being parsed.

◆ popCtx()

void stmg::ParserCtx::popCtx ( )
inline

Pop a context.

Each pushCtx() should have a corresponding popCtx().

◆ pushCtx()

void stmg::ParserCtx::pushCtx ( const std::string &  sStr)
inline

Push a context.

This string context can be used to give better error messages. It is used by ParserCtx::error().

Parameters
sStrThe string. Cannot be empty.

◆ removeChecker() [1/2]

void stmg::ParserCtx::removeChecker ( const xmlpp::Element *  p0Element,
bool  bCheck 
)
inline

Removes a checker for the element.

Parameters
p0ElementThe element. Cannot be null.
bCheckWhether to check both attributes child element names.

◆ removeChecker() [2/2]

virtual void stmg::ParserCtx::removeChecker ( const xmlpp::Element *  p0Element,
bool  bCheckChildElements,
bool  bCheckAttrs 
)
virtual

Removes a checker for the element.

This should always be paired with a addChecker() call.

If an element has multiple checkers, the check is only performed when the last checker is removed.

The bCheckChildElements parameter should be set to false if you are iterating over all child elements and checking their validity explicitely. Same for bCheckAttrs.

Parameters
p0ElementThe element. Cannot be null.
bCheckChildElementsWhether to check child element names.
bCheckAttrsWhether to check attributes.

Reimplemented in stmg::ConditionalCtx.

Member Data Documentation

◆ m_aCheckers

std::vector<Checker> stmg::ParserCtx::m_aCheckers
protected

◆ m_oNamed

Named& stmg::ParserCtx::m_oNamed
protected

◆ m_oStack

std::vector<std::string> stmg::ParserCtx::m_oStack
protected

◆ m_refAppConfig

const shared_ptr<AppConfig> stmg::ParserCtx::m_refAppConfig
protected

◆ m_refAppPreferences

shared_ptr<AppPreferences> stmg::ParserCtx::m_refAppPreferences
protected