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

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)
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
DataTree::ParamUsedWithLeadLagInternal() const
{
......
......@@ -48,7 +48,7 @@ public:
//! Is it possible to use leads/lags on variable nodes?
const bool is_dynamic;
protected:
private:
//! num_constant_id -> NumConstNode
using num_const_node_map_t = map<int, NumConstNode *>;
num_const_node_map_t num_const_node_map;
......@@ -89,6 +89,7 @@ protected:
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;
protected:
//! Stores local variables value (maps symbol ID to corresponding node)
map<int, expr_t> local_variables_table;
//! Stores the order of appearance of local variables in the model block. Needed following change in #563
......@@ -153,6 +154,10 @@ public:
expr_t AddNonNegativeConstant(const string &value);
//! Adds a variable
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
expr_t AddPlus(expr_t iArg1, expr_t iArg2);
//! Adds "arg1-arg2" to model tree
......
......@@ -219,9 +219,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
output << "[";
for (size_t j = 0; j < symb_ids.size(); j++)
{
auto it = variable_node_map.find({ symb_ids[j], 0 });
assert(it != variable_node_map.end());
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, output_type);
getVariable(symb_ids[j])->ExprNode::writeOutput(output, output_type);
if (j < symb_ids.size()-1)
output << ",";
}
......@@ -269,11 +267,8 @@ SteadyStateModel::writeJsonSteadyStateFile(ostream &output, bool transformComput
{
if (j != 0)
output << ",";
auto it =
variable_node_map.find({ symb_ids[j], 0 });
assert(it != variable_node_map.end());
output << "\"";
dynamic_cast<ExprNode *>(it->second)->writeJsonOutput(output, {}, {}, false);
getVariable(symb_ids[j])->writeJsonOutput(output, {}, {}, false);
output << "\"";
}
if (symb_ids.size() > 1)
......@@ -401,11 +396,8 @@ Epilogue::writeEpilogueFile(const string &basename) const
output << endl;
for (const auto & it : def_table)
{
auto node = variable_node_map.find({ it.first, 0 });
assert(node != variable_node_map.end());
output << " ";
dynamic_cast<ExprNode *>(node->second)->writeOutput(output, output_type);
getVariable(it.first)->ExprNode::writeOutput(output, output_type);
output << " = ";
it.second->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << ";" << endl;
......
Markdown is supported
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