[Scummvm-cvs-logs] SF.net SVN: scummvm:[54354] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Nov 19 01:20:15 CET 2010


Revision: 54354
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54354&view=rev
Author:   fingolfin
Date:     2010-11-19 00:20:15 +0000 (Fri, 19 Nov 2010)

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/common/xmlparser.cpp
    scummvm/trunk/common/xmlparser.h

Modified: scummvm/trunk/common/xmlparser.cpp
===================================================================
--- scummvm/trunk/common/xmlparser.cpp	2010-11-19 00:10:09 UTC (rev 54353)
+++ scummvm/trunk/common/xmlparser.cpp	2010-11-19 00:20:15 UTC (rev 54354)
@@ -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<XMLKeyLayout*>::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 @@
 	return true;
 }
 
-bool XMLParser::loadStream(Common::SeekableReadStream *stream) {
+bool XMLParser::loadStream(SeekableReadStream *stream) {
 	_stream = stream;
 	_fileName = "File Stream";
 	return true;
@@ -158,10 +173,10 @@
 	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<XMLKeyLayout::XMLKeyProperty>::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) {
+		for (List<XMLKeyLayout::XMLKeyProperty>::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 @@
 	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 @@
 	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);

Modified: scummvm/trunk/common/xmlparser.h
===================================================================
--- scummvm/trunk/common/xmlparser.h	2010-11-19 00:10:09 UTC (rev 54353)
+++ scummvm/trunk/common/xmlparser.h	2010-11-19 00:20:15 UTC (rev 54354)
@@ -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,15 +38,8 @@
 namespace Common {
 
 class FSNode;
+class SeekableReadStream;
 
-/*
-	XMLParser.cpp/h -- Generic XML Parser
-	=====================================
-
-	External documentation available at:
-		http://www.smartlikearoboc.com/scummvm_doc/xmlparser_doc.html
-*/
-
 #define MAX_XML_DEPTH 8
 
 #define XML_KEY(keyName) {\
@@ -103,20 +96,8 @@
 	 */
 	XMLParser() : _XMLkeys(0), _stream(0) {}
 
-	virtual ~XMLParser() {
-		while (!_activeKey.empty())
-			freeNode(_activeKey.pop());
+	virtual ~XMLParser();
 
-		delete _XMLkeys;
-		delete _stream;
-
-		for (Common::List<XMLKeyLayout*>::iterator i = _layoutList.begin();
-			i != _layoutList.end(); ++i)
-			delete *i;
-
-		_layoutList.clear();
-	}
-
 	/** Active state for the parser */
 	enum ParserState {
 		kParserNeedHeader,
@@ -133,16 +114,16 @@
 	struct XMLKeyLayout;
 	struct ParserNode;
 
-	typedef Common::HashMap<Common::String, XMLParser::XMLKeyLayout*, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ChildMap;
+	typedef HashMap<String, XMLParser::XMLKeyLayout*, IgnoreCase_Hash, IgnoreCase_EqualTo> ChildMap;
 
 	/** nested struct representing the layout of the XML file */
 	struct XMLKeyLayout {
 		struct XMLKeyProperty {
-			Common::String name;
+			String name;
 			bool required;
 		};
 
-		Common::List<XMLKeyProperty> properties;
+		List<XMLKeyProperty> properties;
 		ChildMap children;
 
 		virtual bool doCallback(XMLParser *parent, ParserNode *node) = 0;
@@ -156,8 +137,8 @@
 
 	/** 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 @@
 	 *
 	 * @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 @@
 	 */
 	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 @@
 	/**
 	 * 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 @@
 	 * @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 @@
 	 */
 	virtual void cleanup() {}
 
-	Common::List<XMLKeyLayout*> _layoutList;
+	List<XMLKeyLayout*> _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<ParserNode*> _activeKey; /** Node stack of the parsed keys */
+	Stack<ParserNode*> _activeKey; /** Node stack of the parsed keys */
 };
 
 } // End of namespace Common


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list