C++17 modernization: use std::optional for “periods” option of “plot_conditional_forecast”
Incidentally, in the JSON output, no longer assign a value to the “periods” field if not passed by the user (previously the value -1 was output in the JSON file).fix-tolerance-parameters
parent
fc037a4352
commit
8fd1505ca2
|
@ -3266,10 +3266,10 @@ ConditionalForecastStatement::writeJsonOutput(ostream &output) const
|
|||
output << "}";
|
||||
}
|
||||
|
||||
PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_arg,
|
||||
PlotConditionalForecastStatement::PlotConditionalForecastStatement(optional<int> periods_arg,
|
||||
SymbolList symbol_list_arg,
|
||||
const SymbolTable &symbol_table_arg) :
|
||||
periods{periods_arg},
|
||||
periods{move(periods_arg)},
|
||||
symbol_list{move(symbol_list_arg)},
|
||||
symbol_table{symbol_table_arg}
|
||||
{
|
||||
|
@ -3294,17 +3294,18 @@ void
|
|||
PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
|
||||
{
|
||||
symbol_list.writeOutput("var_list_", output);
|
||||
if (periods == -1)
|
||||
output << "plot_icforecast(var_list_,[],options_,oo_);" << endl;
|
||||
if (periods)
|
||||
output << "plot_icforecast(var_list_, " << *periods << ",options_,oo_);" << endl;
|
||||
else
|
||||
output << "plot_icforecast(var_list_, " << periods << ",options_,oo_);" << endl;
|
||||
output << "plot_icforecast(var_list_,[],options_,oo_);" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
PlotConditionalForecastStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << R"({"statementName": "plot_conditional_forecast", )"
|
||||
<< R"("periods": )" << periods;
|
||||
output << R"({"statementName": "plot_conditional_forecast")";
|
||||
if (periods)
|
||||
output << R"(, "periods": )" << *periods;
|
||||
if (!symbol_list.empty())
|
||||
{
|
||||
output << ", ";
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define _COMPUTINGTASKS_HH
|
||||
|
||||
#include <ostream>
|
||||
#include <optional>
|
||||
|
||||
#include "SymbolList.hh"
|
||||
#include "SymbolTable.hh"
|
||||
|
@ -848,12 +849,11 @@ public:
|
|||
class PlotConditionalForecastStatement : public Statement
|
||||
{
|
||||
private:
|
||||
//! A value of -1 indicates that the user didn't specify a value
|
||||
const int periods;
|
||||
const optional<int> periods; // The user is allowed not to declare periods
|
||||
const SymbolList symbol_list;
|
||||
const SymbolTable &symbol_table;
|
||||
public:
|
||||
PlotConditionalForecastStatement(int periods_arg, SymbolList symbol_list_arg,
|
||||
PlotConditionalForecastStatement(optional<int> periods_arg, SymbolList symbol_list_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
|
||||
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
|
||||
|
|
|
@ -3213,7 +3213,7 @@ conditional_forecast_option : o_periods
|
|||
;
|
||||
|
||||
plot_conditional_forecast : PLOT_CONDITIONAL_FORECAST symbol_list ';'
|
||||
{ driver.plot_conditional_forecast("", $2); }
|
||||
{ driver.plot_conditional_forecast(nullopt, $2); }
|
||||
| PLOT_CONDITIONAL_FORECAST '(' PERIODS EQUAL INT_NUMBER ')' symbol_list ';'
|
||||
{ driver.plot_conditional_forecast($5, $7); }
|
||||
;
|
||||
|
|
|
@ -2498,10 +2498,12 @@ ParsingDriver::conditional_forecast()
|
|||
}
|
||||
|
||||
void
|
||||
ParsingDriver::plot_conditional_forecast(const string &periods, vector<string> symbol_list)
|
||||
ParsingDriver::plot_conditional_forecast(const optional<string> &periods, vector<string> symbol_list)
|
||||
{
|
||||
int nperiods = periods.empty() ? -1 : stoi(periods);
|
||||
mod_file->addStatement(make_unique<PlotConditionalForecastStatement>(nperiods, move(symbol_list),
|
||||
optional<int> iperiods;
|
||||
if (periods)
|
||||
iperiods = stoi(*periods);
|
||||
mod_file->addStatement(make_unique<PlotConditionalForecastStatement>(move(iperiods), move(symbol_list),
|
||||
mod_file->symbol_table));
|
||||
}
|
||||
|
||||
|
|
|
@ -726,7 +726,7 @@ public:
|
|||
//! Conditional forecast paths block
|
||||
void conditional_forecast_paths();
|
||||
//! Plot conditional forecast statement
|
||||
void plot_conditional_forecast(const string &periods, vector<string> symbol_list);
|
||||
void plot_conditional_forecast(const optional<string> &periods, vector<string> symbol_list);
|
||||
//! Smoother on calibrated models
|
||||
void calib_smoother(vector<string> symbol_list);
|
||||
//! Extended path
|
||||
|
|
Loading…
Reference in New Issue