Skip to content

Commit

Permalink
Add named constructor xml::Document::clone
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 10, 2017
1 parent b67e44c commit b4b634b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions libs/xmlutil/Document.cpp
Expand Up @@ -42,6 +42,18 @@ Document Document::create()
return Document(doc);
}

Document Document::clone(const Document& source)
{
if (source._xmlDoc == nullptr)
{
// Nothing to clone, create an empty doc
return Document(nullptr);
}

// Create a deep copy of the other doc
return Document(xmlCopyDoc(source._xmlDoc, 1));
}

void Document::addTopLevelNode(const std::string& name)
{
std::lock_guard<std::mutex> lock(_lock);
Expand Down
5 changes: 4 additions & 1 deletion libs/xmlutil/Document.h
Expand Up @@ -37,7 +37,7 @@ class Document
// Use the isValid() method to check if the load was successful.
Document(const std::string& filename);

// Copy constructor
// Copy constructor (note: does not create an actual copy of the internal xmlDoc)
Document(const Document& other);

// Destructor, frees the xmlDocPtr
Expand All @@ -46,6 +46,9 @@ class Document
// Creates a new xml::Document object (allocates a new xmlDoc)
static Document create();

// Creates a deep copy of the given Document
static Document clone(const Document& source);

// Add a new toplevel node with the given name to this Document
void addTopLevelNode(const std::string& name);

Expand Down

0 comments on commit b4b634b

Please sign in to comment.