27 #ifndef SCHNEK_VARIABLES_HPP_ 28 #define SCHNEK_VARIABLES_HPP_ 31 #include "../exception.hpp" 32 #include "../util/unique.hpp" 39 #pragma GCC diagnostic push 40 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 42 #include <boost/variant.hpp> 44 #pragma GCC diagnostic pop 49 typedef std::shared_ptr<BlockVariables> pBlockVariables;
50 typedef std::list<pBlockVariables> BlockVariablesList;
64 typedef ExpressionVariant ExpressionType;
68 ExpressionType expression;
80 std::shared_ptr< Unique<Variable> > uniqueId;
83 Variable(
int value,
bool initialised_ =
true,
bool readonly_ =
false);
85 Variable(
double value,
bool initialised_ =
true,
bool readonly_ =
false);
87 Variable(std::string value,
bool initialised_ =
true,
bool readonly_ =
false);
89 Variable(pIntExpression expr,
bool initialised_ =
true,
bool readonly_ =
false);
91 Variable(pFloatExpression expr,
bool initialised_ =
true,
bool readonly_ =
false);
93 Variable(pStringExpression expr,
bool initialised_ =
true,
bool readonly_ =
false);
129 long getId() {
return uniqueId->getId(); }
135 typedef std::shared_ptr<Variable> pVariable;
136 typedef std::list<pVariable> VariableList;
137 typedef std::map<std::string, pVariable> VariableMap;
153 std::string className;
155 pBlockVariables parent;
157 BlockVariablesList children;
162 typedef std::map<std::string, pBlockVariables> BlockVariablesMap;
163 typedef std::map<std::string, BlockVariablesList> BlockVariablesListMap;
164 BlockVariablesMap childrenByName;
165 BlockVariablesListMap childrenByClassName;
170 bool exists(std::list<std::string> path,
bool upward);
178 pVariable getVariable(std::list<std::string> path,
bool upward);
181 BlockVariables(std::string name_, std::string className_, pBlockVariables parent_)
182 : name(name_), className(className_), parent(parent_)
186 bool exists(std::string name);
193 pVariable getVariable(std::string name);
198 bool addVariable(std::string name, pVariable variable);
203 bool addChild(pBlockVariables child);
226 pBlockVariables root;
228 pBlockVariables cursor;
234 : root(storage.root), cursor(storage.cursor) {}
249 void addVariable(std::string name, pVariable variable);
257 pBlockVariables createBlock(std::string name, std::string classname);
267 #endif // SCHNEK_VARIABLES_HPP_ VariableTypeInfo getType()
returns the type of the variable
Definition: variables.hpp:103
const BlockVariablesList & getChildren()
returns the children of the block
Definition: variables.hpp:212
ValueVariant getValue()
returns the fixed value of the variable
Definition: variables.hpp:105
Variable & operator=(const Variable &var)
assignment operator
Definition: variables.cpp:106
const ExpressionVariant & getExpression()
returns the expression kept in the variable
Definition: variables.hpp:107
std::string getBlockName()
returns the block's name
Definition: variables.hpp:206
Variable(int value, bool initialised_=true, bool readonly_=false)
construct with an integer
Definition: variables.cpp:42
std::string getClassName()
returns the block's class name
Definition: variables.hpp:208
BlockVariables(std::string name_, std::string className_, pBlockVariables parent_)
Costruct using the block's name and class name.
Definition: variables.hpp:181
bool isConstant()
returns true if the value of the variable is constant and does not depend on non-constant variables ...
Definition: variables.hpp:112
pBlockVariables getParent()
returns the parent (enclosing) block of this block
Definition: variables.hpp:210
VariableTypeInfo
Enum specifying which type the variable returns.
Definition: variables.hpp:62
const VariableMap & getVariables()
returns the variables stored in the block
Definition: variables.hpp:215
bool isInitialised()
returns true if the value of the variable has been initialised
Definition: variables.hpp:118
pBlockVariables getCurrentBlock()
Returns the current block given by the cursor.
Definition: variables.hpp:262
bool isReadOnly()
returns true if the value of the variable is a read only variable
Definition: variables.hpp:115
pBlockVariables getRootBlock()
Returns the root block.
Definition: variables.hpp:260
const ValueVariant & evaluateExpression()
evaluetes the expression kept in the variable and returns the value
Definition: variables.cpp:119
const ValueVariant & evaluate()
returns the value of the variable
Definition: variables.hpp:132
Definition: variables.hpp:147
Definition: variables.hpp:222
Definition: variables.hpp:58