|
8 | 8 | using namespace rapidjson;
|
9 | 9 | using namespace std;
|
10 | 10 |
|
11 |
| -void printIt(const Value &doc) |
12 |
| -{ |
| 11 | +static void printIt(const Value &doc) { |
13 | 12 | char writeBuffer[65536];
|
14 | 13 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
15 | 14 | PrettyWriter<FileWriteStream> writer(os);
|
16 | 15 | doc.Accept(writer);
|
17 |
| - |
18 | 16 | cout << endl;
|
19 | 17 | }
|
20 | 18 |
|
21 |
| -struct NameComparator |
22 |
| -{ |
23 |
| - bool |
24 |
| - operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs, |
25 |
| - const GenericMember<UTF8<>, MemoryPoolAllocator<>> &rhs) const |
| 19 | +struct NameComparator { |
| 20 | + bool operator()( |
| 21 | + const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs, |
| 22 | + const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const |
26 | 23 | {
|
27 | 24 | return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
|
28 | 25 | }
|
29 | 26 | };
|
30 | 27 |
|
31 |
| -int main() |
32 |
| -{ |
| 28 | +int main() { |
33 | 29 | Document d = Document(kObjectType);
|
34 | 30 | Document::AllocatorType &allocator = d.GetAllocator();
|
35 | 31 |
|
36 | 32 | d.AddMember("zeta", Value().SetBool(false), allocator);
|
37 | 33 | d.AddMember("gama", Value().SetString("test string", allocator), allocator);
|
38 | 34 | d.AddMember("delta", Value().SetInt(123), allocator);
|
39 |
| - |
40 |
| - Value a(kArrayType); |
41 |
| - d.AddMember("alpha", a, allocator); |
| 35 | + d.AddMember("alpha", Value(kArrayType).Move(), allocator); |
42 | 36 |
|
43 | 37 | printIt(d);
|
44 | 38 |
|
45 |
| - /** |
| 39 | +/* |
46 | 40 | {
|
47 | 41 | "zeta": false,
|
48 | 42 | "gama": "test string",
|
49 | 43 | "delta": 123,
|
50 | 44 | "alpha": []
|
51 | 45 | }
|
52 |
| -**/ |
| 46 | +*/ |
53 | 47 |
|
54 | 48 | std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
|
55 |
| - |
56 | 49 | printIt(d);
|
57 |
| - /** |
| 50 | + |
| 51 | +/* |
58 | 52 | {
|
59 | 53 | "alpha": [],
|
60 | 54 | "delta": 123,
|
61 | 55 | "gama": "test string",
|
62 | 56 | "zeta": false
|
63 | 57 | }
|
64 |
| -**/ |
65 |
| - return 0; |
| 58 | +*/ |
66 | 59 | }
|
0 commit comments