From aef1ca4c4b43c56962dff25b4c02e24ed7238936 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 19 Nov 2010 00:20:15 +0000 Subject: COMMON: Cleanup XMLParser code * Get rid of obsolete comment about external documentation (link was broken for at least one year) * Remove unnecessary Common:: prefix * Push #include stream.h from .h to .cpp svn-id: r54354 --- common/xmlparser.cpp | 27 ++++++++++++++++++++------ common/xmlparser.h | 53 +++++++++++++++++----------------------------------- 2 files changed, 38 insertions(+), 42 deletions(-) (limited to 'common') diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index ab56ba3751..4dd0e09f53 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -27,10 +27,25 @@ #include "common/util.h" #include "common/archive.h" #include "common/fs.h" +#include "common/stream.h" namespace Common { -bool XMLParser::loadFile(const Common::String &filename) { +XMLParser::~XMLParser() { + while (!_activeKey.empty()) + freeNode(_activeKey.pop()); + + delete _XMLkeys; + delete _stream; + + for (List::iterator i = _layoutList.begin(); + i != _layoutList.end(); ++i) + delete *i; + + _layoutList.clear(); +} + +bool XMLParser::loadFile(const String &filename) { _stream = SearchMan.createReadStreamForMember(filename); if (!_stream) return false; @@ -54,7 +69,7 @@ bool XMLParser::loadBuffer(const byte *buffer, uint32 size, DisposeAfterUse::Fla return true; } -bool XMLParser::loadStream(Common::SeekableReadStream *stream) { +bool XMLParser::loadStream(SeekableReadStream *stream) { _stream = stream; _fileName = "File Stream"; return true; @@ -158,10 +173,10 @@ bool XMLParser::parseActiveKey(bool closed) { if (layout->children.contains(key->name)) { key->layout = layout->children[key->name]; - Common::StringMap localMap = key->values; + StringMap localMap = key->values; int keyCount = localMap.size(); - for (Common::List::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) { + for (List::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) { if (i->required && !localMap.contains(i->name)) return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str()); else if (localMap.contains(i->name)) @@ -198,7 +213,7 @@ bool XMLParser::parseActiveKey(bool closed) { return true; } -bool XMLParser::parseKeyValue(Common::String keyName) { +bool XMLParser::parseKeyValue(String keyName) { assert(_activeKey.empty() == false); if (_activeKey.top()->values.contains(keyName)) @@ -238,7 +253,7 @@ bool XMLParser::parseIntegerKey(const char *key, int count, ...) { return result; } -bool XMLParser::parseIntegerKey(const Common::String &key, int count, ...) { +bool XMLParser::parseIntegerKey(const String &key, int count, ...) { bool result; va_list args; va_start(args, count); diff --git a/common/xmlparser.h b/common/xmlparser.h index c8cc349a6c..ec8f371681 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -27,7 +27,7 @@ #define XML_PARSER_H #include "common/scummsys.h" -#include "common/stream.h" +#include "common/types.h" #include "common/list.h" #include "common/hashmap.h" @@ -38,14 +38,7 @@ namespace Common { class FSNode; - -/* - XMLParser.cpp/h -- Generic XML Parser - ===================================== - - External documentation available at: - http://www.smartlikearoboc.com/scummvm_doc/xmlparser_doc.html -*/ +class SeekableReadStream; #define MAX_XML_DEPTH 8 @@ -103,19 +96,7 @@ public: */ XMLParser() : _XMLkeys(0), _stream(0) {} - virtual ~XMLParser() { - while (!_activeKey.empty()) - freeNode(_activeKey.pop()); - - delete _XMLkeys; - delete _stream; - - for (Common::List::iterator i = _layoutList.begin(); - i != _layoutList.end(); ++i) - delete *i; - - _layoutList.clear(); - } + virtual ~XMLParser(); /** Active state for the parser */ enum ParserState { @@ -133,16 +114,16 @@ public: struct XMLKeyLayout; struct ParserNode; - typedef Common::HashMap ChildMap; + typedef HashMap ChildMap; /** nested struct representing the layout of the XML file */ struct XMLKeyLayout { struct XMLKeyProperty { - Common::String name; + String name; bool required; }; - Common::List properties; + List properties; ChildMap children; virtual bool doCallback(XMLParser *parent, ParserNode *node) = 0; @@ -156,8 +137,8 @@ public: /** Struct representing a parsed node */ struct ParserNode { - Common::String name; - Common::StringMap values; + String name; + StringMap values; bool ignore; bool header; int depth; @@ -181,7 +162,7 @@ public: * * @param filename Name of the file to load. */ - bool loadFile(const Common::String &filename); + bool loadFile(const String &filename); bool loadFile(const FSNode &node); @@ -198,7 +179,7 @@ public: */ bool loadBuffer(const byte *buffer, uint32 size, DisposeAfterUse::Flag disposable = DisposeAfterUse::NO); - bool loadStream(Common::SeekableReadStream *stream); + bool loadStream(SeekableReadStream *stream); void close(); @@ -283,7 +264,7 @@ protected: /** * Parses the value of a given key. There's no reason to overload this. */ - bool parseKeyValue(Common::String keyName); + bool parseKeyValue(String keyName); /** * Called once a key has been parsed. It handles the closing/cleanup of the @@ -343,7 +324,7 @@ protected: * @returns True if the parsing succeeded. */ bool parseIntegerKey(const char *key, int count, ...); - bool parseIntegerKey(const Common::String &keyStr, int count, ...); + bool parseIntegerKey(const String &keyStr, int count, ...); bool vparseIntegerKey(const char *key, int count, va_list args); bool parseXMLHeader(ParserNode *node); @@ -355,19 +336,19 @@ protected: */ virtual void cleanup() {} - Common::List _layoutList; + List _layoutList; private: char _char; SeekableReadStream *_stream; - Common::String _fileName; + String _fileName; ParserState _state; /** Internal state of the parser */ - Common::String _error; /** Current error message */ - Common::String _token; /** Current text token */ + String _error; /** Current error message */ + String _token; /** Current text token */ - Common::Stack _activeKey; /** Node stack of the parsed keys */ + Stack _activeKey; /** Node stack of the parsed keys */ }; } // End of namespace Common -- cgit v1.2.3