-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserializable.cpp
100 lines (81 loc) · 1.76 KB
/
serializable.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "serializable.h"
namespace qtxmpp {
Serializable::Serializable()
{
setText(false);
}
QByteArray Serializable::serialize(Serializable *serializable)
{
if(serializable->isText())
return serializable->getName().toUtf8();
else
{
QByteArray byteArray;
byteArray.append("<" + serializable->getName());
QMapIterator<QString, QString> i(serializable->getAttributes());
while(i.hasNext())
{
i.next();
byteArray.append(" " + i.key() + "='" + i.value() + "'");
}
byteArray.append(">");
QListIterator<Serializable> j(serializable->getChildren());
while(j.hasNext())
{
Serializable ser = j.next();
byteArray.append(Serializable::serialize(&ser));
}
byteArray.append("</" + serializable->getName() + ">");
return byteArray;
}
}
Serializable* Serializable::deserialize()
{
return new Serializable();
}
QString Serializable::getXmlns()
{
return m_xmlns;
}
QString Serializable::getName()
{
return m_name;
}
void Serializable::setXmlns(QString xmlns)
{
m_xmlns = xmlns;
m_attributes["xmlns"] = m_xmlns;
}
void Serializable::setName(QString name)
{
m_name = name;
}
QMap<QString, QString> Serializable::getAttributes()
{
return m_attributes;
}
QList<Serializable> Serializable::getChildren()
{
return m_children;
}
void Serializable::addChild(Serializable serializable)
{
m_children.append(serializable);
}
Serializable Serializable::getChild(int child)
{
return m_children.value(child);
}
void Serializable::deleteChildren()
{
m_children.clear();
}
bool Serializable::isText()
{
return m_text;
}
void Serializable::setText(bool text)
{
m_text = text;
}
}