Commit 24f1276b authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Make all DataTree::*_map private

Introducing a new DataTree::getVariable() const method was necessary in the process.
parent f2cf86b7
...@@ -148,6 +148,18 @@ DataTree::AddVariable(int symb_id, int lag) ...@@ -148,6 +148,18 @@ DataTree::AddVariable(int symb_id, int lag)
return p; return p;
} }
VariableNode *
DataTree::getVariable(int symb_id, int lag) const
{
auto it = variable_node_map.find({ symb_id, lag });
if (it == variable_node_map.end())
{
cerr << "DataTree::getVariable: unknown variable node for symb_id=" << symb_id << " and lag=" << lag << endl;
exit(EXIT_FAILURE);
}
return it->second;
}
bool bool
DataTree::ParamUsedWithLeadLagInternal() const DataTree::ParamUsedWithLeadLagInternal() const
{ {
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
//! Is it possible to use leads/lags on variable nodes? //! Is it possible to use leads/lags on variable nodes?
const bool is_dynamic; const bool is_dynamic;
protected: private:
//! num_constant_id -> NumConstNode //! num_constant_id -> NumConstNode
using num_const_node_map_t = map<int, NumConstNode *>; using num_const_node_map_t = map<int, NumConstNode *>;
num_const_node_map_t num_const_node_map; num_const_node_map_t num_const_node_map;
...@@ -89,6 +89,7 @@ protected: ...@@ -89,6 +89,7 @@ protected:
using second_deriv_external_function_node_map_t = map<tuple<vector<expr_t>, int, int, int>, SecondDerivExternalFunctionNode *>; using second_deriv_external_function_node_map_t = map<tuple<vector<expr_t>, int, int, int>, SecondDerivExternalFunctionNode *>;
second_deriv_external_function_node_map_t second_deriv_external_function_node_map; second_deriv_external_function_node_map_t second_deriv_external_function_node_map;
protected:
//! Stores local variables value (maps symbol ID to corresponding node) //! Stores local variables value (maps symbol ID to corresponding node)
map<int, expr_t> local_variables_table; map<int, expr_t> local_variables_table;
//! Stores the order of appearance of local variables in the model block. Needed following change in #563 //! Stores the order of appearance of local variables in the model block. Needed following change in #563
...@@ -153,6 +154,10 @@ public: ...@@ -153,6 +154,10 @@ public:
expr_t AddNonNegativeConstant(const string &value); expr_t AddNonNegativeConstant(const string &value);
//! Adds a variable //! Adds a variable
VariableNode *AddVariable(int symb_id, int lag = 0); VariableNode *AddVariable(int symb_id, int lag = 0);
//! Gets a variable
/*! Same as AddVariable, except that it fails if the variable node has not
already been created */
VariableNode *getVariable(int symb_id, int lag = 0) const;
//! Adds "arg1+arg2" to model tree //! Adds "arg1+arg2" to model tree
expr_t AddPlus(expr_t iArg1, expr_t iArg2); expr_t AddPlus(expr_t iArg1, expr_t iArg2);
//! Adds "arg1-arg2" to model tree //! Adds "arg1-arg2" to model tree
......
...@@ -219,9 +219,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model ...@@ -219,9 +219,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
output << "["; output << "[";
for (size_t j = 0; j < symb_ids.size(); j++) for (size_t j = 0; j < symb_ids.size(); j++)
{ {
auto it = variable_node_map.find({ symb_ids[j], 0 }); getVariable(symb_ids[j])->ExprNode::writeOutput(output, output_type);
assert(it != variable_node_map.end());
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, output_type);
if (j < symb_ids.size()-1) if (j < symb_ids.size()-1)
output << ","; output << ",";
} }
...@@ -269,11 +267,8 @@ SteadyStateModel::writeJsonSteadyStateFile(ostream &output, bool transformComput ...@@ -269,11 +267,8 @@ SteadyStateModel::writeJsonSteadyStateFile(ostream &output, bool transformComput
{ {
if (j != 0) if (j != 0)
output << ","; output << ",";
auto it =
variable_node_map.find({ symb_ids[j], 0 });
assert(it != variable_node_map.end());
output << "\""; output << "\"";
dynamic_cast<ExprNode *>(it->second)->writeJsonOutput(output, {}, {}, false); getVariable(symb_ids[j])->writeJsonOutput(output, {}, {}, false);
output << "\""; output << "\"";
} }
if (symb_ids.size() > 1) if (symb_ids.size() > 1)
...@@ -401,11 +396,8 @@ Epilogue::writeEpilogueFile(const string &basename) const ...@@ -401,11 +396,8 @@ Epilogue::writeEpilogueFile(const string &basename) const
output << endl; output << endl;
for (const auto & it : def_table) for (const auto & it : def_table)
{ {
auto node = variable_node_map.find({ it.first, 0 });
assert(node != variable_node_map.end());
output << " "; output << " ";
dynamic_cast<ExprNode *>(node->second)->writeOutput(output, output_type); getVariable(it.first)->ExprNode::writeOutput(output, output_type);
output << " = "; output << " = ";
it.second->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); it.second->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << ";" << endl; output << ";" << endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment