summaryrefslogtreecommitdiff
path: root/src/xmlnode.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-12 01:28:27 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-12 01:28:27 +0000
commit4cb166570a8e2e97216bf6c7aeb99b971ff58ad7 (patch)
treeb8d22af96957666ac761b6ca1b57da1eee2e56a5 /src/xmlnode.cpp
parentb6f50f249ba3b18c597531a2d5dbc45f7bfa3eaa (diff)
downloadlibbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.tar.gz
libbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.tar.bz2
libbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.tar.xz
libbu++-4cb166570a8e2e97216bf6c7aeb99b971ff58ad7.zip
Moved out the xml system again. I think that if I am going to do it again,
I'm going to do it over from scratch, that was just painful. Also, started in again on the server system, it's looking pretty good, already got connections working, next up is managing data flow through clients and protocols!
Diffstat (limited to 'src/xmlnode.cpp')
-rw-r--r--src/xmlnode.cpp403
1 files changed, 0 insertions, 403 deletions
diff --git a/src/xmlnode.cpp b/src/xmlnode.cpp
deleted file mode 100644
index 96d5850..0000000
--- a/src/xmlnode.cpp
+++ /dev/null
@@ -1,403 +0,0 @@
1#include "xmlnode.h"
2
3XmlNode::XmlNode( const Bu::FString &sName, XmlNode *pParent ) :
4 sName( sName ),
5 pParent( pParent )
6{
7}
8
9XmlNode::~XmlNode()
10{
11}
12/*
13void XmlNode::setName( const char *sName )
14{
15 if( pParent )
16 {
17 if( this->sName.size() == 0 )
18 {
19 // We're not in the hash yet, so add us
20 this->sName = sName;
21 pParent->hChildren.insert( this->sName.c_str(), this );
22 }
23 else
24 {
25 // Slightly more tricky, delete us, then add us...
26 pParent->hChildren.del( this->sName.c_str() );
27 this->sName = sName;
28 pParent->hChildren.insert( this->sName.c_str(), this );
29 }
30 }
31 else
32 {
33 // If we have no parent, then just set the name string, we don't need
34 // to worry about hashing.
35 this->sName = sName;
36 }
37}
38
39void XmlNode::setContent( const char *sContent, int nIndex )
40{
41 if( nIndex == -1 )
42 {
43 nIndex = nCurContent;
44 }
45 if( nIndex == 0 )
46 {
47 if( this->sPreContent )
48 {
49 delete this->sPreContent;
50 }
51
52 this->sPreContent = new std::string( sContent );
53 }
54 else
55 {
56 nIndex--;
57 if( lPostContent[nIndex] )
58 {
59 delete (std::string *)lPostContent[nIndex];
60 }
61
62 lPostContent.setAt( nIndex, new std::string( sContent ) );
63 }
64}
65
66const char *XmlNode::getContent( int nIndex )
67{
68 if( nIndex == 0 )
69 {
70 if( sPreContent )
71 {
72 return sPreContent->c_str();
73 }
74 }
75 else
76 {
77 nIndex--;
78 if( lPostContent[nIndex] )
79 {
80 return ((std::string *)lPostContent[nIndex])->c_str();
81 }
82 }
83
84 return NULL;
85}*/
86
87XmlNode *XmlNode::addChild( const Bu::FString &sName )
88{
89 return addChild( new XmlNode( sName, this ) );
90}
91
92XmlNode *XmlNode::addChild( XmlNode *pNode )
93{
94 Child c = { typeNode };
95 c.pNode = pNode;
96 lChildren.append( c );
97 pNode->pParent = this;
98
99 return pNode;
100}
101
102XmlNode *XmlNode::getParent()
103{
104 return pParent;
105}
106
107void XmlNode::addProperty( const Bu::FString &sName, const Bu::FString &sValue )
108{
109 hProperties.insert( sName, sValue );
110}
111
112int XmlNode::getNumProperties()
113{
114 return hProperties.size();
115}
116/*
117const char *XmlNode::getPropertyName( int nIndex )
118{
119 std::string *tmp = ((std::string *)lPropNames[nIndex]);
120 if( tmp == NULL )
121 return NULL;
122 return tmp->c_str();
123}
124
125const char *XmlNode::getProperty( int nIndex )
126{
127 std::string *tmp = ((std::string *)lPropValues[nIndex]);
128 if( tmp == NULL )
129 return NULL;
130 return tmp->c_str();
131}
132*/
133Bu::FString XmlNode::getProperty( const Bu::FString &sName )
134{
135 return hProperties[sName];
136}
137/*
138void XmlNode::deleteProperty( int nIndex )
139{
140 hProperties.del( ((std::string *)lPropNames[nIndex])->c_str() );
141
142 delete (std::string *)lPropNames[nIndex];
143 delete (std::string *)lPropValues[nIndex];
144
145 lPropNames.deleteAt( nIndex );
146 lPropValues.deleteAt( nIndex );
147}
148
149bool XmlNode::hasChildren()
150{
151 return hChildren.getSize()>0;
152}*/
153
154int XmlNode::getNumChildren()
155{
156 return lChildren.getSize();
157}
158/*
159XmlNode *XmlNode::getChild( int nIndex )
160{
161 return (XmlNode *)lChildren[nIndex];
162}
163*/
164XmlNode *XmlNode::getChild( const Bu::FString &sName, int nSkip )
165{
166 if( !hChildren.has( sName ) )
167 return NULL;
168
169 Bu::List<XmlNode *>::iterator i = hChildren[sName]->begin();
170 return *i;
171}
172
173Bu::FString XmlNode::getName()
174{
175 return sName;
176}
177/*
178void XmlNode::deleteNode( int nIndex, const char *sReplacementText )
179{
180 XmlNode *xRet = detatchNode( nIndex, sReplacementText );
181
182 if( xRet != NULL )
183 {
184 delete xRet;
185 }
186}
187
188XmlNode *XmlNode::detatchNode( int nIndex, const char *sReplacementText )
189{
190 if( nIndex < 0 || nIndex >= lChildren.getSize() )
191 return NULL;
192
193 // The real trick when deleteing a node isn't actually deleting it, it's
194 // reforming the content around the node that's now missing...hmmm...
195
196 if( nIndex == 0 )
197 {
198 // If the index is zero we have to deal with the pre-content
199 if( sReplacementText )
200 {
201 if( sPreContent == NULL )
202 {
203 sPreContent = new std::string( sReplacementText );
204 }
205 else
206 {
207 *sPreContent += sReplacementText;
208 }
209 }
210 if( lPostContent.getSize() > 0 )
211 {
212 if( lPostContent[0] != NULL )
213 {
214 if( sPreContent == NULL )
215 {
216 sPreContent = new std::string(
217 ((std::string *)lPostContent[0])->c_str()
218 );
219 }
220 else
221 {
222 *sPreContent +=
223 ((std::string *)lPostContent[0])->c_str();
224 }
225 }
226 delete (std::string *)lPostContent[0];
227 lPostContent.deleteAt( 0 );
228 }
229 }
230 else
231 {
232 int nCont = nIndex-1;
233 // If it's above zero we deal with the post-content only
234 if( sReplacementText )
235 {
236 if( lPostContent[nCont] == NULL )
237 {
238 lPostContent.setAt( nCont, new std::string( sReplacementText ) );
239 }
240 else
241 {
242 *((std::string *)lPostContent[nCont]) += sReplacementText;
243 }
244 }
245 if( lPostContent.getSize() > nIndex )
246 {
247 if( lPostContent[nIndex] != NULL )
248 {
249 if( lPostContent[nCont] == NULL )
250 {
251 lPostContent.setAt( nCont, new std::string(
252 ((std::string *)lPostContent[nIndex])->c_str()
253 ) );
254 }
255 else
256 {
257 *((std::string *)lPostContent[nCont]) +=
258 ((std::string *)lPostContent[nIndex])->c_str();
259 }
260 }
261 delete (std::string *)lPostContent[nIndex];
262 lPostContent.deleteAt( nIndex );
263 }
264 }
265
266 XmlNode *xRet = (XmlNode *)lChildren[nIndex];
267 hChildren.del( ((XmlNode *)lChildren[nIndex])->getName() );
268 lChildren.deleteAt( nIndex );
269
270 return xRet;
271}
272
273void XmlNode::replaceNode( int nIndex, XmlNode *pNewNode )
274{
275 if( nIndex < 0 || nIndex >= lChildren.getSize() )
276 return; //TODO: throw an exception
277
278 delete (XmlNode *)lChildren[nIndex];
279 lChildren.setAt( nIndex, pNewNode );
280 pNewNode->pParent = this;
281}
282
283XmlNode *XmlNode::getCopy()
284{
285 XmlNode *pNew = new XmlNode();
286
287 pNew->sName = sName;
288 if( sPreContent )
289 {
290 pNew->sPreContent = new std::string( sPreContent->c_str() );
291 }
292 else
293 {
294 pNew->sPreContent = NULL;
295 }
296 pNew->nCurContent = 0;
297
298 int nSize = lPostContent.getSize();
299 pNew->lPostContent.setSize( nSize );
300 for( int j = 0; j < nSize; j++ )
301 {
302 if( lPostContent[j] )
303 {
304 pNew->lPostContent.setAt(
305 j, new std::string(
306 ((std::string *)lPostContent[j])->c_str()
307 )
308 );
309 }
310 else
311 {
312 pNew->lPostContent.setAt( j, NULL );
313 }
314 }
315
316 nSize = lChildren.getSize();
317 pNew->lChildren.setSize( nSize );
318 for( int j = 0; j < nSize; j++ )
319 {
320 XmlNode *pChild = ((XmlNode *)lChildren[j])->getCopy();
321 pNew->lChildren.setAt( j, pChild );
322 pChild->pParent = pNew;
323 pNew->hChildren.insert( pChild->getName(), pChild );
324 }
325
326 nSize = lPropNames.getSize();
327 pNew->lPropNames.setSize( nSize );
328 pNew->lPropValues.setSize( nSize );
329 for( int j = 0; j < nSize; j++ )
330 {
331 std::string *pProp = new std::string( ((std::string *)lPropNames[j])->c_str() );
332 std::string *pVal = new std::string( ((std::string *)lPropValues[j])->c_str() );
333 pNew->lPropNames.setAt( j, pProp );
334 pNew->lPropValues.setAt( j, pVal );
335 pNew->hProperties.insert( pProp->c_str(), pVal->c_str() );
336 pNew->nCurContent++;
337 }
338
339 return pNew;
340}
341
342void XmlNode::deleteNodeKeepChildren( int nIndex )
343{
344 // This is a tricky one...we need to do some patching to keep things all
345 // even...
346 XmlNode *xRet = (XmlNode *)lChildren[nIndex];
347
348 if( xRet == NULL )
349 {
350 return;
351 }
352 else
353 {
354 if( getContent( nIndex ) )
355 {
356 std::string sBuf( getContent( nIndex ) );
357 sBuf += xRet->getContent( 0 );
358 setContent( sBuf.c_str(), nIndex );
359 }
360 else
361 {
362 setContent( xRet->getContent( 0 ), nIndex );
363 }
364
365 int nSize = xRet->lChildren.getSize();
366 for( int j = 0; j < nSize; j++ )
367 {
368 XmlNode *pCopy = ((XmlNode *)xRet->lChildren[j])->getCopy();
369 pCopy->pParent = this;
370 lChildren.insertBefore( pCopy, nIndex+j );
371
372 if( xRet->lPostContent[j] )
373 {
374 lPostContent.insertBefore(
375 new std::string( ((std::string *)xRet->lPostContent[j])->c_str() ),
376 nIndex+j
377 );
378 }
379 else
380 {
381 lPostContent.insertBefore( NULL, nIndex+j );
382 }
383 }
384
385 if( getContent( nIndex+nSize ) )
386 {
387 //SString sBuf( getContent( nIndex+nSize ) );
388 //sBuf.catfrom( xRet->getContent( nSize ) );
389 //setContent( sBuf, nIndex+nSize );
390 }
391 else
392 {
393 setContent( xRet->getContent( nSize ), nIndex+nSize );
394 }
395
396 deleteNode( nIndex+nSize );
397 }
398}
399
400void XmlNode::replaceNodeWithChildren( int nIndex, XmlNode *pNewNode )
401{
402}
403*/