From 3947903f3352a6787deeb5e47e7ebe17a9615109 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 12 Apr 2019 14:16:42 +0200 Subject: [PATCH] add JSON output for shock_groups --- src/Shocks.cc | 35 +++++++++++++++++++++++++++++++++++ src/Shocks.hh | 1 + 2 files changed, 36 insertions(+) diff --git a/src/Shocks.cc b/src/Shocks.cc index a07b3960..3225c687 100644 --- a/src/Shocks.cc +++ b/src/Shocks.cc @@ -635,3 +635,38 @@ ShockGroupsStatement::writeOutput(ostream &output, const string &basename, bool } } } + +void +ShockGroupsStatement::writeJsonOutput(ostream &output) const +{ + output << R"({"statementName": "shock_groups", "name": ")" << name << R"(", "groups": {)"; + bool unique_label = true; + bool printed_group = false; + for (auto it = shock_groups.begin(); it != shock_groups.end(); it++, unique_label = true) + { + for (auto it1 = it+1; it1 != shock_groups.end(); it1++) + if (it->name == it1->name) + { + unique_label = false; + break; + } + + if (unique_label) + { + if (printed_group) + output << ", "; + else + printed_group = true; + output << R"("group_name": ")" << it->name << R"(",)" + << R"("shocks": [)"; + for (auto it1 = it->list.begin(); it1 != it->list.end(); it1++) + { + if (it1 != it->list.begin()) + output << ", "; + output << R"(")" << *it1 << R"(")"; + } + output << "]"; + } + } + output << "}}"; +} diff --git a/src/Shocks.hh b/src/Shocks.hh index c1879ad1..ad420e30 100644 --- a/src/Shocks.hh +++ b/src/Shocks.hh @@ -163,6 +163,7 @@ private: public: ShockGroupsStatement(group_t shock_groups_arg, string name_arg); void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override; + void writeJsonOutput(ostream &output) const override; }; #endif