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

Public Member Functions

virtual ~XmlEventParser ()=default
 
 XmlEventParser (const std::string &sEventName)
 Constructor. More...
 
const std::string & getEventName () const
 The event name. More...
 
virtual EventparseEvent (GameCtx &oCtx, const xmlpp::Element *p0Element)=0
 Parse and create an event instance. More...
 
virtual void recycleEvents (std::unique_ptr< Event > &refEvent)
 Recycle the event if it is of a type created by this instance. More...
 
virtual int32_t parseEventMsgName (ConditionalCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttr, const std::string &sMsgName)
 Returns event type's msg value from msg name. More...
 
virtual int32_t parseEventListenerGroupName (GameCtx &oCtx, const xmlpp::Element *p0Element, const std::string &sAttr, const std::string &sListenerGroupName)
 Returns event type listener group value from name. More...
 

Protected Member Functions

bool getBlock (GameCtx &oCtx, const std::string &sName, Block &oBlock)
 Return named block. More...
 
EventparseChildEvent (GameCtx &oCtx, const xmlpp::Element *p0Element)
 Parses an event and adds it to the level. More...
 
void parseEventBase (GameCtx &oCtx, const xmlpp::Element *p0Element, Event::Init &oInit)
 Parse event base. More...
 
EventintegrateAndAdd (GameCtx &oCtx, unique_ptr< Event > refEvent, const xmlpp::Element *p0Element)
 Integrate the event add to level. More...
 
int32_t parseEventAttrRepeat (GameCtx &oCtx, const xmlpp::Element *p0EventElement)
 Helper function for the 'repeat' attribute. More...
 
int32_t parseEventAttrStep (GameCtx &oCtx, const xmlpp::Element *p0EventElement)
 Helper function for the 'step' attribute. More...
 
int32_t parseEventAttrRandomProb (GameCtx &oCtx, const xmlpp::Element *p0EventElement)
 Helper function for the 'prob' attribute. More...
 
bool isReservedChildElementOfEvent (const std::string &sElementName) const
 Tells whether a child element name of Event is reserved. More...
 
XmlConditionalParsergetXmlConditionalParser ()
 Get the conditional parser. More...
 
XmlTraitsParsergetXmlTraitsParser ()
 Get the traits parser. More...
 

Constructor & Destructor Documentation

◆ ~XmlEventParser()

virtual stmg::XmlEventParser::~XmlEventParser ( )
virtualdefault

◆ XmlEventParser()

stmg::XmlEventParser::XmlEventParser ( const std::string &  sEventName)

Constructor.

Parameters
sEventNameThe event name. Cannot be empty.

Member Function Documentation

◆ getBlock()

bool stmg::XmlEventParser::getBlock ( GameCtx oCtx,
const std::string &  sName,
Block oBlock 
)
protected

Return named block.

Parameters
oCtxThe context.
sNameThe block name. Cannot be empty.
oBlockThe block structure to be filled.
Returns
Whether a block with the given name exists.

◆ getEventName()

const std::string& stmg::XmlEventParser::getEventName ( ) const

The event name.

Returns
The event name.

◆ getXmlConditionalParser()

XmlConditionalParser& stmg::XmlEventParser::getXmlConditionalParser ( )
protected

Get the conditional parser.

Cannot be called from the subclass constructor.

Returns
The parser.

◆ getXmlTraitsParser()

XmlTraitsParser& stmg::XmlEventParser::getXmlTraitsParser ( )
protected

Get the traits parser.

Cannot be called from the subclass constructor.

Returns
The parser.

◆ integrateAndAdd()

Event* stmg::XmlEventParser::integrateAndAdd ( GameCtx oCtx,
unique_ptr< Event refEvent,
const xmlpp::Element *  p0Element 
)
protected

Integrate the event add to level.

Performs the xml specific integration that links the event to others and to widgets and adds the instance to the level, which will own it.

Parameters
oCtxThe context.
refEventThe event. Cannot be null.
p0ElementThe event element. Cannot be null.
Returns
The added event. Is always refEvent.get().

◆ isReservedChildElementOfEvent()

bool stmg::XmlEventParser::isReservedChildElementOfEvent ( const std::string &  sElementName) const
protected

Tells whether a child element name of Event is reserved.

Use this when using getXmlConditionalParser().visitElementChildren().

Example: ListenerGroup or Filter.

Parameters
sElementNameThe element name in question. Cannot be empty.
Returns
Whether the element name is reserved.

◆ parseChildEvent()

Event* stmg::XmlEventParser::parseChildEvent ( GameCtx oCtx,
const xmlpp::Element *  p0Element 
)
protected

Parses an event and adds it to the level.

This method can be used by events that directly handle other events.

Parameters
oCtxThe context.
p0ElementThe event element. Cannot be null.
Returns
The event. Not null.

◆ parseEvent()

virtual Event* stmg::XmlEventParser::parseEvent ( GameCtx oCtx,
const xmlpp::Element *  p0Element 
)
pure virtual

◆ parseEventAttrRandomProb()

int32_t stmg::XmlEventParser::parseEventAttrRandomProb ( GameCtx oCtx,
const xmlpp::Element *  p0EventElement 
)
protected

Helper function for the 'prob' attribute.

Expects the value to be > 0. Default is 1.

Parameters
oCtxThe context.
p0EventElementThe event element. Cannot be null.
Returns
The prob value.
Exceptions
std::runtime_exception.

◆ parseEventAttrRepeat()

int32_t stmg::XmlEventParser::parseEventAttrRepeat ( GameCtx oCtx,
const xmlpp::Element *  p0EventElement 
)
protected

Helper function for the 'repeat' attribute.

Expects the value to be > 0 or -1 (infinite). Default is -1.

Parameters
oCtxThe context.
p0EventElementThe event element. Cannot be null.
Returns
The repeat value.
Exceptions
std::runtime_exception.

◆ parseEventAttrStep()

int32_t stmg::XmlEventParser::parseEventAttrStep ( GameCtx oCtx,
const xmlpp::Element *  p0EventElement 
)
protected

Helper function for the 'step' attribute.

Expects the value to be > 0. Default is 1.

Parameters
oCtxThe context.
p0EventElementThe event element. Cannot be null.
Returns
The step value.
Exceptions
std::runtime_exception.

◆ parseEventBase()

void stmg::XmlEventParser::parseEventBase ( GameCtx oCtx,
const xmlpp::Element *  p0Element,
Event::Init oInit 
)
protected

Parse event base.

This function should be called rather than filling the attributes by hand in the subclass parser.

Parameters
oCtxThe context.
p0ElementThe event element. Cannot be null.
oInitThe even initialization data to fill.

◆ parseEventListenerGroupName()

virtual int32_t stmg::XmlEventParser::parseEventListenerGroupName ( GameCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttr,
const std::string &  sListenerGroupName 
)
virtual

Returns event type listener group value from name.

Usually listener group the name is the same as defined in the event class as an enum without the 'LISTENER_GROUP_' prefix.

Since also the Event base class has at least the LISTENER_GROUP_FINISHED enum and therefore the name 'FINISHED' defined, subclasses of this function should call XmlEventParser::parseEventListenerGroupName() after checking their own enums.

Parameters
oCtxThe game context.
p0ElementThe element containing the the attribute. Cannot be null.
sAttrThe attribute name containing the listener group name. Cannot be empty.
sListenerGroupNameThe listener group name. Cannot be empty.
Returns
The listener group value.
Exceptions
Ifthe listener group name is unknown.

Reimplemented in stmg::XmlArrayEventParser, stmg::XmlStaticGridEventParser, stmg::XmlBackgroundEventParser, stmg::XmlAlarmsEventParser, stmg::XmlCumulCmpEventParser, stmg::XmlDelayedQueueEventParser, stmg::XmlRandomEventParser, stmg::XmlSoundEventParser, stmg::XmlTileAnimatorEventParser, stmg::XmlVariableEventParser, stmg::XmlSpeedEventParser, stmg::XmlScrollerEventParser, stmg::XmlSysEventParser, stmg::XmlFillerEventParser, and stmg::XmlSquarsorEventParser.

◆ parseEventMsgName()

virtual int32_t stmg::XmlEventParser::parseEventMsgName ( ConditionalCtx oCtx,
const xmlpp::Element *  p0Element,
const std::string &  sAttr,
const std::string &  sMsgName 
)
virtual

Returns event type's msg value from msg name.

Usually the msg name is the same as defined in the event class as an enum without the 'MESSAGE_' prefix.

Subclasses of this function should call XmlEventParser::parseEventMsgName() after checking their own enums. The function will throw an error.

Parameters
oCtxThe game context.
p0ElementThe element containing the the attribute. Cannot be null.
sAttrThe attribute name containing the message name. Cannot be empty.
sMsgNameThe message name. Cannot be empty.
Returns
The message value.
Exceptions
Ifthe msg name is unknown.

Reimplemented in stmg::XmlArrayEventParser, stmg::XmlStaticGridEventParser, stmg::XmlBackgroundEventParser, stmg::XmlPositionerEventParser, stmg::XmlAlarmsEventParser, stmg::XmlCumulCmpEventParser, stmg::XmlDelayedQueueEventParser, stmg::XmlRandomEventParser, stmg::XmlShowTextEventParser, stmg::XmlSoundEventParser, stmg::XmlVariableEventParser, stmg::XmlScrollerEventParser, stmg::XmlFillerEventParser, and stmg::XmlSquarsorEventParser.

◆ recycleEvents()

virtual void stmg::XmlEventParser::recycleEvents ( std::unique_ptr< Event > &  refEvent)
virtual

Recycle the event if it is of a type created by this instance.

The default implementation is empty.

Parameters
refEventThe event. Cannot be null. If recycled is null after function call.