diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-05-05 22:12:07 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-05-05 22:12:07 +0100 |
commit | 6b88a6149d0ee9865ed73e36206b720d4e4ee724 (patch) | |
tree | b892e5540f5f36d7d074aee1b8eac6f27b942367 | |
parent | Pointer free (diff) | |
download | libjsonpp-6b88a6149d0ee9865ed73e36206b720d4e4ee724.tar.bz2 libjsonpp-6b88a6149d0ee9865ed73e36206b720d4e4ee724.tar.xz libjsonpp-6b88a6149d0ee9865ed73e36206b720d4e4ee724.zip |
Variant fix
Swap the wrapper class from the variant to the containers because
std::visit needs specialisations on the type which aren't present for
the subclass.
-rw-r--r-- | libjsonpp/jsonpp.h | 27 | ||||
-rw-r--r-- | libjsonpp/serialize.cpp | 2 | ||||
-rw-r--r-- | libjsonpp/testSerialise.cpp | 14 |
3 files changed, 26 insertions, 17 deletions
diff --git a/libjsonpp/jsonpp.h b/libjsonpp/jsonpp.h index d56ca99..1a57389 100644 --- a/libjsonpp/jsonpp.h +++ b/libjsonpp/jsonpp.h @@ -18,18 +18,27 @@ namespace json { typedef double Number; typedef bool Boolean; class Null { }; - class Value; - typedef std::map<std::string, Value> Object; - typedef std::list<Value> Array; - typedef std::variant<Null, String, Number, Object, Array, Boolean> VT; - class Value : public VT { + class Object; + class Array; + typedef std::variant<Null, String, Number, Object, Array, Boolean> Value; + typedef std::map<std::string, Value> M; + class Object : public M { public: - Value() : VT(Null()) { } - - template <class X> - Value(const X & x) : VT(x) { } + using M::M; + }; + typedef std::list<Value> A; + class Array : public A { + public: + using A::A; }; + static_assert(std::is_move_constructible<Value>::value); + static_assert(std::is_nothrow_move_constructible<Object>::value); + static_assert(std::is_nothrow_move_constructible<Array>::value); + static_assert(std::is_move_assignable<Value>::value); + static_assert(std::is_nothrow_move_assignable<Object>::value); + static_assert(std::is_nothrow_move_assignable<Array>::value); + Value parseValue(std::istream &); Value parseValue(std::istream &, const std::string & encoding); Value parseValue(const Glib::ustring & s); diff --git a/libjsonpp/serialize.cpp b/libjsonpp/serialize.cpp index fe55fbd..055d36f 100644 --- a/libjsonpp/serialize.cpp +++ b/libjsonpp/serialize.cpp @@ -17,7 +17,7 @@ namespace json { << std::setfill('0') // for String \uNNNN ; } - void operator()(const VT & v) const { + void operator()(const Value & v) const { std::visit(*this, v); } void operator()(const std::string & str) const { diff --git a/libjsonpp/testSerialise.cpp b/libjsonpp/testSerialise.cpp index 66fc774..04f95ac 100644 --- a/libjsonpp/testSerialise.cpp +++ b/libjsonpp/testSerialise.cpp @@ -98,23 +98,23 @@ BOOST_AUTO_TEST_CASE( serialise_quotes ) BOOST_AUTO_TEST_CASE( serialise_complexObject ) { BOOST_REQUIRE_EQUAL("{\"a\":\"string\",\"b\":null,\"c\":64,\"d\":true,\"e\":{\"suba\":\"suba-val\",\"subb\":\"subb-val\"},\"f\":[true,false,-4.9,\"item\"]}", writeString( - json::Object({ + json::Object { {"a", "string"s}, - {"b", json::Null()}, + {"b", json::Null() }, {"c", 64.0}, {"d", true}, - {"e", json::Object({ + {"e", json::Object { {"suba", "suba-val"s}, {"subb", "subb-val"s} - }) + } }, - {"f", json::Array({ + {"f", json::Array { true, false, -4.9, "item"s - }), + }, } - }))); + })); } |