Subversion Repositories gelsvn

Rev

Rev 382 | Rev 595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 382 Rev 448
1
#ifndef XMLPARSER_H
1
#ifndef __UTIL_XMLPARSER_H
2
#define XMLPARSER_H
2
#define __UTIL_XMLPARSER_H
3
 
3
 
4
#include <iostream>
4
#include <iostream>
5
#include <fstream>
5
#include <fstream>
6
#include <string>
6
#include <string>
7
#include <list>
7
#include <list>
8
#include <map>
8
#include <map>
9
 
9
 
10
namespace Util
10
namespace Util
11
{
11
{
12
  struct XmlHead
12
  struct XmlHead
13
  {
13
  {
14
    XmlHead() : is_xml(false) { }
14
    XmlHead() : is_xml(false) { }
15
 
15
 
16
    bool is_xml;
16
    bool is_xml;
17
    std::map<std::string, std::string> atts;
17
    std::map<std::string, std::string> atts;
18
  };
18
  };
19
  
19
  
20
  struct XmlBody;
20
  struct XmlBody;
21
  class XmlDoc;
21
  class XmlDoc;
22
 
22
 
23
  struct XmlElement
23
  struct XmlElement
24
  {
24
  {
25
    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) { }
26
    XmlElement(XmlDoc* in_doc) : body(0), doc(in_doc), parent(0) { }
26
    XmlElement(XmlDoc* in_doc) : body(0), doc(in_doc), parent(0) { }
27
    ~XmlElement();
27
    ~XmlElement();
28
 
28
 
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;
34
    XmlDoc* doc;
34
    XmlDoc* doc;
35
    XmlElement* parent;
35
    XmlElement* parent;
36
  };
36
  };
37
 
37
 
38
  struct XmlBody
38
  struct XmlBody
39
  {
39
  {
40
    XmlBody(XmlDoc* parent) : doc(parent), element(parent) { }
40
    XmlBody(XmlDoc* parent) : doc(parent), element(parent) { }
41
 
41
 
42
    void process_element();
42
    void process_element();
43
 
43
 
44
    std::string text;
44
    std::string text;
45
    XmlElement element;
45
    XmlElement element;
46
    XmlDoc* doc;
46
    XmlDoc* doc;
47
  };
47
  };
48
 
48
 
49
  typedef void (*XmlElementHandler)(XmlElement&);
49
  typedef void (*XmlElementHandler)(XmlElement&);
50
 
50
 
51
  class XmlDoc
51
  class XmlDoc
52
  {
52
  {
53
  public:
53
  public:
54
    XmlDoc(const char* filename);
54
    XmlDoc(const char* filename);
55
 
55
 
56
    bool is_valid() const { return head.is_xml; }
56
    bool is_valid() const { return head.is_xml; }
57
    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; }
58
    void process_elements();
58
    void process_elements();
59
    void close() { infile.close(); }
59
    void close() { infile.close(); }
60
 
60
 
61
    XmlHead head;
61
    XmlHead head;
62
 
62
 
63
  private:
63
  private:
64
    friend struct XmlElement;
64
    friend struct XmlElement;
65
    friend struct XmlBody;
65
    friend struct XmlBody;
66
 
66
 
67
    std::ifstream infile;
67
    std::ifstream infile;
68
    XmlBody body;
68
    XmlBody body;
69
    std::map<std::string, XmlElementHandler> handlers;
69
    std::map<std::string, XmlElementHandler> handlers;
70
  };
70
  };
71
 
71
 
72
  std::ostream& operator<<(std::ostream& out, const XmlHead& head);
72
  std::ostream& operator<<(std::ostream& out, const XmlHead& head);
73
}
73
}
74
 
74
 
75
#endif // XMLPARSER_H
75
#endif // XMLPARSER_H
76
 
76
 
77

Generated by GNU Enscript 1.6.6.
77

Generated by GNU Enscript 1.6.6.
78
 
78
 
79
 
79
 
80
 
80