deep copy and clone
This commit is contained in:
23
tinyxml2.cpp
23
tinyxml2.cpp
@@ -771,6 +771,18 @@ void XMLNode::SetValue( const char* str, bool staticMem )
|
||||
}
|
||||
}
|
||||
|
||||
XMLNode* XMLNode::DeepClone(XMLDocument* document) const
|
||||
{
|
||||
XMLNode* clone = this->ShallowClone(document);
|
||||
if (!clone) return 0;
|
||||
|
||||
for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) {
|
||||
XMLNode* childClone = child->DeepClone(document);
|
||||
TIXMLASSERT(childClone);
|
||||
clone->InsertEndChild(childClone);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
void XMLNode::DeleteChildren()
|
||||
{
|
||||
@@ -2006,6 +2018,17 @@ void XMLDocument::Clear()
|
||||
}
|
||||
|
||||
|
||||
void XMLDocument::DeepCopy(XMLDocument* target)
|
||||
{
|
||||
TIXMLASSERT(target);
|
||||
TIXMLASSERT(target != this);
|
||||
|
||||
target->Clear();
|
||||
for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) {
|
||||
target->InsertEndChild(node->DeepClone(target));
|
||||
}
|
||||
}
|
||||
|
||||
XMLElement* XMLDocument::NewElement( const char* name )
|
||||
{
|
||||
TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
||||
|
||||
Reference in New Issue
Block a user