Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sortkeys.cpp
Go to the documentation of this file.
4
5#include <algorithm>
6#include <iostream>
7
8using namespace rapidjson;
9using namespace std;
10
11static void printIt(const Value &doc) {
12 char writeBuffer[65536];
13 FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
15 doc.Accept(writer);
16 cout << endl;
17}
18
20 bool operator()(const Value::Member &lhs, const Value::Member &rhs) const {
21 return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
22 }
23};
24
25int main() {
27 Document::AllocatorType &allocator = d.GetAllocator();
28
29 d.AddMember("zeta", Value().SetBool(false), allocator);
30 d.AddMember("gama", Value().SetString("test string", allocator), allocator);
31 d.AddMember("delta", Value().SetInt(123), allocator);
32 d.AddMember("alpha", Value(kArrayType).Move(), allocator);
33
34 printIt(d);
35
36/*
37{
38 "zeta": false,
39 "gama": "test string",
40 "delta": 123,
41 "alpha": []
42}
43*/
44
45// C++11 supports std::move() of Value so it always have no problem for std::sort().
46// Some C++03 implementations of std::sort() requires copy constructor which causes compilation error.
47// Needs a sorting function only depends on std::swap() instead.
48#if __cplusplus >= 201103L || !defined(__GLIBCXX__)
49 std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
50#endif
51
52 printIt(d);
53
54/*
55{
56 "alpha": [],
57 "delta": 123,
58 "gama": "test string",
59 "zeta": false
60}
61*/
62}
Wrapper of C file stream for output using fwrite().
Default memory allocator used by the parser and DOM.
Definition allocators.h:115
Writer with indentation and spacing.
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition document.h:2110
os_t os
main RapidJSON namespace
Definition name.hpp:106
@ kObjectType
object
Definition rapidjson.h:648
@ kArrayType
array
Definition rapidjson.h:649
int main()
Definition sortkeys.cpp:25
Name-value pair in a JSON object value.
Definition document.h:66
GenericValue< Encoding, Allocator > name
name of member (must be a string)
Definition document.h:67
bool operator()(const Value::Member &lhs, const Value::Member &rhs) const
Definition sortkeys.cpp:20
CK_ULONG d