Add simplereader, simplewriter examples.
Also modify premake to add all projects in example folder.
This commit is contained in:
parent
6225092355
commit
3c8a923439
@ -156,32 +156,10 @@ solution "example"
|
||||
configuration "gmake"
|
||||
buildoptions "-Werror -Wall -Wextra -Weffc++ -Wswitch-default"
|
||||
|
||||
project "condense"
|
||||
kind "ConsoleApp"
|
||||
files "../example/condense/*"
|
||||
setTargetObjDir("../bin")
|
||||
|
||||
project "pretty"
|
||||
kind "ConsoleApp"
|
||||
files "../example/pretty/*"
|
||||
setTargetObjDir("../bin")
|
||||
|
||||
project "prettyauto"
|
||||
kind "ConsoleApp"
|
||||
files "../example/prettyauto/*"
|
||||
setTargetObjDir("../bin")
|
||||
|
||||
project "tutorial"
|
||||
kind "ConsoleApp"
|
||||
files "../example/tutorial/*"
|
||||
setTargetObjDir("../bin")
|
||||
|
||||
project "serialize"
|
||||
kind "ConsoleApp"
|
||||
files "../example/serialize/*"
|
||||
setTargetObjDir("../bin")
|
||||
|
||||
project "simpledom"
|
||||
kind "ConsoleApp"
|
||||
files "../example/simpledom/*"
|
||||
setTargetObjDir("../bin")
|
||||
local examplepaths = os.matchdirs("../example/*")
|
||||
for _, examplepath in ipairs(examplepaths) do
|
||||
project(path.getname(examplepath))
|
||||
kind "ConsoleApp"
|
||||
files(examplepath .. "/*")
|
||||
setTargetObjDir("../bin")
|
||||
end
|
||||
|
32
example/simplereader/simplereader.cpp
Normal file
32
example/simplereader/simplereader.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "rapidjson/reader.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace rapidjson;
|
||||
using namespace std;
|
||||
|
||||
struct MyHandler {
|
||||
bool Null() { cout << "Null()" << endl; return true; }
|
||||
bool Bool(bool b) { cout << "Bool(" << boolalpha << b << ")" << endl; return true; }
|
||||
bool Int(int i) { cout << "Int(" << i << ")" << endl; return true; }
|
||||
bool Uint(unsigned u) { cout << "Uint(" << u << ")" << endl; return true; }
|
||||
bool Int64(int64_t i) { cout << "Int64(" << i << ")" << endl; return true; }
|
||||
bool Uint64(uint64_t u) { cout << "Uint64(" << u << ")" << endl; return true; }
|
||||
bool Double(double d) { cout << "Double(" << d << ")" << endl; return true; }
|
||||
bool String(const char* str, SizeType length, bool copy) {
|
||||
cout << "String(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl;
|
||||
return true;
|
||||
}
|
||||
bool StartObject() { cout << "StartObject()" << endl; return true; }
|
||||
bool EndObject(SizeType memberCount) { cout << "EndObject(" << memberCount << ")" << endl; return true; }
|
||||
bool StartArray() { cout << "StartArray()" << endl; return true; }
|
||||
bool EndArray(SizeType elementCount) { cout << "EndArray(" << elementCount << ")" << endl; return true; }
|
||||
};
|
||||
|
||||
void main() {
|
||||
const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
|
||||
|
||||
MyHandler handler;
|
||||
Reader reader;
|
||||
StringStream ss(json);
|
||||
reader.Parse(ss, handler);
|
||||
}
|
33
example/simplewriter/simplewriter.cpp
Normal file
33
example/simplewriter/simplewriter.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "rapidjson/writer.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace rapidjson;
|
||||
using namespace std;
|
||||
|
||||
void main() {
|
||||
StringBuffer s;
|
||||
Writer<StringBuffer> writer(s);
|
||||
|
||||
writer.StartObject();
|
||||
writer.String("hello");
|
||||
writer.String("world");
|
||||
writer.String("t");
|
||||
writer.Bool(true);
|
||||
writer.String("f");
|
||||
writer.Bool(false);
|
||||
writer.String("n");
|
||||
writer.Null();
|
||||
writer.String("i");
|
||||
writer.Uint(123);
|
||||
writer.String("pi");
|
||||
writer.Double(3.1416);
|
||||
writer.String("a");
|
||||
writer.StartArray();
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
writer.Uint(i);
|
||||
writer.EndArray();
|
||||
writer.EndObject();
|
||||
|
||||
cout << s.GetString() << endl;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user