I'm trying to figure out what the best way to clone rapidjson is. I'm seeing a few good ideas online, which differ greatly.
There's the example Milo gives in his documentation (deep copy milo), which is just like the deep copy example in tutorial.md in rapidjson. However, this is for an oversimplified, one Value json. For large, multi-type, json, iterating would be complicated, and I'm not seeing a good example.
There is newDocument copy which has an example I like, but someone commented parsing is slow, but for a large rapidjson example, iterating over the entire set would take long too. Plus, the <0> or other syntax appear wrong. There is no type given.
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()); }
Apparently there's a DeepCopy patch, but I'm not sure how to use it, or if it's in my version of rapidjson (1.1.0). I haven't had luck using GenericMember yet. We are using DOM. I can't use an unofficial release of rapidjson because the license would be different and it would deviate from mainstream releases of rapidjson.
For libjson, we used to do a shallow copy, like &rhs, but I'm looking for suggestions, and possibly an example of using the DeepCopy patch if it's in 1.1.0.