ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

The base XMLParser class implements generic functionality for parsing XML-like files. More...

#include <xmlparser.h>

Inheritance diagram for Common::XMLParser:
Collaboration diagram for Common::XMLParser:

List of all members.

Classes

struct  ParserNode
 Struct representing a parsed node. More...
struct  XMLKeyLayout
 nested struct representing the layout of the XML file More...

Public Types

enum  ParserState {
  kParserNeedHeader, kParserNeedKey, kParserNeedKeyName, kParserNeedPropertyName,
  kParserNeedPropertyOperator, kParserNeedPropertyValue, kParserError
}
 

Active state for the parser.

More...
typedef HashMap< String,
XMLParser::XMLKeyLayout
*, IgnoreCase_Hash,
IgnoreCase_EqualTo
ChildMap

Public Member Functions

 XMLParser ()
 Parser constructor.
virtual ~XMLParser ()
ParserNodeallocNode ()
void freeNode (ParserNode *node)
bool loadFile (const String &filename)
 Loads a file into the parser.
bool loadFile (const FSNode &node)
bool loadBuffer (const byte *buffer, uint32 size, DisposeAfterUse::Flag disposable=DisposeAfterUse::NO)
 Loads a memory buffer into the parser.
bool loadStream (SeekableReadStream *stream)
void close ()
bool parse ()
 The actual parsing function.
ParserNodegetActiveNode ()
 Returns the active node being parsed (the one on top of the node stack).
ParserNodegetParentNode (ParserNode *child)
 Returns the parent of a given node in the stack.

Public Attributes

XMLKeyLayout_XMLkeys
ObjectPool< ParserNode,
MAX_XML_DEPTH > 
_nodePool

Protected Member Functions

virtual void buildLayout ()=0
 The buildLayout function builds the layout for the parser to use based on a series of helper macros.
virtual bool keyCallback (ParserNode *node)=0
 The keycallback function is automatically overloaded on custom parsers when using the CUSTOM_XML_PARSER() macro.
virtual bool closedKeyCallback (ParserNode *node)
 The closed key callback function MAY be overloaded by inheriting classes to implement parser-specific functions.
bool closeKey ()
 Called when a node is closed.
bool parseKeyValue (String keyName)
 Parses the value of a given key.
bool parseActiveKey (bool closed)
 Called once a key has been parsed.
bool parserError (const String &errStr)
 Prints an error message when parsing fails and stops the parser.
bool skipSpaces ()
 Skips spaces/whitelines etc.
bool skipComments ()
 Skips comment blocks and comment lines.
virtual bool isValidNameChar (char c)
 Check if a given character can be part of a KEY or VALUE name.
bool parseToken ()
 Parses a the first textual token found.
bool parseIntegerKey (const char *key, int count,...)
 Parses the values inside an integer key.
bool parseIntegerKey (const String &keyStr, int count,...)
bool vparseIntegerKey (const char *key, int count, va_list args)
bool parseXMLHeader (ParserNode *node)
virtual void cleanup ()
 Overload if your parser needs to support parsing the same file several times, so you can clean up the internal state of the parser before each parse.

Protected Attributes

List< XMLKeyLayout * > _layoutList

Private Attributes

char _char
SeekableReadStream_stream
String _fileName
ParserState _state
String _error
 Internal state of the parser.
String _token
 Current error message.
Stack< ParserNode * > _activeKey
 Current text token.

Detailed Description

The base XMLParser class implements generic functionality for parsing XML-like files.

In order to use it, it must be inherited with a child class that implements the XMLParser::keyCallback() function.

See also:
XMLParser::keyCallback()

Definition at line 90 of file xmlparser.h.


Member Typedef Documentation


Member Enumeration Documentation

Active state for the parser.

Enumerator:
kParserNeedHeader 
kParserNeedKey 
kParserNeedKeyName 
kParserNeedPropertyName 
kParserNeedPropertyOperator 
kParserNeedPropertyValue 
kParserError 

Definition at line 100 of file xmlparser.h.


Constructor & Destructor Documentation

Common::XMLParser::XMLParser (  )  [inline]

Parser constructor.

Definition at line 95 of file xmlparser.h.

Common::XMLParser::~XMLParser (  )  [virtual]

Definition at line 31 of file xmlparser.cpp.


Member Function Documentation

ParserNode* Common::XMLParser::allocNode (  )  [inline]

Definition at line 148 of file xmlparser.h.

virtual void Common::XMLParser::buildLayout (  )  [protected, pure virtual]

The buildLayout function builds the layout for the parser to use based on a series of helper macros.

This function is automatically generated by the CUSTOM_XML_PARSER() macro on custom parsers.

See the documentation regarding XML layouts.

virtual void Common::XMLParser::cleanup (  )  [inline, protected, virtual]

Overload if your parser needs to support parsing the same file several times, so you can clean up the internal state of the parser before each parse.

Reimplemented in GUI::ThemeParser.

Definition at line 335 of file xmlparser.h.

void Common::XMLParser::close (  ) 

Definition at line 75 of file xmlparser.cpp.

virtual bool Common::XMLParser::closedKeyCallback ( ParserNode node  )  [inline, protected, virtual]

The closed key callback function MAY be overloaded by inheriting classes to implement parser-specific functions.

The closedKeyCallback is issued once a key has been finished parsing, to let the parser verify that all the required subkeys, etc, were included.

Unlike the keyCallbacks(), there's just a closedKeyCallback() for all keys. Use "node->name" to distinguish between each key type.

Returns true if the key was properly closed, false otherwise. By default, all keys are properly closed.

Reimplemented in GUI::ThemeParser.

Definition at line 252 of file xmlparser.h.

bool Common::XMLParser::closeKey (  )  [protected]

Called when a node is closed.

Manages its cleanup and calls the closing callback function if needed.

Definition at line 284 of file xmlparser.cpp.

void Common::XMLParser::freeNode ( ParserNode node  )  [inline]

Definition at line 152 of file xmlparser.h.

ParserNode* Common::XMLParser::getActiveNode (  )  [inline]

Returns the active node being parsed (the one on top of the node stack).

Definition at line 194 of file xmlparser.h.

ParserNode* Common::XMLParser::getParentNode ( ParserNode child  )  [inline]

Returns the parent of a given node in the stack.

Definition at line 204 of file xmlparser.h.

virtual bool Common::XMLParser::isValidNameChar ( char  c  )  [inline, protected, virtual]

Check if a given character can be part of a KEY or VALUE name.

Overload this if you want to support keys with strange characters in their name.

Definition at line 297 of file xmlparser.h.

virtual bool Common::XMLParser::keyCallback ( ParserNode node  )  [protected, pure virtual]

The keycallback function is automatically overloaded on custom parsers when using the CUSTOM_XML_PARSER() macro.

Its job is to call the corresponding Callback function for the given node. A function for each key type must be declared separately. See the custom parser creation instructions.

When parsing a key in such function, one may chose to skip it, e.g. because it's not needed on the current configuration. In order to ignore a key, you must set the "ignore" field of its KeyNode struct to "true": The key and all its children will then be automatically ignored by the parser.

The callback function must return true if the key was properly handled (this includes the case when the key is being ignored). False otherwise. The return of keyCallback() is the same as the callback function's. See the sample implementation in GUI::ThemeParser.

bool Common::XMLParser::loadBuffer ( const byte buffer,
uint32  size,
DisposeAfterUse::Flag  disposable = DisposeAfterUse::NO 
)

Loads a memory buffer into the parser.

Used for loading the default theme fallback directly from memory if no themes can be found.

Parameters:
buffer Pointer to the buffer.
size Size of the buffer
disposable Sets if the XMLParser owns the buffer, i.e. if it can be freed safely after it's no longer needed by the parser.

Definition at line 63 of file xmlparser.cpp.

bool Common::XMLParser::loadFile ( const FSNode node  ) 

Definition at line 54 of file xmlparser.cpp.

bool Common::XMLParser::loadFile ( const String filename  ) 

Loads a file into the parser.

Used for the loading of Theme Description files straight from the filesystem.

Parameters:
filename Name of the file to load.

Definition at line 45 of file xmlparser.cpp.

bool Common::XMLParser::loadStream ( SeekableReadStream stream  ) 

Definition at line 69 of file xmlparser.cpp.

bool Common::XMLParser::parse (  ) 

The actual parsing function.

Parses the loaded data stream, returns true if successful.

Definition at line 301 of file xmlparser.cpp.

bool Common::XMLParser::parseActiveKey ( bool  closed  )  [protected]

Called once a key has been parsed.

It handles the closing/cleanup of the node stack and calls the keyCallback.

Definition at line 156 of file xmlparser.cpp.

bool Common::XMLParser::parseIntegerKey ( const String keyStr,
int  count,
  ... 
) [protected]

Definition at line 252 of file xmlparser.cpp.

bool Common::XMLParser::parseIntegerKey ( const char *  key,
int  count,
  ... 
) [protected]

Parses the values inside an integer key.

The count parameter specifies the number of values inside the key, which are expected to be separated with commas.

Sample usage: parseIntegerKey("255, 255, 255", 3, &red, &green, &blue); [will parse each field into its own integer]

parseIntegerKey("1234", 1, &number); [will parse the single number into the variable]

Parameters:
key String containing the integers to be parsed.
count Number of comma-separated ints in the string.
... Integer variables to store the parsed ints, passed by reference.
Returns:
True if the parsing succeeded.

Definition at line 243 of file xmlparser.cpp.

bool Common::XMLParser::parseKeyValue ( String  keyName  )  [protected]

Parses the value of a given key.

There's no reason to overload this.

Definition at line 212 of file xmlparser.cpp.

bool Common::XMLParser::parserError ( const String errStr  )  [protected]

Prints an error message when parsing fails and stops the parser.

Parser error always returns "false" so we can pass the return value directly and break down the parsing.

Definition at line 80 of file xmlparser.cpp.

bool Common::XMLParser::parseToken (  )  [protected]

Parses a the first textual token found.

Definition at line 511 of file xmlparser.cpp.

bool Common::XMLParser::parseXMLHeader ( ParserNode node  )  [protected]

Definition at line 141 of file xmlparser.cpp.

bool Common::XMLParser::skipComments (  )  [protected]

Skips comment blocks and comment lines.

Returns:
true if any comments were skipped.

Definition at line 475 of file xmlparser.cpp.

bool Common::XMLParser::skipSpaces (  )  [protected]

Skips spaces/whitelines etc.

Returns:
true if any spaces were skipped.

Definition at line 465 of file xmlparser.cpp.

bool Common::XMLParser::vparseIntegerKey ( const char *  key,
int  count,
va_list  args 
) [protected]

Definition at line 261 of file xmlparser.cpp.


Member Data Documentation

Current text token.

Definition at line 349 of file xmlparser.h.

char Common::XMLParser::_char [private]

Definition at line 340 of file xmlparser.h.

Internal state of the parser.

Definition at line 346 of file xmlparser.h.

Definition at line 342 of file xmlparser.h.

Definition at line 337 of file xmlparser.h.

Definition at line 146 of file xmlparser.h.

Definition at line 344 of file xmlparser.h.

Definition at line 341 of file xmlparser.h.

Current error message.

Definition at line 347 of file xmlparser.h.


The documentation for this class was generated from the following files:


Generated on Sat Nov 16 2019 05:02:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge