pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src xml_file_reader.cxx,1.1,1.2 xml_file_


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src xml_file_reader.cxx,1.1,1.2 xml_file_reader.hxx,1.1,1.2 xml_file_writer.cxx,1.2,1.3 xml_file_writer.hxx,1.2,1.3
Date: 18 Feb 2003 01:23:54 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv14392

Modified Files:
        xml_file_reader.cxx xml_file_reader.hxx xml_file_writer.cxx 
        xml_file_writer.hxx 
Log Message:
used XMLFileReader/Writer a bit, might hae introduced a few bugs


Index: xml_file_reader.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_file_reader.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xml_file_reader.cxx 20 Dec 2002 18:45:41 -0000      1.1
+++ xml_file_reader.cxx 18 Feb 2003 01:23:51 -0000      1.2
@@ -17,6 +17,8 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "res_descriptor.hxx"
+#include "color.hxx"
 #include "xml_file_reader.hxx"
 
 XMLFileReader::XMLFileReader(xmlDocPtr doc_, xmlNodePtr node)
@@ -41,18 +43,20 @@
         {
           return node;
         }
+
+      node = node->next;
     }
-  return 0;
+  return NULL;
 }
 
 bool
-XMLFileReader::read_int   (const char* name, int* value)
+XMLFileReader::read_desc  (const char* name, ResDescriptor& value)
 {
   xmlNodePtr node = find_node(name);
 
   if (node)
     {
-      *value = XMLhelper::parse_int(doc, node);
+      value = XMLhelper::parse_surface(doc, node);
       return true;
     }
 
@@ -60,13 +64,27 @@
 }
 
 bool
-XMLFileReader::read_float (const char* name, float* value)
+XMLFileReader::read_color (const char* name, Color& value)
 {
   xmlNodePtr node = find_node(name);
 
   if (node)
     {
-      *value = XMLhelper::parse_float(doc, node);
+      value = XMLhelper::parse_color(doc, node);
+      return true;
+    }
+
+  return false;  
+}
+
+bool
+XMLFileReader::read_int   (const char* name, int& value)
+{
+  xmlNodePtr node = find_node(name);
+
+  if (node)
+    {
+      value = XMLhelper::parse_int(doc, node);
       return true;
     }
 
@@ -74,13 +92,13 @@
 }
 
 bool
-XMLFileReader::read_bool  (const char* name, bool* value)
+XMLFileReader::read_float (const char* name, float& value)
 {
   xmlNodePtr node = find_node(name);
 
   if (node)
     {
-      *value = XMLhelper::parse_bool(doc, node);
+      value = XMLhelper::parse_float(doc, node);
       return true;
     }
 
@@ -88,13 +106,13 @@
 }
 
 bool
-XMLFileReader::read_string(const char* name, std::string* value)
+XMLFileReader::read_bool  (const char* name, bool& value)
 {
   xmlNodePtr node = find_node(name);
 
   if (node)
     {
-      *value = XMLhelper::parse_string(doc, node);
+      value = XMLhelper::parse_bool(doc, node);
       return true;
     }
 
@@ -102,13 +120,27 @@
 }
 
 bool
-XMLFileReader::read_vector(const char* name, Vector* value)
+XMLFileReader::read_string(const char* name, std::string& value)
 {
   xmlNodePtr node = find_node(name);
 
   if (node)
     {
-      *value = XMLhelper::parse_vector(doc, node);
+      value = XMLhelper::parse_string(doc, node);
+      return true;
+    }
+
+  return false;
+}
+
+bool
+XMLFileReader::read_vector(const char* name, Vector& value)
+{
+  xmlNodePtr node = find_node(name);
+
+  if (node)
+    {
+      value = XMLhelper::parse_vector(doc, node);
       return true;
     }
 

Index: xml_file_reader.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_file_reader.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- xml_file_reader.hxx 20 Dec 2002 18:45:41 -0000      1.1
+++ xml_file_reader.hxx 18 Feb 2003 01:23:51 -0000      1.2
@@ -36,13 +36,18 @@
 
   xmlNodePtr find_node(const char* name);
 public:
+  /** @param doc is a pointer to the xml document tree
+      @param node is a pointer to the node of the section to read, but
+      not a pointer to the first element of the section! */
   XMLFileReader(xmlDocPtr doc, xmlNodePtr node);
   
-  bool read_int   (const char* name, int*);
-  bool read_float (const char* name, float*);
-  bool read_bool  (const char* name, bool*);
-  bool read_string(const char* name, std::string*);
-  bool read_vector(const char* name, Vector*);
+  bool read_int   (const char* name, int&);
+  bool read_desc  (const char* name, ResDescriptor&);
+  bool read_color (const char* name, Color&);
+  bool read_float (const char* name, float&);
+  bool read_bool  (const char* name, bool&);
+  bool read_string(const char* name, std::string&);
+  bool read_vector(const char* name, Vector&);
 
 private:
   XMLFileReader (const XMLFileReader&);

Index: xml_file_writer.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_file_writer.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- xml_file_writer.cxx 28 Dec 2002 16:57:38 -0000      1.2
+++ xml_file_writer.cxx 18 Feb 2003 01:23:51 -0000      1.3
@@ -19,6 +19,7 @@
 
 #include <iostream>
 #include "vector.hxx"
+#include "color.hxx"
 #include "xml_file_writer.hxx"
 
 XMLFileWriter::XMLFileWriter(std::ostream& out_)
@@ -39,6 +40,13 @@
 }
 
 void
+XMLFileWriter::begin_section (const char* name, const char* attributes)
+{
+  (*out) << "<" << name << " " << attributes << ">\n";
+  section_stack.push(name);
+}
+
+void
 XMLFileWriter::end_section ()
 {
   const std::string& section_name = section_stack.top();
@@ -58,6 +66,18 @@
 XMLFileWriter::write_float  (const char* name, float value)
 {
   (*out) << "<" << name << ">" << value << "</" << name << ">\n";
+}
+
+void
+XMLFileWriter::write_color  (const char* name, const Color& color)
+{
+  (*out) << "<" << name << ">\n"
+         << "  <red>"   << color.red   << "</red>\n"
+         << "  <green>" << color.green << "</green>\n"
+         << "  <blue>"  << color.blue  << "</blue>\n"
+         << "  <alpha>" << color.alpha << "</alpha>\n"
+         << "</" << name << ">"
+         << std::endl;
 }
 
 void

Index: xml_file_writer.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_file_writer.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- xml_file_writer.hxx 28 Dec 2002 16:57:38 -0000      1.2
+++ xml_file_writer.hxx 18 Feb 2003 01:23:51 -0000      1.3
@@ -24,6 +24,8 @@
 #include <iosfwd>
 #include "file_writer.hxx"
 
+class Color;
+
 /** */
 class XMLFileWriter : public FileWriter
 {
@@ -38,11 +40,13 @@
   virtual ~XMLFileWriter();
 
   void begin_section (const char* name);
+  void begin_section (const char* name, const char* attributes);
   void end_section ();
 
   void write_int    (const char* name, int);
   void write_float  (const char* name, float);
   void write_bool   (const char* name, bool);
+  void write_color  (const char* name, const Color&);
   void write_string (const char* name, const std::string&);
   void write_vector (const char* name, const Vector&);
   





reply via email to

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