Subversion Repositories HomeAutomation

Rev

Rev 1315 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1309 runge 1
/*
2
 * Node.h
3
 *
4
 *  Created on: Apr 26, 2009
5
 *      Author: Mattias Runge
6
 */
7
 
8
#ifndef NODE_H_
9
#define NODE_H_
10
 
11
#include <string>
12
#include <map>
13
#include <stdexcept>
14
#include <utility>
1315 runge 15
#include "log/Logger.h"
1314 runge 16
#include "utils/file.h"
17
#include "utils/convert.h"
18
#include "Exception.hpp"
1309 runge 19
#include <boost/algorithm/string/trim.hpp>
20
 
21
namespace atom {
22
namespace xml {
23
 
24
using namespace std;
25
using namespace boost::algorithm;
26
 
27
class Node
28
{
29
public:
1323 runge 30
    typedef std::map<std::string, std::string> attributeList; // TODO Move these typedef:s out of the class
1309 runge 31
    typedef std::pair<std::string, std::string> attributePair;
32
    typedef std::vector<Node> nodeList;
33
 
34
    Node();
35
    Node(string filename);
36
    Node(string filename, string xmlData);
37
 
1310 runge 38
    void load(string filename);
39
    void parse(string filename, string xmlData);
40
 
1309 runge 41
    string tagName();
42
    attributeList & attributes();
43
 
44
    string operator [](string attributeName);
45
 
46
    Node selectFirst();
47
    Node selectFirst(string tagName);
48
    Node selectFirst(string tagName, attributeList attributes);
49
    Node selectFirst(string tagName, attributePair pair1);
50
    Node selectFirst(string tagName, attributePair pair1, attributePair pair2);
51
    Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3);
52
    Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4);
53
    Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4, attributePair pair5);
54
 
55
    nodeList select();
56
    nodeList select(string tagName);
57
    nodeList select(string tagName, attributeList attributes);
58
    nodeList select(string tagName, attributePair pair1);
59
    nodeList select(string tagName, attributePair pair1, attributePair pair2);
60
    nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3);
61
    nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4);
62
    nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4, attributePair pair5);
63
 
64
    string toString();
65
 
66
private:
1315 runge 67
    log::Logger LOG;
1309 runge 68
 
69
    bool myIsEmpty;
70
    string myTagName;
71
    attributeList myAttributes;
72
    nodeList myChildren;
73
 
74
    int parseTag(string filename, string xmlData, unsigned int position);
75
};
76
 
77
}
78
}
79
 
80
#endif /* NODE_H_ */