deep copy and clone

This commit is contained in:
Lee Thomason
2017-06-01 18:09:43 -07:00
parent 1f5ab7cd0b
commit 7085f00e40
3 changed files with 129 additions and 2 deletions

View File

@@ -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() );