Simplify OptionsList::writeJsonOutput()
parent
29c683c6ad
commit
5b50c10229
156
src/Statement.cc
156
src/Statement.cc
|
@ -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();)
|
|
||||||
{
|
{
|
||||||
output << R"(")"<< it->first << R"(": )" << it->second;
|
if (opt_written)
|
||||||
++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 << ", ";
|
||||||
|
output << R"(")" << name << R"(": {)";
|
||||||
|
vals.writeJsonOutput(output);
|
||||||
output << "}";
|
output << "}";
|
||||||
++it;
|
opt_written = true;
|
||||||
if (it != symbol_list_options.end()
|
|
||||||
|| !(vector_int_options.empty()
|
|
||||||
&& vector_str_options.empty()
|
|
||||||
&& vector_cellstr_options.empty()))
|
|
||||||
output << ", ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (opt_written)
|
||||||
if (it->second.size() > 1)
|
output << ", ";
|
||||||
|
output << R"(")" << name << R"(": [)";
|
||||||
|
for (auto it = vals.begin(); it != vals.end(); ++it)
|
||||||
{
|
{
|
||||||
for (auto viit = it->second.begin();
|
if (it != vals.begin())
|
||||||
viit != it->second.end();)
|
output << ", ";
|
||||||
{
|
output << *it;
|
||||||
output << *viit;
|
|
||||||
++viit;
|
|
||||||
if (viit != it->second.end())
|
|
||||||
output << ", ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 (opt_written)
|
||||||
if (it->second.size() > 1)
|
output << ", ";
|
||||||
|
output << R"(")" << name << R"(": [)";
|
||||||
|
for (auto it = vals.begin(); it != vals.end(); ++it)
|
||||||
{
|
{
|
||||||
for (auto viit = it->second.begin();
|
if (it != vals.begin())
|
||||||
viit != it->second.end();)
|
output << ", ";
|
||||||
{
|
output << R"(")" << *it << R"(")";
|
||||||
output << R"(")" << *viit << R"(")";
|
|
||||||
++viit;
|
|
||||||
if (viit != it->second.end())
|
|
||||||
output << ", ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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();
|
|
||||||
viit != it->second.end();)
|
|
||||||
{
|
|
||||||
output << R"(")" << *viit << R"(")";
|
|
||||||
++viit;
|
|
||||||
if (viit != it->second.end())
|
|
||||||
output << ", ";
|
|
||||||
}
|
|
||||||
output << "]";
|
|
||||||
++it;
|
|
||||||
if (it != vector_cellstr_options.end())
|
|
||||||
output << ", ";
|
output << ", ";
|
||||||
|
output << R"(")" << name << R"(": [)";
|
||||||
|
for (auto it = vals.begin(); it != vals.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it != vals.begin())
|
||||||
|
output << ", ";
|
||||||
|
output << R"(")" << *it << R"(")";
|
||||||
|
}
|
||||||
|
output << "]";
|
||||||
|
opt_written = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
output << "}";
|
output << "}";
|
||||||
|
|
Loading…
Reference in New Issue