Subversion Repositories gelsvn

Rev

Rev 375 | Rev 382 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 375 Rev 380
Line 1... Line 1...
1
#ifndef XMLPARSER_H
1
#ifndef XMLPARSER_H
2
#define XMLPARSER_H
2
#define XMLPARSER_H
3
 
3
 
4
#include <iostream>
4
#include <iostream>
-
 
5
#include <fstream>
5
#include <string>
6
#include <string>
6
#include <list>
7
#include <list>
7
#include <map>
8
#include <map>
8
 
9
 
9
namespace Util
10
namespace Util
Line 23... Line 24...
23
  {
24
  {
24
    XmlElement(XmlDoc* in_doc, XmlElement* parent_elem) : body(0), doc(in_doc), parent(parent_elem) { }
25
    XmlElement(XmlDoc* in_doc, XmlElement* parent_elem) : body(0), doc(in_doc), parent(parent_elem) { }
25
    XmlElement(XmlDoc* in_doc) : body(0), doc(in_doc), parent(0) { }
26
    XmlElement(XmlDoc* in_doc) : body(0), doc(in_doc), parent(0) { }
26
    ~XmlElement();
27
    ~XmlElement();
27
 
28
 
28
    void process_element(XmlElement& elem);
-
 
29
    void process_elements();
29
    void process_elements();
30
 
30
 
31
    std::string name;
31
    std::string name;
32
    std::map<std::string, std::string> atts;
32
    std::map<std::string, std::string> atts;
33
    XmlBody* body;
33
    XmlBody* body;
Line 35... Line 35...
35
    XmlElement* parent;
35
    XmlElement* parent;
36
  };
36
  };
37
 
37
 
38
  struct XmlBody
38
  struct XmlBody
39
  {
39
  {
40
    XmlBody(XmlDoc* parent) : doc(parent) { }
40
    XmlBody(XmlDoc* parent) : doc(parent), element(parent) { }
41
 
41
 
-
 
42
    void process_element();
-
 
43
 
42
    std::list<std::string> text;
44
    std::string text;
43
    std::list<XmlElement> elements;
45
    XmlElement element;
44
    XmlDoc* doc;
46
    XmlDoc* doc;
45
  };
47
  };
46
 
48
 
47
  typedef void (*XmlElementHandler)(XmlElement&);
49
  typedef void (*XmlElementHandler)(XmlElement&);
48
 
50
 
Line 52... Line 54...
52
    XmlDoc(const char* filename);
54
    XmlDoc(const char* filename);
53
 
55
 
54
    bool is_valid() const { return head.is_xml; }
56
    bool is_valid() const { return head.is_xml; }
55
    void add_handler(const std::string& element_name, const XmlElementHandler& h) { handlers[element_name] = h; }
57
    void add_handler(const std::string& element_name, const XmlElementHandler& h) { handlers[element_name] = h; }
56
    void process_elements();
58
    void process_elements();
57
    std::ostream& put(std::ostream& out) const;
59
    void close() { infile.close(); }
-
 
60
 
-
 
61
    XmlHead head;
58
 
62
 
59
  private:
63
  private:
60
    friend XmlElement;
64
    friend XmlElement;
-
 
65
    friend XmlBody;
61
 
66
 
62
    void load_xml(const char* filename);
-
 
63
 
-
 
64
    XmlHead head;
67
    std::ifstream infile;
65
    XmlBody body;
68
    XmlBody body;
66
    std::map<std::string, XmlElementHandler> handlers;
69
    std::map<std::string, XmlElementHandler> handlers;
67
  };
70
  };
68
 
71
 
69
  std::ostream& operator<<(std::ostream& out, const XmlHead& head);
72
  std::ostream& operator<<(std::ostream& out, const XmlHead& head);
70
  std::ostream& operator<<(std::ostream& out, const XmlElement& elem);
-
 
71
  std::ostream& operator<<(std::ostream& out, const XmlBody& body);
-
 
72
  inline std::ostream& operator<<(std::ostream& out, const XmlDoc& doc) { return doc.put(out); } 
-
 
73
}
73
}
74
 
74
 
75
#endif // XMLPARSER_H
75
#endif // XMLPARSER_H
76
 
76