Skip to content

Commit

Permalink
Correct formatting of FAQ 8 and 9
Browse files Browse the repository at this point in the history
  • Loading branch information
mloskot committed Jul 2, 2015
1 parent 50660c0 commit 5ac04cb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,30 @@

8. How to clear-and-minimize a document or value?

* 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:

```
Document d;
...
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):
```
d.Swap(Value(kObjectType).Move())
```

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:
```
Document person;
person.Parse("{\"person\":{\"name\":{\"first\":\"Adam\",\"last\":\"Thomas\"}}}");
Document address;
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`:
```
{ "person": {
"name": { "first": "Adam", "last": "Thomas" },
Expand All @@ -136,9 +136,9 @@ Let's assume we want to merge them in such way that the whole `address` document
}
```

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:
```
Documnet address(person.GetAllocator());
...
Expand All @@ -150,7 +150,7 @@ Alternatively, if we don't want to explicitly refer to the root value of `addres
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:
```
Value addressValue = Value(address["address"], person.GetAllocator());
person["person"].AddMember("address", addressValue, person.GetAllocator());
Expand Down

0 comments on commit 5ac04cb

Please sign in to comment.