From 9a8084aa6896f2aeac0fc83bb76d375ba35805cc Mon Sep 17 00:00:00 2001 From: 5cript Date: Fri, 10 Jul 2015 22:38:59 +0200 Subject: [PATCH] Fixed readme on the release 1.1 branch --- README.md | 58 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ed41749..74dca02 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,18 @@ # SimpleJSON A JSON stringifier / parser that uses boost fusion introspection methods for automagic struct <-> JSON conversion +INFO: The library changed from version 1.0 to 1.1 so that it breaks working code. + All functions now receive a stream parameter and return this passed stream. + This is far more convenient and faster too. Its "the C++ style". Sorry for inconvenience, but + this is certainly a step forward. + This library is not fine tuned for speed. -The slowest part should be the boost/property_tree library used for parsing JSON. Dependencies: > boost/property_tree
-> boost/fusion +> boost/fusion
+> boost/mpl
+> boost/phoenix
Code example: ```C++ @@ -19,13 +25,14 @@ Code example: #include #include +#include struct ConfigContent : public JSON::FusionStruct , public JSON::ParsableStruct { - int id; - std::string libPath; - std::vector someArray; + int id; + std::string libPath; + std::vector someContainer; }; BOOST_FUSION_ADAPT_STRUCT @@ -33,31 +40,44 @@ BOOST_FUSION_ADAPT_STRUCT ConfigContent, (int, id) (std::string, libPath) - (std::vector , someArray) + (std::vector , someContainer) ) -ConfigContent parse(std::string const& json) +ConfigContent parse(std::istream& json) { - ConfigContent cc; - auto tree = JSON::parse_json(json); - JSON::js_parse(cc, "config_content", tree); - return cc; + ConfigContent cc; + auto tree = JSON::parse_json(json); + JSON::parse(cc, "config_content", tree); + return cc; } -std::string stringify(ConfigContent const& cc) +std::ostream& stringify(std::ostream& stream, ConfigContent const& cc) { - return std::string("{\"config_content\":") + JSON::js_try_stringify("config_content", cc) + "}"; + stream << "{"; + JSON::try_stringify(stream, "config_content", cc, JSON::ProduceNamedOutput); + stream << "}"; + return stream; } int main() { - std::string str; - ConfigContent cc; - cc.id = 2; + ConfigContent cc; + cc.id = 2; + cc.libPath = "./somewhere"; + cc.someContainer = {"Hello", "World"}; + + std::stringstream sstr; + stringify(sstr, cc); + auto unnecessarilyComplexCopy = parse(sstr); - str = stringify(cc); - auto unnecessarilyComplexCopy = parse(str); + ///////////////////////////////////////////////////////////////////////// + // Lets check if we got what we set + ///////////////////////////////////////////////////////////////////////// - // assert unnecessarilyComplexCopy == cc + std::cout << sstr.str() << "\n\n"; + std::cout << unnecessarilyComplexCopy.id << "\n"; + std::cout << unnecessarilyComplexCopy.libPath << "\n"; + for (auto const& i : unnecessarilyComplexCopy.someContainer) + std::cout << i << "\n"; } ```