From 8eb6e8b74ef8a00cb611d1f6fbf1d1400be7f9a1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 May 2018 12:22:14 +0100 Subject: C++17 JSON Updates to match the new pure C++17 JSON interface --- project2/json/conversion.h | 2 +- project2/json/presenter.cpp | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/project2/json/conversion.h b/project2/json/conversion.h index 0e9d56d..3bc2412 100644 --- a/project2/json/conversion.h +++ b/project2/json/conversion.h @@ -19,7 +19,7 @@ class Project2ToJson : public boost::static_visitor { } }; -class JsonToProject2 : public boost::static_visitor { +class JsonToProject2 { public: VariableType operator()(const json::Object &) const; VariableType operator()(const json::Array &) const; diff --git a/project2/json/presenter.cpp b/project2/json/presenter.cpp index 7f20f8e..4a5713a 100644 --- a/project2/json/presenter.cpp +++ b/project2/json/presenter.cpp @@ -47,21 +47,20 @@ JsonPresenter::addNamedValue(const Glib::ustring & name, const VariableType & va void JsonPresenter::addValueToObject(const Glib::ustring & name, const VariableType & value) const { - (*curRowSet.top())[name.collate_key()] = json::ValuePtr(new json::Value(boost::apply_visitor(Project2ToJson(), value))); + (*curRowSet.top())[name.collate_key()] = boost::apply_visitor(Project2ToJson(), value); } void JsonPresenter::addValueToArray(const Glib::ustring &, const VariableType & value) const { - curRowArray.top()->push_back(json::ValuePtr(new json::Value(boost::apply_visitor(Project2ToJson(), value)))); + curRowArray.top()->push_back(boost::apply_visitor(Project2ToJson(), value)); } void JsonPresenter::addNewRow(const Glib::ustring &) const { - json::Value * v = new json::Value(json::Object()); - curRowSet.push(boost::get(v)); - curRowArray.top()->push_back(json::ValuePtr(v)); + auto v = &curRowArray.top()->emplace_back(); + curRowSet.push(std::get_if(v)); vaStack.push(&JsonPresenter::addValueToObject); } @@ -75,9 +74,8 @@ JsonPresenter::finishRow() const void JsonPresenter::addNewRowSet(const Glib::ustring & name) const { - json::Value * v = new json::Value(json::Object()); - (*curRowSet.top())[name.collate_key()] = json::ValuePtr(v); - curRowSet.push(boost::get(v)); + auto v = &((*curRowSet.top())[name.collate_key()] = json::Object()); + curRowSet.push(std::get_if(v)); } void @@ -95,9 +93,8 @@ JsonPresenter::finishRowSet() const void JsonPresenter::addNewArray(const Glib::ustring & name, bool) const { - json::Value * v = new json::Value(json::Array()); - curRowArray.push(boost::get(v)); - (*curRowSet.top())[name.collate_key()] = json::ValuePtr(v); + auto v = &((*curRowSet.top())[name.collate_key()] = json::Array()); + curRowArray.push(std::get_if(v)); vaStack.push(&JsonPresenter::addValueToArray); } @@ -137,7 +134,7 @@ JsonPresenter::writeTo(std::ostream & o, const std::string & encoding, ExecConte serializeValue(object, o, encoding); } else { - serializeValue(*object[returnObject(ec).as().collate_key()], o, encoding); + serializeValue(object[returnObject(ec).as().collate_key()], o, encoding); } } -- cgit v1.2.3