|
From: <cn...@us...> - 2009-06-28 22:00:29
|
Revision: 388
http://hgengine.svn.sourceforge.net/hgengine/?rev=388&view=rev
Author: cnlohr
Date: 2009-06-28 22:00:27 +0000 (Sun, 28 Jun 2009)
Log Message:
-----------
update the XML Parser to be able to handle .GetValue(), thus reaping all of the rewards of the named
resource class.
Modified Paths:
--------------
Mercury2/src/XMLParser.cpp
Mercury2/src/XMLParser.h
Modified: Mercury2/src/XMLParser.cpp
===================================================================
--- Mercury2/src/XMLParser.cpp 2009-06-28 21:59:32 UTC (rev 387)
+++ Mercury2/src/XMLParser.cpp 2009-06-28 22:00:27 UTC (rev 388)
@@ -1,13 +1,14 @@
#include <XMLParser.h>
#include <MercuryFile.h>
+#include <MercuryVector.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
-#if defined(WIN32)
-# if defined(_MSC_VER)
-# pragma comment(lib, "libxml2.lib")
-# endif
+#if defined(WIN32)
+# if defined(_MSC_VER)
+# pragma comment(lib, "libxml2.lib")
+# endif
#endif
XMLNode::XMLNode(xmlNode* node, xmlDoc* doc)
@@ -184,6 +185,33 @@
return *this;
}
+bool XMLNode::GetValue( const MString & sDataPointer, MString & sReturn )
+{
+ MVector< MString > out;
+ SplitStrings( sDataPointer, out, ".", " ", 1, 1 );
+ //Out now contains the input in a parsed form;
+ //a.b.c is now:
+ //out[0] = "a"; out[1] = "b"; out[2] = "c";
+ XMLNode & rthis = *this;
+ for( unsigned i = 0; i < out.size() - 1; i++ )
+ {
+ while( rthis.Name() != out[i] && rthis.IsValid() )
+ rthis = rthis.NextNode();
+
+ if( !rthis.IsValid() )
+ return false;
+
+ if( i < out.size() - 2 )
+ rthis = rthis.Child();
+
+ if( !rthis.IsValid() )
+ return false;
+ }
+
+ sReturn = rthis.Attribute( out[out.size()-1] );
+ return true;
+}
+
XMLDocument::XMLDocument()
:m_doc(NULL)
{
Modified: Mercury2/src/XMLParser.h
===================================================================
--- Mercury2/src/XMLParser.h 2009-06-28 21:59:32 UTC (rev 387)
+++ Mercury2/src/XMLParser.h 2009-06-28 22:00:27 UTC (rev 388)
@@ -2,6 +2,7 @@
#define XMLPARSER_H
#include <MAutoPtr.h>
+#include <MercuryNamedResource.h>
struct _xmlNode;
typedef struct _xmlNode xmlNode;
@@ -14,7 +15,7 @@
private:
};
-class XMLNode
+class XMLNode : public MercuryNamedResource
{
public:
XMLNode(xmlNode* node = NULL, xmlDoc* doc = NULL);
@@ -35,6 +36,8 @@
XMLNode FindFallbackNode() const;
const XMLNode& operator=(const XMLNode& n);
+
+ virtual bool GetValue( const MString & sDataPointer, MString & sReturn );
private:
XMLNode RecursiveFindFallbackNode(const MString& path) const;
XMLNode FindParentWithName(const MString& name) const;
@@ -62,26 +65,35 @@
#endif
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * All rights reserved. *
- * *
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
- * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
- * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
- * * Neither the name of the Mercury developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
- * *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|