Update sortkeys.cpp
This commit is contained in:
parent
1892013216
commit
f595f8a6a5
@ -8,59 +8,52 @@
|
|||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void printIt(const Value &doc)
|
static void printIt(const Value &doc) {
|
||||||
{
|
|
||||||
char writeBuffer[65536];
|
char writeBuffer[65536];
|
||||||
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
||||||
PrettyWriter<FileWriteStream> writer(os);
|
PrettyWriter<FileWriteStream> writer(os);
|
||||||
doc.Accept(writer);
|
doc.Accept(writer);
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NameComparator
|
struct NameComparator {
|
||||||
{
|
bool operator()(
|
||||||
bool
|
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &lhs,
|
||||||
operator()(const GenericMember<UTF8<>, MemoryPoolAllocator<>> &lhs,
|
|
||||||
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const
|
const GenericMember<UTF8<>, MemoryPoolAllocator<> > &rhs) const
|
||||||
{
|
{
|
||||||
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
|
return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main() {
|
||||||
{
|
|
||||||
Document d = Document(kObjectType);
|
Document d = Document(kObjectType);
|
||||||
Document::AllocatorType &allocator = d.GetAllocator();
|
Document::AllocatorType &allocator = d.GetAllocator();
|
||||||
|
|
||||||
d.AddMember("zeta", Value().SetBool(false), allocator);
|
d.AddMember("zeta", Value().SetBool(false), allocator);
|
||||||
d.AddMember("gama", Value().SetString("test string", allocator), allocator);
|
d.AddMember("gama", Value().SetString("test string", allocator), allocator);
|
||||||
d.AddMember("delta", Value().SetInt(123), allocator);
|
d.AddMember("delta", Value().SetInt(123), allocator);
|
||||||
|
d.AddMember("alpha", Value(kArrayType).Move(), allocator);
|
||||||
Value a(kArrayType);
|
|
||||||
d.AddMember("alpha", a, allocator);
|
|
||||||
|
|
||||||
printIt(d);
|
printIt(d);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
{
|
{
|
||||||
"zeta": false,
|
"zeta": false,
|
||||||
"gama": "test string",
|
"gama": "test string",
|
||||||
"delta": 123,
|
"delta": 123,
|
||||||
"alpha": []
|
"alpha": []
|
||||||
}
|
}
|
||||||
**/
|
*/
|
||||||
|
|
||||||
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
|
std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator());
|
||||||
|
|
||||||
printIt(d);
|
printIt(d);
|
||||||
/**
|
|
||||||
|
/*
|
||||||
{
|
{
|
||||||
"alpha": [],
|
"alpha": [],
|
||||||
"delta": 123,
|
"delta": 123,
|
||||||
"gama": "test string",
|
"gama": "test string",
|
||||||
"zeta": false
|
"zeta": false
|
||||||
}
|
}
|
||||||
**/
|
*/
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user