38 #ifndef _OCRABASE_IFUNCTION_H_ 39 #define _OCRABASE_IFUNCTION_H_ 111 #define DECLARE_SUBTYPE_TRAITS(type, subTypeReturn, preAccess, access) \ 112 template<> struct return_type_traits<type > \ 114 typedef subTypeReturn sub_type_t; \ 115 static subTypeReturn getSub(const type& v, int index) {return preAccess(v.access(index));} \ 116 static void resize(type& v, int m, int n=0);\ 127 #undef DECLARE_SUBTYPE_TRAITS 130 inline void return_type_traits<VectorXd>::resize(VectorXd& v,
int m,
int n) {v.resize(m);}
133 inline void return_type_traits<MatrixXd>::resize(MatrixXd& v,
int m,
int n) {v.resize(m,n);}
136 inline void return_type_traits<std::vector<MatrixXd*> >::resize(std::vector<MatrixXd*>& v,
int m,
int n)
142 for (
int i=(
int)v.size()-1; i>=m; --i)
149 for (
size_t i=0; i<v.size(); ++i)
154 for (
size_t i=v.size(); i<(size_t)m; ++i)
155 v.push_back(
new MatrixXd(n, n));
178 #define DECLARE_FUNCTION_TRAITS(templateArg, propName, returnType, virtualFunctionName, abilityId) \ 179 template<templateArg> struct ocra_function_traits propName \ 181 typedef returnType type_t; \ 182 typedef return_type_traits<returnType>::sub_type_t sub_type_t; \ 183 virtual void virtualFunctionName() const \ 185 std::stringstream s; \ 186 s << "[Function::" << #virtualFunctionName << "] is not implemented. Did you forget to declare its overload as a protected const method ?"; \ 187 std::cout << s.str()<<std::endl; \ 188 throw std::runtime_error(s.str()); \ 193 template<class FunctionType> static void update(const FunctionType& function) { function.virtualFunctionName(); } \ 194 static bool extractUsage(const std::vector<bool>& usageSet) {return usageSet[abilityId];}\ 218 #undef DECLARE_FUNCTION_TRAITS 242 template<eFunctionAbility Property>
244 :
public ocra_function_traits<Property>
257 :ocra_function_traits<Property>()
258 ,_used(ocra_function_traits<Property>::extractUsage(props))
281 typedef typename ocra_function_traits<Property>::type_t
return_type;
321 template<
class FunctionType>
322 const return_type&
get(FunctionType& data)
const 324 ocra_assert(_used &&
"this function property is not used bordel");
327 ocra_function_traits<Property>::update(data);
342 template<
class FunctionType>
343 return_sub_type
get(FunctionType& data,
int index)
const 366 mutable bool _validated;
380 #define OCRA_FUNCTION_INTERFACE_LIST(begin, pre, end) \ 381 begin IFunction<FUN_VALUE> end \ 382 pre IFunction<PARTIAL_X> end \ 383 pre IFunction<PARTIAL_T> end \ 384 pre IFunction<FUN_DOT> end \ 385 pre IFunction<PARTIAL_X_DOT> end \ 386 pre IFunction<PARTIAL_XX> end \ 387 pre IFunction<FUN_DDOT> end \ 388 pre IFunction<PARTIAL_TT> end \ 389 pre IFunction<PARTIAL_TX> end \ 390 pre IFunction<PARTIAL_XT> end \ 391 pre IFunction<PARTIAL_T_DOT> end \ 392 pre IFunction<PARTIAL_X_DOT_X_DOT> end \ 396 #define OCRA_FUNCTION_INTERFACE_COMA , 403 #define OCRA_FUNCTION_INTERFACE_INHERITANCE(inheritanceAccessRight)\ 404 OCRA_FUNCTION_INTERFACE_LIST(inheritanceAccessRight, OCRA_FUNCTION_INTERFACE_COMA inheritanceAccessRight, ) 412 #define OCRA_APPLY_FUNCTION_ON_ALL_INTERFACE(methodAndArgs) \ 413 OCRA_FUNCTION_INTERFACE_LIST(, , ::methodAndArgs;) 418 #define OCRA_FUNCTION_INTERFACE_INITIALIZE(usageSet)\ 419 OCRA_FUNCTION_INTERFACE_LIST(, OCRA_FUNCTION_INTERFACE_COMA, (usageSet)) 423 #endif //_OCRABASE_IFUNCTION_H_
IFunction(const std::vector< bool > &props)
IFunction Constructor.
Computation ability of a ocra function.
DECLARE_FUNCTION_TRAITS(eFunctionAbility Property,, int, updateProperty,-1)
ocra_function_traits< Property >::sub_type_t return_sub_type
eFunctionAbility
Enumeration of the computation abilities of a ocra function.
type and function definitions for the return types.
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
ocra_function_traits< Property >::type_t return_type
void resizeData(int m, int n)
bool canBeComputed() const
Eigen::DenseBase< MatrixXd >::ConstRowXpr MatrixXdRow
DECLARE_SUBTYPE_TRAITS(VectorXd, double,, operator[])
#define ocra_assert(ocra_expression)
Declaration file of the OptimizationVariable class.