ocra-recipes
Doxygen documentation for the ocra-recipes repository
|
This class represents a variable in a mathematical sense. More...
#include <Variable.h>
Public Types | |
typedef Component< Variable, CompositeVariable, VariableParenthood >::parenthood_t | parenthood_t |
Public Types inherited from ocra::Component< Variable, CompositeVariable, VariableParenthood > | |
typedef Variable | component_t |
Inherited typedefs. More... | |
typedef CompositeVariable | parent_t |
typedef Parenthood< Variable, CompositeVariable, VariableParenthood > | parenthood_t |
typedef std::vector< parenthood_t * >::const_iterator | const_iterator |
typedef std::vector< parenthood_t * >::iterator | iterator |
Public Member Functions | |
Variable (const std::string &name="") | |
virtual | ~Variable ()=0 |
The variable is automatically detached from parents and children at destruction. More... | |
virtual const std::string & | getName () const |
virtual bool | isBaseVariable () const |
int | getSize () const |
operator const VectorXd & () const | |
Implicit conversion to an Eigen vector. More... | |
const VectorXd & | getValue () const |
void | setValue (const VectorXd &value) |
bool | hasTimeDerivative () const |
bool | hasTimePrimitive () const |
void | getRelativeMappingOf (const Variable &subVariable, std::vector< int > &mapping) const |
Returns the indexes of a subvariable in the variable. More... | |
size_t | getNumberOfChildren () const |
Returns 0 in BaseVariable and the number of childhoods otherwise. More... | |
void | printNode (int depth, std::ostream &os) const |
Prints the name of the variables; preprends 3*depth blank spaces. More... | |
double | operator[] (size_t i) const |
double | at (size_t i) const |
virtual Variable & | getTimeDerivative () |
Get the time derivative/primitive of the variable. More... | |
virtual Variable & | getTimePrimitive () |
void | createTimeDerivative (const std::string &name) |
Creates a time derivative/primitive with a given name. More... | |
void | createTimePrimitive (const std::string &name) |
Public Member Functions inherited from ocra::Component< Variable, CompositeVariable, VariableParenthood > | |
bool | isChildOf (const CompositeVariable &node) |
void | printTree (std::ostream &os) |
virtual int | isAncestorOf (const Variable &node) const =0 |
Returns the number of levels that separate the component from a potential child. More... | |
virtual void | printSubTree (int depth, std::ostream &os) const =0 |
Overload in ComponentDerived and CompositeDerived to simply call printTree_impl(). More... | |
size_t | getNumParenthoods () const |
Basic access to the parents. More... | |
const parenthood_t & | getParenthood (size_t i) const |
const_iterator | parents_begin () const |
Iterator range on the set of parents. More... | |
iterator | parents_begin () |
const_iterator | parents_end () const |
iterator | parents_end () |
int | isDescendantOf (const CompositeVariable &node) const |
Returns the number of levels that separates the component from a potential parent. More... | |
int | isDescendantOf (const Variable &node) const |
Public Member Functions inherited from ocra::ObserverSubject | |
ObserverSubject () | |
virtual | ~ObserverSubject () |
Public Member Functions inherited from ocra::Observer | |
virtual | ~Observer () |
template<int EVT> | |
void | bind (SubjectBase< EVT > &subject) |
Call this method to automatically propagate observed events to observers connected to the subject given in argument. More... | |
template<int EVT> | |
void | stopPropagation () |
Public Member Functions inherited from ocra::ObserverBase< EVT_RESIZE > | |
void | bind (subject_type &subject) |
Call this method to automatically propagate observed events to observers connected to the subject given in argument. More... | |
Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES > | |
void | bind (subject_type &subject) |
Call this method to automatically propagate observed events to observers connected to the subject given in argument. More... | |
Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE > | |
void | bind (subject_type &subject) |
Call this method to automatically propagate observed events to observers connected to the subject given in argument. More... | |
Public Member Functions inherited from ocra::Subject | |
virtual | ~Subject () |
template<int EVT, class Derived , class Base > | |
void | connect (Derived &object, void(Base::*newCallback)(int)) const |
Call this method to register a non-static method as a callback. More... | |
template<int EVT> | |
void | connect (void(*newCallback)(int)) const |
Call this method to register a free function as a callback. More... | |
template<int EVT, class Derived , class Base > | |
void | disconnect (Derived &object, void(Base::*callbackToErase)(int)) const |
Disconnect non-static method. More... | |
template<int EVT> | |
void | disconnect (void(*callbackToErase)(int)) const |
Disconnect free function. More... | |
template<int EVT> | |
void | propagate () const |
template<int EVT> | |
void | propagate (int timestamp) const |
Public Member Functions inherited from ocra::SubjectBase< EVT_RESIZE > | |
void | connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const |
Call this method to register a non-static method as a callback. More... | |
void | connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const |
Call this method to register a free function as a callback. More... | |
void | disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const |
Disconnect non-static method. More... | |
void | disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const |
Disconnect free function. More... | |
void | propagate (int timestamp) const |
void | propagate () const |
Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES > | |
void | connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const |
Call this method to register a non-static method as a callback. More... | |
void | connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const |
Call this method to register a free function as a callback. More... | |
void | disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const |
Disconnect non-static method. More... | |
void | disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const |
Disconnect free function. More... | |
void | propagate (int timestamp) const |
void | propagate () const |
Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE > | |
void | connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const |
Call this method to register a non-static method as a callback. More... | |
void | connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const |
Call this method to register a free function as a callback. More... | |
void | disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const |
Disconnect non-static method. More... | |
void | disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const |
Disconnect free function. More... | |
void | propagate (int timestamp) const |
void | propagate () const |
Protected Member Functions | |
virtual void | do_setValue (const VectorXd &value)=0 |
This method will attempt to assign a given value to the memory map. More... | |
virtual size_t | do_getNumberOfChildren () const =0 |
Returns 0 in {Wrap|Base}Variable and the number of childhoods otherwise. More... | |
void | onAttachedParent (const parenthood_t &parent) |
void | onDetachedParent (const parenthood_t &parent) |
virtual Variable * | do_createTimeDerivative (const std::string &name)=0 |
These methods must be overloaded in children classes to perform instantiation and return pointers to them. More... | |
virtual Variable * | do_createTimePrimitive (const std::string &name)=0 |
Protected Member Functions inherited from ocra::Component< Variable, CompositeVariable, VariableParenthood > | |
virtual void | onAttachedParent (const parenthood_t &parent) |
Default implementation of the callbacks, to overload in class ComponentDerived. More... | |
virtual void | onDetachedParent (const parenthood_t &parent) |
Component () | |
~Component () | |
Protected Member Functions inherited from ocra::ObserverBase< EVT_RESIZE > | |
void | stopPropagation () |
Call this method from your callbacks to avoid propagation to the bound subject (if any). More... | |
ObserverBase () | |
~ObserverBase () | |
Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES > | |
void | stopPropagation () |
Call this method from your callbacks to avoid propagation to the bound subject (if any). More... | |
ObserverBase () | |
~ObserverBase () | |
Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE > | |
void | stopPropagation () |
Call this method from your callbacks to avoid propagation to the bound subject (if any). More... | |
ObserverBase () | |
~ObserverBase () | |
Protected Member Functions inherited from ocra::SubjectBase< EVT_RESIZE > | |
SubjectBase () | |
~SubjectBase () | |
Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES > | |
SubjectBase () | |
~SubjectBase () | |
Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE > | |
SubjectBase () | |
~SubjectBase () | |
Static Protected Member Functions | |
static void | callInsertInMemoryMap (Variable &obj, const parenthood_t &child, size_t whereInChild, std::vector< const double * >::const_iterator start, std::vector< const double * >::const_iterator end) |
Proxy to the implementation of memory maps update. More... | |
static void | callRemoveFromMemoryMap (Variable &obj, const parenthood_t &child, size_t whereInChild, size_t numElements) |
static std::vector< const double * > & | getMemoryMap (Variable &obj) |
Additional Inherited Members | |
Protected Types inherited from ocra::ObserverBase< EVT_RESIZE > | |
typedef SubjectBase< EVT > | subject_type |
typedef InvokerBase< EVT > | invoker_type |
Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES > | |
typedef SubjectBase< EVT > | subject_type |
typedef InvokerBase< EVT > | invoker_type |
Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_VALUE > | |
typedef SubjectBase< EVT > | subject_type |
typedef InvokerBase< EVT > | invoker_type |
This class represents a variable in a mathematical sense.
This class represents the mathematical concept of variable. A variable has a name, and a value. A variable can be created by composition of existing variables (
This class is an abstract class and cannot be instantiated. Variables that can be instantiated are:
A variable is a tree whose leaves are instances of BaseVariable; the other nodes are instances of CompositeVariable. Any node (leaf or not) can be manipulated using the Variable interface. Note, however, that the behavior of the functions can differ depending on what instances of variables compose the tree.
Example:
The resulting structure is:
. |- BaseVariable("b1") .CompositeVariable("c") –| . |- BaseVariable("b2")
An access to c[2] is equivalent to an access to b1[2] and an access to c[4] is equivalent to an access to b2[1]: the variables b1 and b2 have been concatenated to produce the composite variable c.
Definition at line 105 of file Variable.h.
typedef Component<Variable, CompositeVariable, VariableParenthood>::parenthood_t ocra::Variable::parenthood_t |
Definition at line 116 of file Variable.h.
ocra::Variable::Variable | ( | const std::string & | name = "" | ) |
Definition at line 36 of file Variable.cpp.
|
pure virtual |
The variable is automatically detached from parents and children at destruction.
Definition at line 46 of file Variable.cpp.
double ocra::Variable::at | ( | size_t | i | ) | const |
Definition at line 70 of file Variable.cpp.
|
staticprotected |
Proxy to the implementation of memory maps update.
Definition at line 278 of file Variable.cpp.
|
staticprotected |
Definition at line 300 of file Variable.cpp.
void ocra::Variable::createTimeDerivative | ( | const std::string & | name | ) |
Creates a time derivative/primitive with a given name.
Throws std::runtime_error if the derivative/primitive already exist.
Definition at line 130 of file Variable.cpp.
void ocra::Variable::createTimePrimitive | ( | const std::string & | name | ) |
Definition at line 147 of file Variable.cpp.
|
protectedpure virtual |
These methods must be overloaded in children classes to perform instantiation and return pointers to them.
These methods shall not return null pointers!
Implemented in ocra::CompositeVariable, and ocra::BaseVariable.
|
protectedpure virtual |
Implemented in ocra::CompositeVariable, and ocra::BaseVariable.
|
protectedpure virtual |
Returns 0 in {Wrap|Base}Variable and the number of childhoods otherwise.
Other behaviors will result in an assertion failure in DEBUG or if OCRA_ASSERT_ACTIVE is defined.
Implemented in ocra::CompositeVariable, and ocra::BaseVariable.
|
protectedpure virtual |
This method will attempt to assign a given value to the memory map.
Implemented in ocra::CompositeVariable, and ocra::BaseVariable.
|
staticprotected |
Definition at line 305 of file Variable.cpp.
|
virtual |
Definition at line 164 of file Variable.cpp.
size_t ocra::Variable::getNumberOfChildren | ( | ) | const |
Returns 0 in BaseVariable and the number of childhoods otherwise.
Definition at line 223 of file Variable.cpp.
void ocra::Variable::getRelativeMappingOf | ( | const Variable & | subVariable, |
std::vector< int > & | mapping | ||
) | const |
Returns the indexes of a subvariable in the variable.
Returns a mapping such that (*this)[mapping[i]] == subVariable[i]. Example: ocra::BaseVariable("b1", 3); ocra::BaseVariable("b2", 2); ocra::CompositeVariable c; c.add(b1).add(b2); std::vector<int> mapping_of_b2_in_c; c.getRelativeMappingOf(b2, mapping_of_b2_in_c); // mapping_of_b2_in_c is [3, 4]
Definition at line 175 of file Variable.cpp.
int ocra::Variable::getSize | ( | ) | const |
Definition at line 81 of file Variable.cpp.
|
virtual |
Get the time derivative/primitive of the variable.
If the derivative/primitive doesn't exist, it will be created automatically at the first call to this method.
Reimplemented in ocra::CompositeVariable, and ocra::BaseVariable.
Definition at line 106 of file Variable.cpp.
|
virtual |
Reimplemented in ocra::CompositeVariable, and ocra::BaseVariable.
Definition at line 113 of file Variable.cpp.
const VectorXd & ocra::Variable::getValue | ( | ) | const |
Definition at line 94 of file Variable.cpp.
bool ocra::Variable::hasTimeDerivative | ( | ) | const |
Definition at line 120 of file Variable.cpp.
bool ocra::Variable::hasTimePrimitive | ( | ) | const |
Definition at line 125 of file Variable.cpp.
|
virtual |
Return true if this variable is a base variable, false otherwise.
Reimplemented in ocra::BaseVariable.
Definition at line 169 of file Variable.cpp.
|
protected |
Definition at line 228 of file Variable.cpp.
|
protected |
Definition at line 242 of file Variable.cpp.
ocra::Variable::operator const VectorXd & | ( | ) | const |
Implicit conversion to an Eigen vector.
Definition at line 87 of file Variable.cpp.
double ocra::Variable::operator[] | ( | size_t | i | ) | const |
Get the value of the component i of the variable. The method Variable::at performs an additional verifications and throws std::runtime_error if i is out of bounds.
Definition at line 65 of file Variable.cpp.
|
virtual |
Prints the name of the variables; preprends 3*depth blank spaces.
Implements ocra::Component< Variable, CompositeVariable, VariableParenthood >.
Definition at line 251 of file Variable.cpp.
void ocra::Variable::setValue | ( | const VectorXd & | value | ) |
Definition at line 99 of file Variable.cpp.