Skip to content
Snippets Groups Projects
Verified Commit 5b50c102 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Simplify OptionsList::writeJsonOutput()

parent 29c683c6
Branches
Tags
No related merge requests found
...@@ -246,144 +246,94 @@ OptionsList::writeJsonOutput(ostream &output) const ...@@ -246,144 +246,94 @@ OptionsList::writeJsonOutput(ostream &output) const
if (getNumberOfOptions() == 0) if (getNumberOfOptions() == 0)
return; return;
bool opt_written{false};
output << R"("options": {)"; output << R"("options": {)";
for (auto it = num_options.begin(); for (const auto &[name, val] : num_options)
it != num_options.end();) {
{ if (opt_written)
output << R"(")"<< it->first << R"(": )" << it->second;
++it;
if (it != num_options.end()
|| !(paired_num_options.empty()
&& string_options.empty()
&& date_options.empty()
&& symbol_list_options.empty()
&& vector_int_options.empty()
&& vector_str_options.empty()
&& vector_cellstr_options.empty()))
output << ", "; output << ", ";
output << R"(")" << name << R"(": )" << val;
opt_written = true;
} }
for (auto it = paired_num_options.begin(); for (const auto &[name, vals] : paired_num_options)
it != paired_num_options.end();)
{ {
output << R"(")"<< it->first << R"(": [)" << it->second.first << ", " << it->second.second << "]"; if (opt_written)
++it;
if (it != paired_num_options.end()
|| !(string_options.empty()
&& date_options.empty()
&& symbol_list_options.empty()
&& vector_int_options.empty()
&& vector_str_options.empty()
&& vector_cellstr_options.empty()))
output << ", "; output << ", ";
output << R"(")" << name << R"(": [)" << vals.first << ", " << vals.second << "]";
opt_written = true;
} }
for (auto it = string_options.begin(); for (const auto &[name, val] : string_options)
it != string_options.end();)
{ {
output << R"(")"<< it->first << R"(": ")" << it->second << R"(")"; if (opt_written)
++it;
if (it != string_options.end()
|| !(date_options.empty()
&& symbol_list_options.empty()
&& vector_int_options.empty()
&& vector_str_options.empty()
&& vector_cellstr_options.empty()))
output << ", "; output << ", ";
output << R"(")" << name << R"(": ")" << val << R"(")";
opt_written = true;
} }
for (auto it = date_options.begin(); for (const auto &[name, val] : date_options)
it != date_options.end();)
{ {
output << R"(")"<< it->first << R"(": ")" << it->second << R"(")"; if (opt_written)
++it;
if (it != date_options.end()
|| !(symbol_list_options.empty()
&& vector_int_options.empty()
&& vector_str_options.empty()
&& vector_cellstr_options.empty()))
output << ", "; output << ", ";
output << R"(")" << name << R"(": ")" << val << R"(")";
opt_written = true;
} }
for (auto it = symbol_list_options.begin(); for (const auto &[name, vals] : symbol_list_options)
it != symbol_list_options.end();)
{ {
output << R"(")"<< it->first << R"(": {)"; if (opt_written)
it->second.writeJsonOutput(output);
output << "}";
++it;
if (it != symbol_list_options.end()
|| !(vector_int_options.empty()
&& vector_str_options.empty()
&& vector_cellstr_options.empty()))
output << ", "; output << ", ";
output << R"(")" << name << R"(": {)";
vals.writeJsonOutput(output);
output << "}";
opt_written = true;
} }
for (auto it = vector_int_options.begin(); for (const auto &[name, vals] : vector_int_options)
it != vector_int_options.end();)
{
output << R"(")"<< it->first << R"(": [)";
if (it->second.size() > 1)
{ {
for (auto viit = it->second.begin(); if (opt_written)
viit != it->second.end();) output << ", ";
output << R"(")" << name << R"(": [)";
for (auto it = vals.begin(); it != vals.end(); ++it)
{ {
output << *viit; if (it != vals.begin())
++viit;
if (viit != it->second.end())
output << ", "; output << ", ";
output << *it;
} }
}
else
output << it->second.front() << endl;
output << "]"; output << "]";
++it; opt_written = true;
if (it != vector_int_options.end()
|| !(vector_str_options.empty()
&& vector_cellstr_options.empty()))
output << ", ";
} }
for (auto it = vector_str_options.begin(); for (const auto &[name, vals] : vector_str_options)
it != vector_str_options.end();)
{
output << R"(")"<< it->first << R"(": [)";
if (it->second.size() > 1)
{ {
for (auto viit = it->second.begin(); if (opt_written)
viit != it->second.end();) output << ", ";
output << R"(")" << name << R"(": [)";
for (auto it = vals.begin(); it != vals.end(); ++it)
{ {
output << R"(")" << *viit << R"(")"; if (it != vals.begin())
++viit;
if (viit != it->second.end())
output << ", "; output << ", ";
output << R"(")" << *it << R"(")";
} }
}
else
output << it->second.front() << endl;
output << "]"; output << "]";
++it; opt_written = true;
if (it != vector_str_options.end()
|| !(vector_cellstr_options.empty()))
output << ", ";
} }
for (auto it = vector_cellstr_options.begin(); for (const auto &[name, vals] : vector_cellstr_options)
it != vector_cellstr_options.end();)
{ {
output << R"(")"<< it->first << R"(": [)"; if (opt_written)
for (auto viit = it->second.begin(); output << ", ";
viit != it->second.end();) output << R"(")" << name << R"(": [)";
for (auto it = vals.begin(); it != vals.end(); ++it)
{ {
output << R"(")" << *viit << R"(")"; if (it != vals.begin())
++viit;
if (viit != it->second.end())
output << ", "; output << ", ";
output << R"(")" << *it << R"(")";
} }
output << "]"; output << "]";
++it; opt_written = true;
if (it != vector_cellstr_options.end())
output << ", ";
} }
output << "}"; output << "}";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment