diff options
-rw-r--r-- | project2/json/conversion.h | 2 | ||||
-rw-r--r-- | 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<json::Value> { } }; -class JsonToProject2 : public boost::static_visitor<VariableType> { +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<json::Object>(v)); - curRowArray.top()->push_back(json::ValuePtr(v)); + auto v = &curRowArray.top()->emplace_back(); + curRowSet.push(std::get_if<json::Object>(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<json::Object>(v)); + auto v = &((*curRowSet.top())[name.collate_key()] = json::Object()); + curRowSet.push(std::get_if<json::Object>(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<json::Array>(v)); - (*curRowSet.top())[name.collate_key()] = json::ValuePtr(v); + auto v = &((*curRowSet.top())[name.collate_key()] = json::Array()); + curRowArray.push(std::get_if<json::Array>(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<Glib::ustring>().collate_key()], o, encoding); + serializeValue(object[returnObject(ec).as<Glib::ustring>().collate_key()], o, encoding); } } |