I\'m making a class and I want to return my class inside a method. My class has a rapidjson::Document
object.
You can see the previous problems here: L
Repository https://github.com/rjeczalik/rapidjson have the DeepCopy patch which might help you copy one document into another.
must use (const) reference as return type(try to store new documents in creator class), you can't copy documents, i.e. can't return by value, since implicitly you try to use disabled copy constructor
I created this method to copy document object and it works fine for me:
static void copyDocument(rapidjson::Document & newDocument, rapidjson::Document & copiedDocument) {
rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
newDocument.Accept(writer);
std::string str = strbuf.GetString();
copiedDocument.Parse<0>(str.c_str());
}
Use the CopyFrom method on a new Document:
rapidjson::Document inDoc; // source document
rapidjson::Document outDoc; // destination document
outDoc.CopyFrom(inDoc, outDoc.GetAllocator());
I tested this approach and changes made to the output document had no effect on the input document. Make sure the CopyFrom method is given the output document's allocator.