summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-05-06 12:22:14 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-05-06 12:22:14 +0100
commit8eb6e8b74ef8a00cb611d1f6fbf1d1400be7f9a1 (patch)
treea9c40749b4e1310e7ad9809c6933882230ff99a3
parentC++17 and Ice 3.7 (diff)
downloadproject2-1.3.1.tar.bz2
project2-1.3.1.tar.xz
project2-1.3.1.zip
C++17 JSONproject2-1.3.1
Updates to match the new pure C++17 JSON interface
-rw-r--r--project2/json/conversion.h2
-rw-r--r--project2/json/presenter.cpp21
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);
}
}