-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathElementNode.cpp
80 lines (66 loc) · 1.82 KB
/
ElementNode.cpp
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
#include "ElementNode.h"
#include <sstream>
namespace Bxml {
ElementNode::ElementNode(char* data, size_t length, Context context, bool hasAttributes) :
Node(data, length, context)
{
name = NULL;
// TODO: use length to prevent data overrun
DependencyId = DEP_NO_DEPENDENCY;
size++; // pass ElementNode start token
if (context == TemplateDefinition) {
uint16* DependencyIdPtr = reinterpret_cast<uint16*>(data+size);
DependencyId = *DependencyIdPtr;
size += sizeof uint16;
}
uint32* LengthPtr = reinterpret_cast<uint32*>(data+size);
Length = *LengthPtr;
size += sizeof uint32;
name = new Name(data+size, length-size);
size += name->getSize();
if (hasAttributes) {
attributeList = new AttributeList(data+size, length-size);
size += attributeList->getSize();
}
else {
attributeList = NULL;
}
Node* node;
do {
node = Node::createNode(data+size, length-size, context);
size += appendChild(node);
} while (!node->isLast());
}
ElementNode::~ElementNode(void)
{
if (name != NULL) {
delete name;
}
}
std::wstring* ElementNode::toXml() {
if (Xml == NULL) {
std::wstringstream xmlStream;
if (DependencyId != DEP_NO_DEPENDENCY /* && NULL optional substitution exists */) {
// TODO: do not emit anything
}
else {
xmlStream << L'<';
std::wstring* nameXml = name->toXml();
xmlStream << (*nameXml);
if (attributeList != NULL) {
std::wstring* attrListXml = attributeList->toXml();
xmlStream << (*attrListXml);
}
for (Node* node = getFirstChild(); nextChildExists(); node = getNextChild()) {
std::wstring* nodeXml = node->toXml();
xmlStream << (*nodeXml);
}
}
Xml = new std::wstring(xmlStream.str());
}
return Xml;
}
std::wstring* ElementNode::getName() {
return name->toXml();
}
}