-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccxml.cpp
More file actions
83 lines (76 loc) · 1.63 KB
/
ccxml.cpp
File metadata and controls
83 lines (76 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "ccxml.h"
#include "tinyxml2.h"
#include <vector>
#include <map>
#include "ccspring.h"
class Tiny2Node : public INode{
public:
Tiny2Node(tinyxml2::XMLElement *node) :_node(node)
{
}
Tiny2Node(){}
/**
* 平行节点的下一个节点
*/
virtual INode* nextNode(const char *name)
{
return newNext(_node->NextSiblingElement(name));
}
/**
* 获取节点属性
*/
virtual std::string getStr(const char *name)
{
return (_node->Attribute(name) ? _node->Attribute(name):"");
}
/**
* 获取子节点
*/
virtual INode* childNode(const char *name)
{
return newName(name,_node->FirstChildElement(name));
}
private:
tinyxml2::XMLElement *_node;
std::string next;
std::map<std::string,std::string> childs;
friend class Tiny2Doc;
Tiny2Node *newNext(tinyxml2::XMLElement *ele)
{
if (!ele) return 0;
next.resize(sizeof(Tiny2Node) + sizeof(int));
Tiny2Node * next1 = new (&next[0]) Tiny2Node(ele);
return next1;
}
Tiny2Node *newName(const char *name,tinyxml2::XMLElement *ele)
{
if (!ele) return 0;
std::string & child = childs[name];
child.resize(sizeof(Tiny2Node) + sizeof(int));
Tiny2Node * node = new (&child[0]) Tiny2Node(ele);
return node;
}
};
class Tiny2Doc : public IXML, public Creator<Tiny2Doc>{
public:
bool initFrom(const char *filename)
{
if (doc.LoadFile(filename)) return false;
return true;
}
INode* firstNode(const char *name)
{
tinyxml2::XMLElement * ele = doc.RootElement();
root._node = ele->FirstChildElement(name);
if (root._node == 0) return 0;
return &root;
}
private:
tinyxml2::XMLDocument doc;
Tiny2Node root;
};
void XML::imp()
{
setImp<Tiny2Doc>();
}
CREATOR("tinyxml2",Tiny2Doc);