]> git.mxchange.org Git - simgear.git/blobdiff - simgear/xml/easyxml.cxx
cppbind.Ghost: clean up a bit
[simgear.git] / simgear / xml / easyxml.cxx
index 57a1bee2577ddced0f561efc901545b7194f7c39..2a6953593df74132e08ec779a71511ad5618afd2 100644 (file)
@@ -1,17 +1,31 @@
-// easyxml.cxx - implementation of EasyXML interfaces.
-
+/**
+ * \file easyxml.cxx - implementation of EasyXML interfaces.
+ * Written by David Megginson, 2000-2001
+ * This file is in the Public Domain, and comes with NO WARRANTY of any kind.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+     
 #include <simgear/compiler.h>
 
 #include <string.h>            // strcmp()
 
 #include "easyxml.hxx"
-#include "xmlparse.h"
-
-#include STL_FSTREAM
-#include STL_IOSTREAM
-
-SG_USING_STD(ifstream);
-
+     
+#ifdef SYSTEM_EXPAT
+#  include <expat.h>
+#else
+#  include "sg_expat.h"     
+#endif
+     
+#include <fstream>
+#include <iostream>
+
+using std::ifstream;
+using std::istream;
+using std::string;
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -123,24 +137,20 @@ XMLAttributesDefault::setValue (const char * name, const char * value)
 }
 
 
-\f
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void XMLVisitor::savePosition(void)
+{
+  if (parser) {
+    column = XML_GetCurrentColumnNumber(parser);
+    line = XML_GetCurrentLineNumber(parser);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////////
 // Attribute list wrapper for Expat.
 ////////////////////////////////////////////////////////////////////////
 
-class ExpatAtts : public XMLAttributes
-{
-public:
-  ExpatAtts (const char ** atts) : _atts(atts) {}
-  
-  virtual int size () const;
-  virtual const char * getName (int i) const;
-  virtual const char * getValue (int i) const;
-  
-private:
-  const char ** _atts;
-};
-
 int
 ExpatAtts::size () const
 {
@@ -162,6 +172,11 @@ ExpatAtts::getValue (int i) const
   return _atts[i*2+1];
 }
 
+const char * 
+ExpatAtts::getValue (const char * name) const
+{
+  return XMLAttributes::getValue(name);
+}
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -173,18 +188,21 @@ ExpatAtts::getValue (int i) const
 static void
 start_element (void * userData, const char * name, const char ** atts)
 {
+  VISITOR.savePosition();
   VISITOR.startElement(name, ExpatAtts(atts));
 }
 
 static void
 end_element (void * userData, const char * name)
 {
+  VISITOR.savePosition();
   VISITOR.endElement(name);
 }
 
 static void
 character_data (void * userData, const char * s, int len)
 {
+  VISITOR.savePosition();
   VISITOR.data(s, len);
 }
 
@@ -193,6 +211,7 @@ processing_instruction (void * userData,
                        const char * target,
                        const char * data)
 {
+  VISITOR.savePosition();
   VISITOR.pi(target, data);
 }
 
@@ -213,6 +232,8 @@ readXML (istream &input, XMLVisitor &visitor, const string &path)
   XML_SetCharacterDataHandler(parser, character_data);
   XML_SetProcessingInstructionHandler(parser, processing_instruction);
 
+  visitor.setParser(parser);
+  visitor.setPath(path);
   visitor.startXML();
 
   char buf[16384];
@@ -225,6 +246,7 @@ readXML (istream &input, XMLVisitor &visitor, const string &path)
                                        XML_GetCurrentLineNumber(parser),
                                        XML_GetCurrentColumnNumber(parser)),
                            "SimGear XML Parser");
+      visitor.setParser(0);
       XML_ParserFree(parser);
       throw ex;
     }
@@ -236,6 +258,7 @@ readXML (istream &input, XMLVisitor &visitor, const string &path)
                                        XML_GetCurrentLineNumber(parser),
                                        XML_GetCurrentColumnNumber(parser)),
                            "SimGear XML Parser");
+      visitor.setParser(0);
       XML_ParserFree(parser);
       throw ex;
     }
@@ -249,11 +272,14 @@ readXML (istream &input, XMLVisitor &visitor, const string &path)
                                      XML_GetCurrentLineNumber(parser),
                                      XML_GetCurrentColumnNumber(parser)),
                          "SimGear XML Parser");
+    visitor.setParser(0);
     XML_ParserFree(parser);
     throw ex;
   }
 
+  visitor.setParser(0);
   XML_ParserFree(parser);
+  visitor.endXML();
 }
 
 void
@@ -299,6 +325,7 @@ readXML (const char *buf, const int size, XMLVisitor &visitor)
   }
 
   XML_ParserFree(parser);
+  visitor.endXML();
 }
 
 // end of easyxml.cxx