ocra-recipes
Doxygen documentation for the ocra-recipes repository
Classes | Namespaces | Macros | Enumerations | Functions
IFunction.h File Reference

Declaration file of the IFunction interface. More...

#include <ocra/util/MathTypes.h>
#include "ocra/optim/ocra_assert.h"
#include <iostream>
#include <vector>
#include <stdexcept>
Include dependency graph for IFunction.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ocra::return_type_traits< T >
 type and function definitions for the return types. More...
 
class  ocra::IFunction< Property >
 Computation ability of a ocra function. More...
 

Namespaces

 ocra
 Optimization-based Robot Controller namespace. a library of classes to write and solve optimization problems dedicated to the control of multi-body systems.
 

Macros

#define DECLARE_SUBTYPE_TRAITS(type, subTypeReturn, preAccess, access)
 
#define DECLARE_FUNCTION_TRAITS(templateArg, propName, returnType, virtualFunctionName, abilityId)
 
#define OCRA_FUNCTION_INTERFACE_LIST(begin, pre, end)
 
#define OCRA_FUNCTION_INTERFACE_COMA   ,
 
#define OCRA_FUNCTION_INTERFACE_INHERITANCE(inheritanceAccessRight)   OCRA_FUNCTION_INTERFACE_LIST(inheritanceAccessRight, OCRA_FUNCTION_INTERFACE_COMA inheritanceAccessRight, )
 
#define OCRA_APPLY_FUNCTION_ON_ALL_INTERFACE(methodAndArgs)   OCRA_FUNCTION_INTERFACE_LIST(, , ::methodAndArgs;)
 
#define OCRA_FUNCTION_INTERFACE_INITIALIZE(usageSet)   OCRA_FUNCTION_INTERFACE_LIST(, OCRA_FUNCTION_INTERFACE_COMA, (usageSet))
 

Enumerations

enum  ocra::eFunctionAbility {
  ocra::FUN_VALUE = 0, ocra::PARTIAL_X, ocra::PARTIAL_T, ocra::FUN_DOT,
  ocra::PARTIAL_X_DOT, ocra::PARTIAL_XX, ocra::FUN_DDOT, ocra::PARTIAL_TT,
  ocra::PARTIAL_TX, ocra::PARTIAL_XT, ocra::PARTIAL_T_DOT, ocra::PARTIAL_X_DOT_X_DOT,
  ocra::PROP_NUMBER
}
 Enumeration of the computation abilities of a ocra function. More...
 

Functions

 ocra::DECLARE_SUBTYPE_TRAITS (VectorXd, double,, operator[])
 
 ocra::DECLARE_SUBTYPE_TRAITS (MatrixXd, MatrixXdRow,, row)
 
 ocra::DECLARE_SUBTYPE_TRAITS (std::vector< MatrixXd * >, const MatrixXd &,*, operator[])
 
 ocra::DECLARE_FUNCTION_TRAITS (eFunctionAbility Property,, int, updateProperty,-1)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< FUN_VALUE >, VectorXd, updateValue, FUN_VALUE)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_X >, MatrixXd, updateJacobian, PARTIAL_X)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_T >, VectorXd, updatePartialT, PARTIAL_T)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< FUN_DOT >, VectorXd, updateFdot, FUN_DOT)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_X_DOT >, MatrixXd, updateJdot, PARTIAL_X_DOT)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_XX >, std::vector< MatrixXd * >, updateHessian, PARTIAL_XX)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< FUN_DDOT >, VectorXd, updateFddot, FUN_DDOT)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_TT >, VectorXd, updatePartialTT, PARTIAL_TT)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_TX >, MatrixXd, updatePartialTX, PARTIAL_TX)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_XT >, MatrixXd, updatePartialXT, PARTIAL_XT)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_T_DOT >, VectorXd, updatePartialTdot, PARTIAL_T_DOT)
 
 ocra::DECLARE_FUNCTION_TRAITS (,< PARTIAL_X_DOT_X_DOT >, VectorXd, updateJdotXdot, PARTIAL_X_DOT_X_DOT)
 

Detailed Description

Declaration file of the IFunction interface.

Copyright (C) 2010 CEA/DRT/LIST/DIASI/LSI

Author
Escande Adrien
Evrard Paul
Date
10.05.31

Given a (mathematical) function f depending on a set of time-dependant variable x and possibly explicitly of the time t, the coding mechanism to obtain the value at the point $ \left(x(t),t\right) $ of this function or one of its (partial) derivative is always the same, despite the fact that the output spaces can be different. For example, if $ f: R^n \times R \rightarrow R^m $, $ f(x,t) $ is a m-vector and $ \frac{\partial^2 f}{\partial t \partial x}(x,t) $ is mxn matrix, yet obtaining this value eventually boils down on a programmer viewpoint to calling a method of a class. The IFunction interface aims at taking advantage of this similarity to factorize code.

On an programmer viewpoint, the object corresponding to a mathematical function can only compute its value at $ \left(x(t),t\right) $ or the value of a derivative if the corresponding method has been implemented. We call ability the capacity of a (c++ object) function to compute such a value. Each possible ability produces a corresponding IFunction.

This file defines several coding mechanims (traits and macros) to make it easy to add and implement new abilities. If you wish to add an ability you need to: (a) add an identifier in the enumeration eFunctionAbility, (b) add a DECLARE_FUNCTION_TRAITS call, with the desired return type for your ability and the name of the function that will compute its value, (c) add a line in the macro OCRA_FUNCTION_INTERFACE_LIST. It is VERY IMPORTANT to add this line at the end of the macros. Failing to do so would mess up with the initialization list of the derived classes in a silent way since default parameters are used. In step (b) you might want to use a type for which a sub_type_traits was not defined yet, in which case you need to add a DECLARE_SUBTYPE_TRAITS call with the proper arguments. Every point where the programmer may want/need to add an entry is flagged by [ADD-IN] in the documentation preceeding the point.

Copyright (C) 2010 CEA/DRT/LIST/DIASI/LSI

Author
Escande Adrien
Date
10.05.31

Definition in file IFunction.h.

Macro Definition Documentation

#define DECLARE_FUNCTION_TRAITS (   templateArg,
  propName,
  returnType,
  virtualFunctionName,
  abilityId 
)
Value:
template<templateArg> struct ocra_function_traits propName \
{ \
typedef returnType type_t; \
typedef return_type_traits<returnType>::sub_type_t sub_type_t; \
virtual void virtualFunctionName() const \
{ \
std::stringstream s; \
s << "[Function::" << #virtualFunctionName << "] is not implemented. Did you forget to declare its overload as a protected const method ?"; \
std::cout << s.str()<<std::endl; \
throw std::runtime_error(s.str()); \
} \ \
template<class FunctionType> static void update(const FunctionType& function) { function.virtualFunctionName(); } \
static bool extractUsage(const std::vector<bool>& usageSet) {return usageSet[abilityId];}\
};

Definition at line 178 of file IFunction.h.

#define DECLARE_SUBTYPE_TRAITS (   type,
  subTypeReturn,
  preAccess,
  access 
)
Value:
template<> struct return_type_traits<type > \
{ \
typedef subTypeReturn sub_type_t; \
static subTypeReturn getSub(const type& v, int index) {return preAccess(v.access(index));} \
static void resize(type& v, int m, int n=0);\
};

Definition at line 111 of file IFunction.h.

#define OCRA_APPLY_FUNCTION_ON_ALL_INTERFACE (   methodAndArgs)    OCRA_FUNCTION_INTERFACE_LIST(, , ::methodAndArgs;)

Definition at line 412 of file IFunction.h.

#define OCRA_FUNCTION_INTERFACE_COMA   ,

Definition at line 396 of file IFunction.h.

#define OCRA_FUNCTION_INTERFACE_INHERITANCE (   inheritanceAccessRight)    OCRA_FUNCTION_INTERFACE_LIST(inheritanceAccessRight, OCRA_FUNCTION_INTERFACE_COMA inheritanceAccessRight, )

Definition at line 403 of file IFunction.h.

#define OCRA_FUNCTION_INTERFACE_INITIALIZE (   usageSet)    OCRA_FUNCTION_INTERFACE_LIST(, OCRA_FUNCTION_INTERFACE_COMA, (usageSet))

Definition at line 418 of file IFunction.h.

#define OCRA_FUNCTION_INTERFACE_LIST (   begin,
  pre,
  end 
)
Value:
begin IFunction<FUN_VALUE> end \
pre IFunction<PARTIAL_X> end \
pre IFunction<PARTIAL_T> end \
pre IFunction<FUN_DOT> end \
pre IFunction<PARTIAL_X_DOT> end \
pre IFunction<PARTIAL_XX> end \
pre IFunction<FUN_DDOT> end \
pre IFunction<PARTIAL_TT> end \
pre IFunction<PARTIAL_TX> end \
pre IFunction<PARTIAL_XT> end \
pre IFunction<PARTIAL_T_DOT> end \
pre IFunction<PARTIAL_X_DOT_X_DOT> end \
/*pre IFunction<[NEW_PROP]> end*/

Definition at line 380 of file IFunction.h.