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

Factorization in OptionsList class

parent 3e942505
No related branches found
No related tags found
No related merge requests found
/* /*
* Copyright © 2006-2021 Dynare Team * Copyright © 2006-2022 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -158,63 +158,7 @@ VerbatimStatement::writeJsonOutput(ostream &output) const ...@@ -158,63 +158,7 @@ VerbatimStatement::writeJsonOutput(ostream &output) const
void void
OptionsList::writeOutput(ostream &output) const OptionsList::writeOutput(ostream &output) const
{ {
for (const auto & [name, val] : num_options) writeOutputCommon(output, "options_");
output << "options_." << name << " = " << val << ";" << endl;
for (const auto & [name, vals] : paired_num_options)
output << "options_." << name << " = [" << vals.first << "; "
<< vals.second << "];" << endl;
for (const auto & [name, val] : string_options)
output << "options_." << name << " = '" << val << "';" << endl;
for (const auto & [name, val] : date_options)
output << "options_." << name << " = " << val << ";" << endl;
for (const auto & [name, list] : symbol_list_options)
list.writeOutput("options_." + name, output);
for (const auto & [name, vals] : vector_int_options)
{
output << "options_." << name << " = ";
if (vals.size() > 1)
{
output << "[";
for (int viit : vals)
output << viit << ";";
output << "];" << endl;
}
else
output << vals.front() << ";" << endl;
}
for (const auto & [name, vals] : vector_str_options)
{
output << "options_." << name << " = ";
if (vals.size() > 1)
{
output << "{";
for (const auto &viit : vals)
output << "'" << viit << "';";
output << "};" << endl;
}
else
output << vals.front() << ";" << endl;
}
/* vector_cellstr_options should ideally be merged into vector_str_options
only difference is treatment of vals.size==1, where vector_str_options
does not add quotes and curly brackets, i.e. allows for type conversion of
'2' into the number 2
*/
for (const auto & [name, vals] : vector_cellstr_options)
{
output << "options_." << name << " = {";
for (const auto &viit : vals)
output << "'" << viit << "';";
output << "};" << endl;
}
} }
void void
...@@ -231,6 +175,12 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const ...@@ -231,6 +175,12 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
else else
output << option_group << " = struct();" << endl; output << option_group << " = struct();" << endl;
writeOutputCommon(output, option_group);
}
void
OptionsList::writeOutputCommon(ostream &output, const string &option_group) const
{
for (const auto & [name, val] : num_options) for (const auto & [name, val] : num_options)
output << option_group << "." << name << " = " << val << ";" << endl; output << option_group << "." << name << " = " << val << ";" << endl;
...@@ -275,6 +225,12 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const ...@@ -275,6 +225,12 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
output << vals.front() << ";" << endl; output << vals.front() << ";" << endl;
} }
/* vector_cellstr_options should ideally be merged into vector_str_options
only difference is treatment of vals.size==1, where vector_str_options
does not add quotes and curly brackets, i.e. allows for type conversion of
'2' into the number 2
*/
for (const auto & [name, vals] : vector_cellstr_options) for (const auto & [name, vals] : vector_cellstr_options)
{ {
output << option_group << "." << name << " = {"; output << option_group << "." << name << " = {";
......
...@@ -230,6 +230,8 @@ public: ...@@ -230,6 +230,8 @@ public:
void writeOutput(ostream &output, const string &option_group) const; void writeOutput(ostream &output, const string &option_group) const;
void writeJsonOutput(ostream &output) const; void writeJsonOutput(ostream &output) const;
void clear(); void clear();
private:
void writeOutputCommon(ostream &output, const string &option_group) const;
}; };
#endif // ! _STATEMENT_HH #endif // ! _STATEMENT_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment