27 #ifndef SCHNEK_VARIABLES_HPP_ 28 #define SCHNEK_VARIABLES_HPP_ 31 #include "../exception.hpp" 32 #include "../util/unique.hpp" 37 #include <boost/shared_ptr.hpp> 38 #include <boost/variant.hpp> 44 typedef boost::shared_ptr<BlockVariables> pBlockVariables;
45 typedef std::list<pBlockVariables> BlockVariablesList;
59 typedef ExpressionVariant ExpressionType;
63 ExpressionType expression;
75 boost::shared_ptr< Unique<Variable> > uniqueId;
78 Variable(
int value,
bool initialised_ =
true,
bool readonly_ =
false);
80 Variable(
double value,
bool initialised_ =
true,
bool readonly_ =
false);
82 Variable(std::string value,
bool initialised_ =
true,
bool readonly_ =
false);
84 Variable(pIntExpression expr,
bool initialised_ =
true,
bool readonly_ =
false);
86 Variable(pFloatExpression expr,
bool initialised_ =
true,
bool readonly_ =
false);
88 Variable(pStringExpression expr,
bool initialised_ =
true,
bool readonly_ =
false);
124 long getId() {
return uniqueId->getId(); }
130 typedef boost::shared_ptr<Variable> pVariable;
131 typedef std::list<pVariable> VariableList;
132 typedef std::map<std::string, pVariable> VariableMap;
148 std::string className;
150 pBlockVariables parent;
152 BlockVariablesList children;
157 typedef std::map<std::string, pBlockVariables> BlockVariablesMap;
158 typedef std::map<std::string, BlockVariablesList> BlockVariablesListMap;
159 BlockVariablesMap childrenByName;
160 BlockVariablesListMap childrenByClassName;
165 bool exists(std::list<std::string> path,
bool upward);
173 pVariable getVariable(std::list<std::string> path,
bool upward);
176 BlockVariables(std::string name_, std::string className_, pBlockVariables parent_)
177 : name(name_), className(className_), parent(parent_)
181 bool exists(std::string name);
188 pVariable getVariable(std::string name);
193 bool addVariable(std::string name, pVariable variable);
198 bool addChild(pBlockVariables child);
221 pBlockVariables root;
223 pBlockVariables cursor;
229 : root(storage.root), cursor(storage.cursor) {}
244 void addVariable(std::string name, pVariable variable);
252 pBlockVariables createBlock(std::string name, std::string classname);
262 #endif // SCHNEK_VARIABLES_HPP_ VariableTypeInfo getType()
returns the type of the variable
Definition: variables.hpp:98
const BlockVariablesList & getChildren()
returns the children of the block
Definition: variables.hpp:207
ValueVariant getValue()
returns the fixed value of the variable
Definition: variables.hpp:100
Variable & operator=(const Variable &var)
assignment operator
Definition: variables.cpp:107
const ExpressionVariant & getExpression()
returns the expression kept in the variable
Definition: variables.hpp:102
std::string getBlockName()
returns the block's name
Definition: variables.hpp:201
Variable(int value, bool initialised_=true, bool readonly_=false)
construct with an integer
Definition: variables.cpp:43
std::string getClassName()
returns the block's class name
Definition: variables.hpp:203
BlockVariables(std::string name_, std::string className_, pBlockVariables parent_)
Costruct using the block's name and class name.
Definition: variables.hpp:176
bool isConstant()
returns true if the value of the variable is constant and does not depend on non-constant variables ...
Definition: variables.hpp:107
pBlockVariables getParent()
returns the parent (enclosing) block of this block
Definition: variables.hpp:205
VariableTypeInfo
Enum specifying which type the variable returns.
Definition: variables.hpp:57
const VariableMap & getVariables()
returns the variables stored in the block
Definition: variables.hpp:210
bool isInitialised()
returns true if the value of the variable has been initialised
Definition: variables.hpp:113
pBlockVariables getCurrentBlock()
Returns the current block given by the cursor.
Definition: variables.hpp:257
bool isReadOnly()
returns true if the value of the variable is a read only variable
Definition: variables.hpp:110
pBlockVariables getRootBlock()
Returns the root block.
Definition: variables.hpp:255
const ValueVariant & evaluateExpression()
evaluetes the expression kept in the variable and returns the value
Definition: variables.cpp:120
const ValueVariant & evaluate()
returns the value of the variable
Definition: variables.hpp:127
Definition: variables.hpp:142
Definition: variables.hpp:217
Definition: variables.hpp:53