16 #ifndef _OCRABASE_VARIABLE_H_ 17 #define _OCRABASE_VARIABLE_H_ 22 #include <Eigen/Eigen> 25 #include <boost/noncopyable.hpp> 32 class CompositeVariable;
119 Variable(
const std::string& name =
"");
122 virtual ~Variable() = 0;
124 virtual const std::string& getName()
const;
127 virtual bool isBaseVariable()
const;
136 double operator[](
size_t i)
const;
137 double at(
size_t i)
const;
143 operator const VectorXd& ()
const;
145 const VectorXd& getValue()
const;
146 void setValue(
const VectorXd& value);
154 virtual Variable& getTimeDerivative();
155 virtual Variable& getTimePrimitive();
163 void createTimeDerivative(
const std::string& name);
164 void createTimePrimitive(
const std::string& name);
167 bool hasTimeDerivative()
const;
168 bool hasTimePrimitive()
const;
185 void getRelativeMappingOf(
const Variable& subVariable, std::vector<int>& mapping)
const;
188 size_t getNumberOfChildren()
const;
191 void printNode(
int depth, std::ostream& os)
const;
199 void onAttachedParent(
const parenthood_t& parent);
200 void onDetachedParent(
const parenthood_t& parent);
206 virtual void do_setValue(
const VectorXd& value) = 0;
214 virtual Variable* do_createTimeDerivative(
const std::string& name) = 0;
215 virtual Variable* do_createTimePrimitive(
const std::string& name) = 0;
222 virtual size_t do_getNumberOfChildren()
const = 0;
234 static void callInsertInMemoryMap
235 (Variable& obj,
const parenthood_t& child,
size_t whereInChild,
236 std::vector<const double*>::const_iterator start, std::vector<const double*>::const_iterator end);
238 static void callRemoveFromMemoryMap(Variable& obj,
const parenthood_t& child,
size_t whereInChild,
size_t numElements);
240 static std::vector<const double*>& getMemoryMap(Variable& obj);
254 VariablePtr(Variable* var,
bool owns): var_(var), owns_(owns) {}
255 operator bool()
const {
return (var_ != 0x0); }
259 void insertInMemoryMap(
const parenthood_t& child,
size_t whereInChild, std::vector<const double*>::const_iterator start, std::vector<const double*>::const_iterator end);
261 void removeFromMemoryMap(
const parenthood_t& child,
size_t whereInChild,
size_t numElements);
264 void updateValue()
const;
271 void onChildValueChanged(
int timestamp);
274 std::vector<const double*> memoryMap_;
276 VariablePtr timeDerivative_;
277 VariablePtr timePrimitive_;
278 mutable VectorXd value_;
279 mutable bool updateValue_;
305 :
public Leaf<BaseVariable>
316 bool isBaseVariable()
const;
318 void resize(
size_t newSize);
323 int isAncestorOf(
const Variable& var)
const;
324 void printSubTree(
int depth, std::ostream& os)
const;
327 void do_setValue(
const VectorXd& value);
330 Variable* do_createTimeDerivative(
const std::string& name);
332 Variable* do_createTimePrimitive(
const std::string& name);
336 size_t do_getNumberOfChildren()
const;
339 std::vector<double> memory_;
357 class CompositeVariable
358 :
public Composite<Variable, CompositeVariable, VariableParenthood>
362 CompositeVariable(
const std::string& name);
363 CompositeVariable(
const std::string& name, Variable& var);
364 CompositeVariable(
const std::string& name, Variable& var1, Variable& var2);
365 CompositeVariable(
const std::string& name,
const std::vector<Variable*>& vars);
370 Variable& operator()(
size_t i);
372 CompositeVariable& addByMerge(Variable& v);
374 CompositeVariable& getTimeDerivative();
375 CompositeVariable& getTimePrimitive();
378 CompositeVariable& add(Variable& child);
380 CompositeVariable&
remove(Variable& child);
382 const Variable& operator()(
size_t i)
const;
384 int isAncestorOf(
const Variable& var)
const;
385 void printSubTree(
int depth, std::ostream& os)
const;
388 void do_setValue(
const VectorXd& value);
396 void onAttachedChild(
const parenthood_t& child);
397 void onDetachedChild(
const parenthood_t& child);
402 Variable* do_createTimeDerivative(
const std::string& name);
404 Variable* do_createTimePrimitive(
const std::string& name);
408 size_t do_getNumberOfChildren()
const;
412 #endif //_OCRABASE_VARIABLE_H_ This class stores information about a composite-component relationship.
Utility classes and functions to implement the Composite design pattern.
Component< Variable, CompositeVariable, VariableParenthood >::parenthood_t parenthood_t
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Base class for the Composite class of the Composite pattern.
size_t startIndexInParentMap
This class represents a variable in a mathematical sense.
Base class for the Component class of the Composite pattern.
Base class for the Leaf class of the Composite pattern.
A concatenation of base variables and other composite variables.
Declaration file of the Observer, Subject and ObserverSubject classes.
Implements a basic variable.