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

Public Member Functions

 GameCtx (const shared_ptr< AppPreferences > &refAppPreferences, File oGameFile, Game &oGame, const GameConstraints &oGameConstraints)
 
Gamegame ()
 
NamedObjIndex< Block > & getNamedBlocks ()
 
Levellevel ()
 
const GameConstraintsgetGameConstraints () const
 
int32_t getContextTeam () const override
 Returns the context team. More...
 
std::pair< int32_t, OwnerTypegetVariableIdAndOwnerTypeFromContext (const std::string &sName, int32_t nTeam, int32_t nMate) const
 Returns the variable id and owner type from the team and mate context. More...
 
- Public Member Functions inherited from stmg::ConditionalCtx
 ConditionalCtx (const shared_ptr< AppPreferences > &refAppPreferences, Named &oNamed)
 
 ConditionalCtx (const shared_ptr< AppConfig > &refAppConfig, Named &oNamed)
 
virtual int32_t getContextMate () const
 The context mate. More...
 
void addChecker (const xmlpp::Element *p0Element) override
 Adds a checker for the element. More...
 
void removeChecker (const xmlpp::Element *p0Element, bool bCheckChildElements, bool bCheckAttrs) override
 Removes a checker for the element. More...
 
- Public Member Functions inherited from stmg::ParserCtx
 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...
 
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...
 
std::runtime_error error (const std::string &sErr)
 Creates an exception for the current context. More...
 
void dump () const
 

Protected Member Functions

std::string err (const std::string &sErr) override
 Builds complete error string from context. More...
 
- Protected Member Functions inherited from stmg::ParserCtx
std::vector< Checker >::iterator getChecker (const xmlpp::Element *p0Element)
 

Additional Inherited Members

- Static Public Member Functions inherited from stmg::ParserCtx
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 Attributes inherited from stmg::ParserCtx
const shared_ptr< AppConfigm_refAppConfig
 
shared_ptr< AppPreferencesm_refAppPreferences
 
Namedm_oNamed
 
std::vector< std::string > m_oStack
 
std::vector< Checkerm_aCheckers
 

Constructor & Destructor Documentation

◆ GameCtx()

stmg::GameCtx::GameCtx ( const shared_ptr< AppPreferences > &  refAppPreferences,
File  oGameFile,
Game oGame,
const GameConstraints oGameConstraints 
)

Member Function Documentation

◆ err()

std::string stmg::GameCtx::err ( const std::string &  s)
overrideprotectedvirtual

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 from stmg::ParserCtx.

◆ game()

Game& stmg::GameCtx::game ( )
inline

◆ getContextTeam()

int32_t stmg::GameCtx::getContextTeam ( ) const
overridevirtual

Returns the context team.

In "one team per level" games the level is returned. In "all teams in one level" games 0 is returned if only one team is playing, -1 otherwise.

Returns
The pref team or -1 if undefined.

Reimplemented from stmg::ConditionalCtx.

◆ getGameConstraints()

const GameConstraints& stmg::GameCtx::getGameConstraints ( ) const
inline

◆ getNamedBlocks()

NamedObjIndex<Block>& stmg::GameCtx::getNamedBlocks ( )
inline

◆ getVariableIdAndOwnerTypeFromContext()

std::pair<int32_t, OwnerType> stmg::GameCtx::getVariableIdAndOwnerTypeFromContext ( const std::string &  sName,
int32_t  nTeam,
int32_t  nMate 
) const

Returns the variable id and owner type from the team and mate context.

Example: if a team variable named "Points" exists and the parameter nTeam is -1, false is returned because can't determine what team it belongs to.

Parameters
sNameThe variable name. Cannot be empty.
nTeamThe context team. Must be >= 0 (and exist) or -1 if not defined.
nMateThe context mate. Must be >= 0 (and exist) or -1 if not defined. Must be -1 if nTeam is -1.
Returns
If it exists and its context is defined, the variable's id and the owner type, -1 and undefined otherwise.

◆ level()

Level& stmg::GameCtx::level ( )