MCPcopy Create free account
hub / github.com/DFHack/dfhack / ReplaceChild

Method ReplaceChild

depends/tinyxml/tinyxml.cpp:296–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294
295
296TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis )
297{
298 if ( !replaceThis )
299 return 0;
300
301 if ( replaceThis->parent != this )
302 return 0;
303
304 if ( withThis.ToDocument() ) {
305 // A document can never be a child. Thanks to Noam.
306 TiXmlDocument* document = GetDocument();
307 if ( document )
308 document->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
309 return 0;
310 }
311
312 TiXmlNode* node = withThis.Clone();
313 if ( !node )
314 return 0;
315
316 node->next = replaceThis->next;
317 node->prev = replaceThis->prev;
318
319 if ( replaceThis->next )
320 replaceThis->next->prev = node;
321 else
322 lastChild = node;
323
324 if ( replaceThis->prev )
325 replaceThis->prev->next = node;
326 else
327 firstChild = node;
328
329 delete replaceThis;
330 node->parent = this;
331 return node;
332}
333
334
335bool TiXmlNode::RemoveChild( TiXmlNode* removeThis )

Callers

nothing calls this directly

Calls 3

SetErrorMethod · 0.80
CloneMethod · 0.80
ToDocumentMethod · 0.45

Tested by

no test coverage detected