-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAttribute.cpp
More file actions
80 lines (59 loc) · 1.38 KB
/
Attribute.cpp
File metadata and controls
80 lines (59 loc) · 1.38 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
#include "Attribute.h"
#include "Tokens.h"
#include <sstream>
namespace Bxml {
Attribute::Attribute(char* data, size_t length)
{
Xml = NULL;
size = 0;
last = (*(data+size)) == AttributeLast;
size += sizeof byte;
name = new Name(data+size, length-size);
size += name->getSize();
Node *value = NULL;
do {
value = Node::createNode(data+size, length-size);
size += appendData(value);
} while (!value->isLast());
}
Attribute::~Attribute(void)
{
delete name;
for (size_t i=0, size=attributeData->size(); i<size; ++i) {
delete (*attributeData)[i];
}
delete attributeData;
if (Xml != NULL) {
delete Xml;
}
}
size_t Attribute::appendData(Node *node) {
attributeData->push_back(node);
return node->getSize();
}
std::wstring* Attribute::toXml() {
if (Xml == NULL) {
if (attributeData->size() == 0) {
Xml = new std::wstring();
}
else {
std::wstringstream xmlStream;
std::wstring* nameXml = name->toXml();
xmlStream << (*nameXml) << L"='";
for (size_t i=0, size=attributeData->size(); i<size; ++i) {
std::wstring* dataPartXml = (*attributeData)[i]->toXml();
xmlStream << (*dataPartXml);
}
xmlStream << L"'";
Xml = new std::wstring(xmlStream.str());
}
}
return Xml;
}
bool Attribute::isLast() {
return last;
}
size_t Attribute::getSize() {
return size;
}
}