fix a compatibility issue with doxygen

This commit is contained in:
Wenhao Liu 2015-11-28 22:40:43 +08:00
parent 9d47c62337
commit fe89676a9e

View File

@ -106,59 +106,59 @@
Call one of the `SetXXX()` methods - they call destructor which deallocates DOM data: Call one of the `SetXXX()` methods - they call destructor which deallocates DOM data:
``` ~~~~~~~~~~cpp
Document d; Document d;
... ...
d.SetObject(); // clear and minimize d.SetObject(); // clear and minimize
``` ~~~~~~~~~~
Alternatively, use equivalent of the [C++ swap with temporary idiom](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize): Alternatively, use equivalent of the [C++ swap with temporary idiom](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize):
``` ~~~~~~~~~~cpp
Value(kObjectType).Swap(d); Value(kObjectType).Swap(d);
``` ~~~~~~~~~~
or equivalent, but sightly longer to type: or equivalent, but sightly longer to type:
``` ~~~~~~~~~~cpp
d.Swap(Value(kObjectType).Move()); d.Swap(Value(kObjectType).Move());
``` ~~~~~~~~~~
9. How to insert a document node into another document? 9. How to insert a document node into another document?
Let's take the following two DOM trees represented as JSON documents: Let's take the following two DOM trees represented as JSON documents:
``` ~~~~~~~~~~cpp
Document person; Document person;
person.Parse("{\"person\":{\"name\":{\"first\":\"Adam\",\"last\":\"Thomas\"}}}"); person.Parse("{\"person\":{\"name\":{\"first\":\"Adam\",\"last\":\"Thomas\"}}}");
Document address; Document address;
address.Parse("{\"address\":{\"city\":\"Moscow\",\"street\":\"Quiet\"}}"); address.Parse("{\"address\":{\"city\":\"Moscow\",\"street\":\"Quiet\"}}");
``` ~~~~~~~~~~
Let's assume we want to merge them in such way that the whole `address` document becomes a node of the `person`: Let's assume we want to merge them in such way that the whole `address` document becomes a node of the `person`:
``` ~~~~~~~~~~js
{ "person": { { "person": {
"name": { "first": "Adam", "last": "Thomas" }, "name": { "first": "Adam", "last": "Thomas" },
"address": { "city": "Moscow", "street": "Quiet" } "address": { "city": "Moscow", "street": "Quiet" }
} }
} }
``` ~~~~~~~~~~
The most important requirement to take care of document and value life-cycle as well as consistent memory managent using the right allocator during the value transfer. The most important requirement to take care of document and value life-cycle as well as consistent memory managent using the right allocator during the value transfer.
Simple yet most efficient way to achieve that is to modify the `address` definition above to initialize it with allocator of the `person` document, then we just add the root nenber of the value: Simple yet most efficient way to achieve that is to modify the `address` definition above to initialize it with allocator of the `person` document, then we just add the root nenber of the value:
``` ~~~~~~~~~~cpp
Documnet address(person.GetAllocator()); Documnet address(person.GetAllocator());
... ...
person["person"].AddMember("address", address["address"], person.GetAllocator()); person["person"].AddMember("address", address["address"], person.GetAllocator());
``` ~~~~~~~~~~
Alternatively, if we don't want to explicitly refer to the root value of `address` by name, we can refer to it via iterator: Alternatively, if we don't want to explicitly refer to the root value of `address` by name, we can refer to it via iterator:
``` ~~~~~~~~~~cpp
auto addressRoot = address.MemberBegin(); auto addressRoot = address.MemberBegin();
person["person"].AddMember(addressRoot->name, addressRoot->value, person.GetAllocator()); person["person"].AddMember(addressRoot->name, addressRoot->value, person.GetAllocator());
``` ~~~~~~~~~~
Second way is to deep-clone the value from the address document: Second way is to deep-clone the value from the address document:
``` ~~~~~~~~~~cpp
Value addressValue = Value(address["address"], person.GetAllocator()); Value addressValue = Value(address["address"], person.GetAllocator());
person["person"].AddMember("address", addressValue, person.GetAllocator()); person["person"].AddMember("address", addressValue, person.GetAllocator());
``` ~~~~~~~~~~
## Document/Value (DOM) ## Document/Value (DOM)