ocra-recipes
Doxygen documentation for the ocra-recipes repository
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
ocra::Variable Class Referenceabstract

This class represents a variable in a mathematical sense. More...

#include <Variable.h>

Inheritance diagram for ocra::Variable:
[legend]
Collaboration diagram for ocra::Variable:
[legend]

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, VariableParenthoodparenthood_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 VariablegetTimeDerivative ()
 Get the time derivative/primitive of the variable. More...
 
virtual VariablegetTimePrimitive ()
 
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_tgetParenthood (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 Variabledo_createTimeDerivative (const std::string &name)=0
 These methods must be overloaded in children classes to perform instantiation and return pointers to them. More...
 
virtual Variabledo_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
 

Detailed Description

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 (

See also
ocra::CompositeVariable).

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:

ocra::BaseVariable b1("b1", 3);
ocra::BaseVariable b2("b2", 2);
c.add(b1).add(b2);

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.

Warning
DO NOT ATTEMPT TO DERIVE THIS CLASS! The only intended derived classes are BaseVariable, and CompositeVariable.

Definition at line 105 of file Variable.h.

Member Typedef Documentation

Definition at line 116 of file Variable.h.

Constructor & Destructor Documentation

ocra::Variable::Variable ( const std::string &  name = "")

Definition at line 36 of file Variable.cpp.

ocra::Variable::~Variable ( )
pure virtual

The variable is automatically detached from parents and children at destruction.

Definition at line 46 of file Variable.cpp.

Member Function Documentation

double ocra::Variable::at ( size_t  i) const

Definition at line 70 of file Variable.cpp.

void ocra::Variable::callInsertInMemoryMap ( Variable obj,
const parenthood_t child,
size_t  whereInChild,
std::vector< const double * >::const_iterator  start,
std::vector< const double * >::const_iterator  end 
)
staticprotected

Proxy to the implementation of memory maps update.

Definition at line 278 of file Variable.cpp.

void ocra::Variable::callRemoveFromMemoryMap ( Variable obj,
const parenthood_t child,
size_t  whereInChild,
size_t  numElements 
)
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.

virtual Variable* ocra::Variable::do_createTimeDerivative ( const std::string &  name)
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!

Note
This will be asserted if the preprocessor symbol OCRA_ASSERT_ACTIVE is defined.

Implemented in ocra::CompositeVariable, and ocra::BaseVariable.

virtual Variable* ocra::Variable::do_createTimePrimitive ( const std::string &  name)
protectedpure virtual
virtual size_t ocra::Variable::do_getNumberOfChildren ( ) const
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.

virtual void ocra::Variable::do_setValue ( const VectorXd &  value)
protectedpure virtual

This method will attempt to assign a given value to the memory map.

Implemented in ocra::CompositeVariable, and ocra::BaseVariable.

std::vector< const double * > & ocra::Variable::getMemoryMap ( Variable obj)
staticprotected

Definition at line 305 of file Variable.cpp.

const std::string & ocra::Variable::getName ( ) const
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.

Variable & ocra::Variable::getTimeDerivative ( )
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.

Variable & ocra::Variable::getTimePrimitive ( )
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.

bool ocra::Variable::isBaseVariable ( ) const
virtual

Return true if this variable is a base variable, false otherwise.

Reimplemented in ocra::BaseVariable.

Definition at line 169 of file Variable.cpp.

void ocra::Variable::onAttachedParent ( const parenthood_t parent)
protected

Definition at line 228 of file Variable.cpp.

void ocra::Variable::onDetachedParent ( const parenthood_t parent)
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.

void ocra::Variable::printNode ( int  depth,
std::ostream &  os 
) const
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.


The documentation for this class was generated from the following files: