summaryrefslogtreecommitdiff
path: root/src/xmldocument.cpp
blob: 234ff81cf7c1cb46f877cbb55bc1a64f86336451 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include <stdlib.h>
#include "xmlwriter.h"

XmlDocument::XmlDocument( XmlNode *pRoot )
{
	this->pRoot = pRoot;
	pCurrent = NULL;
	bCompleted = (pRoot!=NULL);
}

XmlDocument::~XmlDocument()
{
	if( pRoot )
	{
		delete pRoot;
	}
}

void XmlDocument::addNode( const char *sName, const char *sContent, bool bClose )
{
	if( pRoot == NULL )
	{
		// This is the first node, so ignore position and just insert it.
		pCurrent = pRoot = new XmlNode( sName, NULL, sContent );
	}
	else
	{
		pCurrent = pCurrent->addChild( sName, sContent );
	}

	if( bClose )
	{
		closeNode();
	}
}

void XmlDocument::setName( const char *sName )
{
	pCurrent->setName( sName );
}

bool XmlDocument::isCompleted()
{
	return bCompleted;
}

XmlNode *XmlDocument::getRoot()
{
	return pRoot;
}

XmlNode *XmlDocument::getCurrent()
{
	return pCurrent;
}

void XmlDocument::closeNode()
{
	if( pCurrent != NULL )
	{
		pCurrent = pCurrent->getParent();
		
		if( pCurrent == NULL )
		{
			bCompleted = true;
		}
	}
}

void XmlDocument::addProperty( const char *sName, const char *sValue )
{
	if( pCurrent )
	{
		pCurrent->addProperty( sName, sValue );
	}
}

void XmlDocument::addProperty( const char *sName, const unsigned char nValue )
{
	char buf[12];
	sprintf( buf, "%hhi", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const char nValue )
{
	char buf[12];
	sprintf( buf, "%hhi", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const unsigned short nValue )
{
	char buf[12];
	sprintf( buf, "%hi", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const short nValue )
{
	char buf[12];
	sprintf( buf, "%hi", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const int nValue )
{
	char buf[12];
	sprintf( buf, "%li", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const unsigned long nValue )
{
	char buf[12];
	sprintf( buf, "%li", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const long nValue )
{
	char buf[12];
	sprintf( buf, "%li", nValue );
	addProperty( sName, buf );
}

void XmlDocument::addProperty( const char *sName, const double dValue )
{
	char buf[40];
	sprintf( buf, "%f", dValue );
	addProperty( sName, buf );
}

void XmlDocument::setContent( const char *sContent )
{
	if( pCurrent )
	{
		pCurrent->setContent( sContent );
	}
}