netpanzer-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netPanzer-CVS] netpanzer/src Lib/Xml/XmlConfig.cpp Lib/Xml/Xml...


From: Hankin Chick
Subject: [netPanzer-CVS] netpanzer/src Lib/Xml/XmlConfig.cpp Lib/Xml/Xml...
Date: Sat, 22 Nov 2003 04:13:58 -0500

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Hankin Chick <address@hidden>   03/11/22 04:13:57

Modified files:
        src/Lib/Xml    : XmlConfig.cpp XmlConfig.hpp XmlStore.cpp 
                         XmlStore.hpp 
        src/NetPanzer/Interfaces: ConfigVariable.cpp ConfigVariable.hpp 

Log message:
        adds iXY support to gameconfig

Patches:
Index: netpanzer/src/Lib/Xml/XmlConfig.cpp
diff -u netpanzer/src/Lib/Xml/XmlConfig.cpp:1.3 
netpanzer/src/Lib/Xml/XmlConfig.cpp:1.4
--- netpanzer/src/Lib/Xml/XmlConfig.cpp:1.3     Tue Sep 23 11:38:26 2003
+++ netpanzer/src/Lib/Xml/XmlConfig.cpp Sat Nov 22 04:13:56 2003
@@ -107,6 +107,42 @@
 //-----------------------------------------------------------------
 /**
  * Read number from attribute.
+ * @return iXY
+ */
+iXY
+XmlConfig::readXY(const char *name) const
+{
+    xmlChar *strXml = xmlGetProp(m_node, (const xmlChar*)name);
+    if (strXml == 0) {
+        throw Exception("xml config: '%s->%s' is empty",
+            m_node->name, name);
+    }
+
+    LOGGER.debug("readXY '%s->%s=%s'",
+            m_node->name, name, strXml);
+
+    char *endptr,*endptr2;
+    long x = strtol((char *)strXml, &endptr, 0);
+    if(*endptr!=',') {
+        throw Exception("xml config: '%s->%s=%s' has no comma ",
+            m_node->name, name, strXml);
+    }
+    long y = strtol(endptr+1, &endptr2, 0);
+    bool ok = (strXml[0] != '\0' && endptr2[0] == '\0');
+
+    if (!ok) {
+        throw Exception("xml config: '%s->%s=%s' is not XY",
+            m_node->name, name, strXml);
+    }
+
+    xmlFree(strXml);
+    return iXY(x,y);
+}
+
+
+//-----------------------------------------------------------------
+/**
+ * Read number from attribute.
  * @return long
  * @return defaultValue default value
  */
Index: netpanzer/src/Lib/Xml/XmlConfig.hpp
diff -u netpanzer/src/Lib/Xml/XmlConfig.hpp:1.2 
netpanzer/src/Lib/Xml/XmlConfig.hpp:1.3
--- netpanzer/src/Lib/Xml/XmlConfig.hpp:1.2     Tue Sep 23 11:38:26 2003
+++ netpanzer/src/Lib/Xml/XmlConfig.hpp Sat Nov 22 04:13:57 2003
@@ -21,6 +21,7 @@
 
 #include <string>
 #include <libxml/tree.h>
+#include <iXY.hpp>
 
 /**
  * XML configuration from file.
@@ -40,6 +41,7 @@
         const XmlConfig getChild(const char *childName) const;
         long readInt(const char *name) const;
         long readInt(const char *name, long defaultValue) const;
+        iXY readXY(const char *name) const;
         std::string readString(const char *name,
                 const char *defaultValue = 0) const;
 };
Index: netpanzer/src/Lib/Xml/XmlStore.cpp
diff -u netpanzer/src/Lib/Xml/XmlStore.cpp:1.2 
netpanzer/src/Lib/Xml/XmlStore.cpp:1.3
--- netpanzer/src/Lib/Xml/XmlStore.cpp:1.2      Mon Sep 22 11:15:51 2003
+++ netpanzer/src/Lib/Xml/XmlStore.cpp  Sat Nov 22 04:13:57 2003
@@ -77,6 +77,21 @@
 }
 //-----------------------------------------------------------------
 /**
+ * Write number to new attribute.
+ * @param name attribute name
+ * @param value value
+ */
+void
+XmlStore::writeXY(const char *name, const iXY &value)
+{
+
+    std::ostringstream buffer;
+    buffer << value.x << "," << value.y;;
+    xmlSetProp(m_node, (const xmlChar*)name,
+            (const xmlChar*)(buffer.str().c_str()));
+}
+//-----------------------------------------------------------------
+/**
  * Write string to new attribute.
  * @param name attribute name
  * @param value value
Index: netpanzer/src/Lib/Xml/XmlStore.hpp
diff -u netpanzer/src/Lib/Xml/XmlStore.hpp:1.2 
netpanzer/src/Lib/Xml/XmlStore.hpp:1.3
--- netpanzer/src/Lib/Xml/XmlStore.hpp:1.2      Mon Sep 22 11:15:51 2003
+++ netpanzer/src/Lib/Xml/XmlStore.hpp  Sat Nov 22 04:13:57 2003
@@ -20,6 +20,7 @@
 
 #include <string>
 #include <libxml/tree.h>
+#include <iXY.hpp>
 
 /**
  * Save XML configuration to file.
@@ -37,6 +38,7 @@
 
         const XmlStore createChild(const char *childName);
         void writeInt(const char *name, long value);
+        void writeXY(const char *name, const iXY &value);
         void writeString(const char *name, const char *value);
         void save(const char *filename);
 };
Index: netpanzer/src/NetPanzer/Interfaces/ConfigVariable.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/ConfigVariable.cpp:1.2 
netpanzer/src/NetPanzer/Interfaces/ConfigVariable.cpp:1.3
--- netpanzer/src/NetPanzer/Interfaces/ConfigVariable.cpp:1.2   Thu Nov  6 
12:53:26 2003
+++ netpanzer/src/NetPanzer/Interfaces/ConfigVariable.cpp       Sat Nov 22 
04:13:57 2003
@@ -36,6 +36,21 @@
 }
 
 //---------------------------------------------------------------------------
+ConfigXY::ConfigXY(const std::string& newname, const iXY &newvalue)
+    : ConfigVariable(newname)
+{
+    *this = newvalue;
+}
+
+ConfigXY::~ConfigXY()
+{
+}
+const iXY& ConfigXY::operator = (const iXY& newvalue)
+{
+    value = newvalue;
+    return value;
+}
+//---------------------------------------------------------------------------
 
 ConfigBool::ConfigBool(const std::string& newname, bool newvalue)
     : ConfigVariable(newname), value(newvalue)
Index: netpanzer/src/NetPanzer/Interfaces/ConfigVariable.hpp
diff -u netpanzer/src/NetPanzer/Interfaces/ConfigVariable.hpp:1.3 
netpanzer/src/NetPanzer/Interfaces/ConfigVariable.hpp:1.4
--- netpanzer/src/NetPanzer/Interfaces/ConfigVariable.hpp:1.3   Thu Nov  6 
12:53:26 2003
+++ netpanzer/src/NetPanzer/Interfaces/ConfigVariable.hpp       Sat Nov 22 
04:13:57 2003
@@ -20,6 +20,7 @@
 
 #include <iostream>
 #include <string>
+#include <iXY.hpp>
 
 class ConfigVariable
 {
@@ -55,6 +56,21 @@
 private:
     int value;
     int min, max;
+};
+
+class ConfigXY : public ConfigVariable
+{
+public:
+    ConfigXY(const std::string& name, const iXY &value);
+    ~ConfigXY();
+
+    operator const iXY& () const
+    { return value; }
+
+    const iXY& operator = (const iXY& newvalue);
+    
+private:
+    iXY value;
 };
 
 class ConfigBool : public ConfigVariable




reply via email to

[Prev in Thread] Current Thread [Next in Thread]