diff --git a/build/premake4.lua b/build/premake4.lua index 0b5dbb1..4f7d77f 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -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 diff --git a/example/simplereader/simplereader.cpp b/example/simplereader/simplereader.cpp new file mode 100644 index 0000000..70df6ba --- /dev/null +++ b/example/simplereader/simplereader.cpp @@ -0,0 +1,32 @@ +#include "rapidjson/reader.h" +#include + +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); +} diff --git a/example/simplewriter/simplewriter.cpp b/example/simplewriter/simplewriter.cpp new file mode 100644 index 0000000..98da2cb --- /dev/null +++ b/example/simplewriter/simplewriter.cpp @@ -0,0 +1,33 @@ +#include "rapidjson/writer.h" +#include "rapidjson/stringbuffer.h" +#include + +using namespace rapidjson; +using namespace std; + +void main() { + StringBuffer s; + Writer 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; +}