diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-05-09 15:04:31 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-05-09 15:04:31 +0000 |
commit | ad92dc50b7cdf7cfe086f21d19442d03a90fd05d (patch) | |
tree | 9ca6f7bde704cb44276a05b6e83f36754e07f732 /src/xmldocument.cpp | |
parent | 2e035fee36768e3c765b7f5dc10bf0a3b7d2448b (diff) | |
download | libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.gz libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.bz2 libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.xz libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.zip |
Just a few things re-arranged, moved the new taf/xml systems to the inprogress
directory, and moved the old xml system in, so it will require heavy changes.
Diffstat (limited to 'src/xmldocument.cpp')
-rw-r--r-- | src/xmldocument.cpp | 146 |
1 files changed, 143 insertions, 3 deletions
diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp index cb21826..d7867d5 100644 --- a/src/xmldocument.cpp +++ b/src/xmldocument.cpp | |||
@@ -1,9 +1,149 @@ | |||
1 | #include "xmldocument.h" | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | ||
3 | #include "xmlwriter.h" | ||
2 | 4 | ||
3 | Bu::XmlDocument::XmlDocument() | 5 | XmlDocument::XmlDocument( XmlNode *pRoot ) |
4 | { | 6 | { |
7 | this->pRoot = pRoot; | ||
8 | pCurrent = NULL; | ||
9 | bCompleted = (pRoot!=NULL); | ||
5 | } | 10 | } |
6 | 11 | ||
7 | Bu::XmlDocument::~XmlDocument() | 12 | XmlDocument::~XmlDocument() |
8 | { | 13 | { |
14 | if( pRoot ) | ||
15 | { | ||
16 | delete pRoot; | ||
17 | } | ||
9 | } | 18 | } |
19 | |||
20 | void XmlDocument::addNode( const char *sName, const char *sContent, bool bClose ) | ||
21 | { | ||
22 | if( pRoot == NULL ) | ||
23 | { | ||
24 | // This is the first node, so ignore position and just insert it. | ||
25 | pCurrent = pRoot = new XmlNode( sName, NULL, sContent ); | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | pCurrent = pCurrent->addChild( sName, sContent ); | ||
30 | } | ||
31 | |||
32 | if( bClose ) | ||
33 | { | ||
34 | closeNode(); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | void XmlDocument::setName( const char *sName ) | ||
39 | { | ||
40 | pCurrent->setName( sName ); | ||
41 | } | ||
42 | |||
43 | bool XmlDocument::isCompleted() | ||
44 | { | ||
45 | return bCompleted; | ||
46 | } | ||
47 | |||
48 | XmlNode *XmlDocument::getRoot() | ||
49 | { | ||
50 | return pRoot; | ||
51 | } | ||
52 | |||
53 | XmlNode *XmlDocument::detatchRoot() | ||
54 | { | ||
55 | XmlNode *pTemp = pRoot; | ||
56 | pRoot = NULL; | ||
57 | return pTemp; | ||
58 | } | ||
59 | |||
60 | XmlNode *XmlDocument::getCurrent() | ||
61 | { | ||
62 | return pCurrent; | ||
63 | } | ||
64 | |||
65 | void XmlDocument::closeNode() | ||
66 | { | ||
67 | if( pCurrent != NULL ) | ||
68 | { | ||
69 | pCurrent = pCurrent->getParent(); | ||
70 | |||
71 | if( pCurrent == NULL ) | ||
72 | { | ||
73 | bCompleted = true; | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | void XmlDocument::addProperty( const char *sName, const char *sValue ) | ||
79 | { | ||
80 | if( pCurrent ) | ||
81 | { | ||
82 | pCurrent->addProperty( sName, sValue ); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void XmlDocument::addProperty( const char *sName, const unsigned char nValue ) | ||
87 | { | ||
88 | char buf[12]; | ||
89 | sprintf( buf, "%hhi", nValue ); | ||
90 | addProperty( sName, buf ); | ||
91 | } | ||
92 | |||
93 | void XmlDocument::addProperty( const char *sName, const char nValue ) | ||
94 | { | ||
95 | char buf[12]; | ||
96 | sprintf( buf, "%hhi", nValue ); | ||
97 | addProperty( sName, buf ); | ||
98 | } | ||
99 | |||
100 | void XmlDocument::addProperty( const char *sName, const unsigned short nValue ) | ||
101 | { | ||
102 | char buf[12]; | ||
103 | sprintf( buf, "%hi", nValue ); | ||
104 | addProperty( sName, buf ); | ||
105 | } | ||
106 | |||
107 | void XmlDocument::addProperty( const char *sName, const short nValue ) | ||
108 | { | ||
109 | char buf[12]; | ||
110 | sprintf( buf, "%hi", nValue ); | ||
111 | addProperty( sName, buf ); | ||
112 | } | ||
113 | |||
114 | void XmlDocument::addProperty( const char *sName, const int nValue ) | ||
115 | { | ||
116 | char buf[12]; | ||
117 | sprintf( buf, "%d", nValue ); | ||
118 | addProperty( sName, buf ); | ||
119 | } | ||
120 | |||
121 | void XmlDocument::addProperty( const char *sName, const unsigned long nValue ) | ||
122 | { | ||
123 | char buf[12]; | ||
124 | sprintf( buf, "%li", nValue ); | ||
125 | addProperty( sName, buf ); | ||
126 | } | ||
127 | |||
128 | void XmlDocument::addProperty( const char *sName, const long nValue ) | ||
129 | { | ||
130 | char buf[12]; | ||
131 | sprintf( buf, "%li", nValue ); | ||
132 | addProperty( sName, buf ); | ||
133 | } | ||
134 | |||
135 | void XmlDocument::addProperty( const char *sName, const double dValue ) | ||
136 | { | ||
137 | char buf[40]; | ||
138 | sprintf( buf, "%f", dValue ); | ||
139 | addProperty( sName, buf ); | ||
140 | } | ||
141 | |||
142 | void XmlDocument::setContent( const char *sContent ) | ||
143 | { | ||
144 | if( pCurrent ) | ||
145 | { | ||
146 | pCurrent->setContent( sContent ); | ||
147 | } | ||
148 | } | ||
149 | |||