-
Notifications
You must be signed in to change notification settings - Fork 3
/
AttributeList.cpp
55 lines (44 loc) · 1.04 KB
/
AttributeList.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
#include "AttributeList.h"
#include <sstream>
namespace Bxml {
AttributeList::AttributeList(char* data, size_t length)
{
Xml = NULL;
size = 0;
size_t* byteLengthPtr = reinterpret_cast<size_t*>(data);
byteLength = *byteLengthPtr;
size += sizeof size_t;
Attribute* attr = NULL;
do {
attr = new Attribute(data+size, length-size);
size += appendAttribute(attr);
} while (!attr->isLast());
}
AttributeList::~AttributeList(void)
{
if (Xml != NULL) {
delete Xml;
}
}
size_t AttributeList::appendAttribute(Attribute *attr) {
attributes->push_back(attr);
return attr->getSize();
}
std::wstring* AttributeList::toXml() {
if (Xml == NULL) {
std::wstringstream xmlStream;
for (size_t i=0; i<attributes->size(); ++i) {
std::wstring* attrXml = (*attributes)[i]->toXml();
xmlStream << L" " << (*attrXml);
}
Xml = new std::wstring(xmlStream.str());
}
return Xml;
}
size_t AttributeList::getSize() {
return size;
}
size_t AttributeList::getByteLength() {
return byteLength;
}
}