add JSON output for shock_groups

issue#70
Houtan Bastani 2019-04-12 14:16:42 +02:00
parent 1edc9af764
commit 3947903f33
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
2 changed files with 36 additions and 0 deletions

View File

@ -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 << "}}";
}

View File

@ -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