]> git.mxchange.org Git - simgear.git/blob - simgear/xml/easyxml.hxx
Added a touch of error checking to the screen dump routine, i.e. don't
[simgear.git] / simgear / xml / easyxml.hxx
1 #ifndef __EASYXML_HXX
2 #define __EASYXML_HXX
3
4 #include <iostream>
5 #include <string>
6 #include <vector>
7
8 using std::istream;
9 using std::string;
10 using std::vector;
11
12
13 /**
14  * Interface for XML attributes.
15  */
16 class XMLAttributes
17 {
18 public:
19   XMLAttributes ();
20   virtual ~ XMLAttributes ();
21
22   virtual int size () const = 0;
23   virtual const char * getName (int i) const = 0;
24   virtual const char * getValue (int i) const = 0;
25
26   virtual int findAttribute (const char * name) const;
27   virtual bool hasAttribute (const char * name) const;
28   virtual const char * getValue (const char * name) const;
29 };
30
31
32 /**
33  * Default mutable attributes implementation.
34  */
35 class XMLAttributesDefault : public XMLAttributes
36 {
37 public:
38   XMLAttributesDefault ();
39   XMLAttributesDefault (const XMLAttributes & atts);
40   virtual ~XMLAttributesDefault ();
41
42   virtual int size () const;
43   virtual const char * getName (int i) const;
44   virtual const char * getValue (int i) const;
45
46   virtual void addAttribute (const char * name, const char * value);
47   virtual void setName (int i, const char * name);
48   virtual void setValue (int i, const char * value);
49   virtual void setValue (const char * name, const char * value);
50
51 private:
52   vector<string> _atts;
53 };
54
55
56 /**
57  * Visitor class for an XML document.
58  *
59  * To read an XML document, a module must subclass the visitor to do
60  * something useful for the different XML events.
61  */
62 class XMLVisitor
63 {
64 public:
65                                 // start an XML document
66   virtual void startXML () {}
67                                 // end an XML document
68   virtual void endXML () {}
69                                 // start an element
70   virtual void startElement (const char * name, const XMLAttributes &atts) {}
71                                 // end an element
72   virtual void endElement (const char * name) {}
73                                 // character data
74   virtual void data (const char * s, int length) {}
75                                 // processing instruction
76   virtual void pi (const char * target, const char * data) {}
77                                 // non-fatal warning
78   virtual void warning (const char * message, int line, int column) {}
79                                 // fatal error
80   virtual void error (const char * message, int line, int column) = 0;
81 };
82
83
84 /**
85  * Read an XML document.
86  */
87 extern bool readXML (istream &input, XMLVisitor &visitor);
88
89
90 #endif // __EASYXML_HXX
91