Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
c9060b4a
Commit
c9060b4a
authored
Dec 04, 2018
by
seky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added example for sorting keys
parent
30d92a63
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
CMakeLists.txt
example/CMakeLists.txt
+1
-0
sortkeys.cpp
example/sortkeys/sortkeys.cpp
+70
-0
No files found.
example/CMakeLists.txt
View file @
c9060b4a
...
...
@@ -21,6 +21,7 @@ set(EXAMPLES
simplereader
simplepullreader
simplewriter
sortkeys
tutorial
)
include_directories
(
"../include/"
)
...
...
example/sortkeys/sortkeys.cpp
0 → 100644
View file @
c9060b4a
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/document.h"
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <algorithm>
#include <iostream>
using
namespace
rapidjson
;
using
namespace
std
;
void
printIt
(
Document
&
doc
)
{
string
output
;
StringBuffer
buffer
;
PrettyWriter
<
StringBuffer
>
writer
(
buffer
);
doc
.
Accept
(
writer
);
output
=
buffer
.
GetString
();
cout
<<
output
<<
endl
;
}
struct
ValueNameComparator
{
bool
operator
()(
const
GenericMember
<
UTF8
<>
,
MemoryPoolAllocator
<>>
&
lhs
,
const
GenericMember
<
UTF8
<>
,
MemoryPoolAllocator
<>>
&
rhs
)
const
{
string
lhss
=
string
(
lhs
.
name
.
GetString
());
string
rhss
=
string
(
rhs
.
name
.
GetString
());
return
lhss
<
rhss
;
}
};
int
main
()
{
Document
d
=
Document
(
kObjectType
);
Document
::
AllocatorType
&
allocator
=
d
.
GetAllocator
();
d
.
AddMember
(
"zeta"
,
Value
().
SetBool
(
false
),
allocator
);
d
.
AddMember
(
"gama"
,
Value
().
SetString
(
"test string"
,
allocator
),
allocator
);
d
.
AddMember
(
"delta"
,
Value
().
SetInt
(
123
),
allocator
);
Value
a
(
kArrayType
);
d
.
AddMember
(
"alpha"
,
a
,
allocator
);
printIt
(
d
);
/**
{
"zeta": false,
"gama": "test string",
"delta": 123,
"alpha": []
}
**/
std
::
sort
(
d
.
MemberBegin
(),
d
.
MemberEnd
(),
ValueNameComparator
());
printIt
(
d
);
/**
{
"alpha": [],
"delta": 123,
"gama": "test string",
"zeta": false
}
**/
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment