33 #ifndef STATE_MAP_BASE_HPP 34 #define STATE_MAP_BASE_HPP 40 #include <eigen3/Eigen/Eigen> 44 #ifdef USE_MAP_ALIGNMENT 45 #include <boost/align/aligned_allocator.hpp> 49 constexpr
const int MapAlignment = Eigen::Aligned16;
50 template <
typename T,
size_t N>
51 struct __attribute__((aligned(16))) aligned_array :
public std::array<T, N>
61 template <
class TDerived>
62 struct StateMapBaseCRTPTraits;
68 template <
class ThisStateTraits>
69 constexpr
inline typename std::enable_if<
72 template <
class ThisStateTraits>
73 constexpr
inline typename std::enable_if<
74 (!std::is_same<typename ThisStateTraits::NumericType, typename ThisStateTraits::LeafType>::value) &&
78 template <
class ThisStateTraits>
79 constexpr
inline typename std::enable_if<
80 (!std::is_same<typename ThisStateTraits::NumericType, typename ThisStateTraits::LeafType>::value) &&
85 template <
typename Tuple, std::
size_t II = 0>
90 template <
typename Tuple, std::
size_t II = 0>
93 constexpr
const int sizeSubThis = getMapSize<StateMapBaseCRTPTraits<typename std::tuple_element<II, Tuple>::type>>();
94 constexpr
const int sizeSubNext = get_tuple_map_size<Tuple, II + 1>();
95 return +((sizeSubThis == -1) || (sizeSubNext == -1)) * (-1) +
96 !((sizeSubThis == -1) || (sizeSubNext == -1)) * (sizeSubThis + sizeSubNext);
99 template <
class ThisStateTraits>
100 constexpr
inline typename std::enable_if<
101 std::is_same<typename ThisStateTraits::NumericType, typename ThisStateTraits::LeafType>::value,
int>::type
104 return ThisStateTraits::subSize;
106 template <
class ThisStateTraits>
107 constexpr
inline typename std::enable_if<
108 (!std::is_same<typename ThisStateTraits::NumericType, typename ThisStateTraits::LeafType>::value) &&
113 constexpr
const int sizeSubThis = ThisStateTraits::subSize;
114 constexpr
const int sizeSubLeaf = getMapSize<StateMapBaseCRTPTraits<typename ThisStateTraits::LeafType>>();
115 return ((sizeSubThis == -1) || (sizeSubLeaf == -1)) * (-1) +
116 !((sizeSubThis == -1) || (sizeSubLeaf == -1)) * (sizeSubThis * sizeSubLeaf);
118 template <
class ThisStateTraits>
119 constexpr
inline typename std::enable_if<
120 (!std::is_same<typename ThisStateTraits::NumericType, typename ThisStateTraits::LeafType>::value) &&
125 return get_tuple_map_size<typename ThisStateTraits::LeafsTupleType>();
128 template <
class TNumericType>
129 struct LeafTypeContNum
131 using LeafType = TNumericType;
133 template <
class TLeafType>
134 struct LeafTypeContClass
136 using LeafType =
typename TLeafType::ImplType;
141 template <
class TNumericType>
145 #ifdef USE_MAP_ALIGNMENT 146 using ContainerType = std::vector<TNumericType, boost::alignment::aligned_allocator<TNumericType, MapAlignment>>;
178 template <
class Derived2>
180 template <
class Derived2>
181 friend struct StateMapBaseCRTPTraits;
182 template <
class TNumericType2>
184 template <
class TNumericType2,
class... TLeafTypes2>
186 template <
class TNumericType2,
class TLeafType2>
188 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
190 template <
class TLeafType2>
191 friend struct LeafTypeContClass;
192 template <
class TNumericType2,
int TMapSize2>
195 template <
class TNumericType,
int TMapSize>
199 #ifdef USE_MAP_ALIGNMENT 207 DataBufferArray(std::shared_ptr<ContainerType> _dataBuffer) : dataBuffer_(_dataBuffer)
233 template <
class Derived2>
235 template <
class Derived2>
236 friend struct StateMapBaseCRTPTraits;
237 template <
class TNumericType2>
239 template <
class TNumericType2,
class... TLeafTypes2>
241 template <
class TNumericType2,
class TLeafType2>
243 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
245 template <
class TLeafType2>
246 friend struct LeafTypeContClass;
247 template <
class TNumericType2,
int TMapSize2>
251 template <
class TNumericType,
int TMapSize>
252 class DataBuffer :
public std::conditional<TMapSize == Eigen::Dynamic, DataBufferVector<TNumericType>,
253 DataBufferArray<TNumericType, TMapSize>>::type
256 using DataBufferContainerClass =
typename std::conditional<TMapSize == Eigen::Dynamic, DataBufferVector<TNumericType>,
287 template <
class Derived2>
289 template <
class Derived2>
290 friend struct StateMapBaseCRTPTraits;
291 template <
class TNumericType2>
293 template <
class TNumericType2,
class... TLeafTypes2>
295 template <
class TNumericType2,
class TLeafType2>
297 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
299 template <
class TLeafType2>
300 friend struct LeafTypeContClass;
303 template <
class TDerived>
307 using NumericType =
typename StateMapBaseCRTPTraits<TDerived>::NumericType;
310 using LeafType =
typename StateMapBaseCRTPTraits<TDerived>::LeafTypeExt;
313 using RootType =
typename StateMapBaseCRTPTraits<TDerived>::RootType;
316 static constexpr
const int MapSize = getMapSize<StateMapBaseCRTPTraits<TDerived>>();
322 #ifdef USE_MAP_ALIGNMENT 323 using MapTypeCRTP = Eigen::Map<MatrixTypeCRTP, MapAlignment>;
329 static constexpr
const bool IsDynamic = StateMapBaseCRTPTraits<TDerived>::isDynamic;
353 return thisDerived().dataImplCRTP();
359 return thisDerived().dataImplCRTP();
363 template <
typename leafType =
LeafType,
367 return thisDerived().subImplCRTP(_i);
371 template <
typename leafType =
LeafType,
375 return thisDerived().subImplCRTP(_i);
379 template <
size_t _i,
typename leafType =
LeafType,
383 return thisDerived().template subImplCRTP<_i>();
387 template <
size_t _i,
typename leafType =
LeafType,
391 return thisDerived().template subImplCRTP<_i>();
395 template <
size_t _i,
typename leafType =
LeafType,
397 typename std::tuple_element<_i,
typename StateMapBaseCRTPTraits<TDerived>::LeafsTupleTypeExt>::type&
sub()
399 return thisDerived().template subImplCRTP<_i>();
403 template <
size_t _i,
typename leafType =
LeafType,
405 const typename std::tuple_element<_i,
typename StateMapBaseCRTPTraits<TDerived>::LeafsTupleTypeExt>::type&
sub()
const 407 return thisDerived().template subImplCRTP<_i>();
411 template <bool isDynamic = IsDynamic, typename std::enable_if<(isDynamic)>::type* =
nullptr>
414 thisDerived().subResizeImplCRTP(_size);
420 thisDerived().bindToMemoryImplCRTP(_memRef);
426 return thisDerived().subSizeImplCRTP();
432 return thisDerived().memStartRefImplCRTP();
438 return static_cast<TDerived&
>(*this);
444 return static_cast<const TDerived&
>(*this);
448 template <
class Derived2>
450 template <
class Derived2>
451 friend struct StateMapBaseCRTPTraits;
452 template <
class TNumericType2>
454 template <
class TNumericType2,
class... TLeafTypes2>
456 template <
class TNumericType2,
class TLeafType2>
458 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
460 template <
class TLeafType2>
461 friend struct LeafTypeContClass;
464 template <
class TDerived>
467 template <
class TNumericType>
471 #ifdef USE_MAP_ALIGNMENT 472 using MapTypeVirt = Eigen::Map<Eigen::Matrix<TNumericType, Eigen::Dynamic, 1>, MapAlignment>;
474 using MapTypeVirt = Eigen::Map<Eigen::Matrix<TNumericType, Eigen::Dynamic, 1> >;
504 return dataImplVirt();
510 return dataImplVirt();
516 return subImplVirt(_i);
522 return subImplVirt(_i);
528 subResizeImplVirt(_size);
534 return subSizeImplVirt();
540 return memStartRefImplVirt();
546 bindToMemoryImplVirt(_memRef);
553 virtual const MapTypeVirt dataImplVirt()
const = 0;
562 virtual void subResizeImplVirt(
const size_t& _size) = 0;
565 virtual const size_t subSizeImplVirt()
const = 0;
568 virtual TNumericType*
const memStartRefImplVirt()
const = 0;
571 virtual void bindToMemoryImplVirt(TNumericType* _memRef) = 0;
577 template <
class Derived2>
579 template <
class Derived2>
580 friend struct StateMapBaseCRTPTraits;
581 template <
class TNumericType2>
583 template <
class TNumericType2,
class... TLeafTypes2>
585 template <
class TNumericType2,
class TLeafType2>
587 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
589 template <
class TLeafType2>
590 friend struct LeafTypeContClass;
595 #endif // STATE_MAP_BASE_HPP const StateBaseVirtualType & sub(const size_t &_i) const
const MapTypeCRTP & data() const
Eigen::Matrix< NumericType, MapSize, 1 > MatrixTypeCRTP
typename StateMapBaseCRTPTraits< StateMapTuple< TNum, TLeafTypes... > >::NumericType NumericType
StateBaseVirtualType & sub(const size_t &_i)
std::array< TNumericType, TMapSize > ContainerType
typename StateMapBaseCRTPTraits< StateMapTuple< TNum, TLeafTypes... > >::LeafTypeExt LeafType
void subResize(const size_t &_size)
const LeafType & sub() const
Eigen::Map< MatrixTypeCRTP > MapTypeCRTP
std::shared_ptr< ContainerType > dataBuffer_
typename DataBufferContainerClass::ContainerType DataBufferContainerType
const TDerived & thisDerived() const
NumericType *const memStartRef() const
std::tuple_element< _i, typename StateMapBaseCRTPTraits< TDerived >::LeafsTupleTypeExt >::type & sub()
void bindToMemory(NumericType *_memRef)
typename StateMapBaseCRTPTraits< StateMapTuple< TNum, TLeafTypes... > >::RootType RootType
Eigen::Map< Eigen::Matrix< TNumericType, Eigen::Dynamic, 1 > > MapTypeVirt
static constexpr auto value
std::vector< TNumericType > ContainerType
DataBufferArray(std::shared_ptr< ContainerType > _dataBuffer)
void bindToMemory(TNumericType *_memRef)
std::shared_ptr< ContainerType > dataBuffer_
typename std::conditional< TMapSize==Eigen::Dynamic, DataBufferVector< TNumericType >, DataBufferArray< TNumericType, TMapSize >>::type DataBufferContainerClass
const LeafType & sub(const size_t &_i) const
LeafType & sub(const size_t &_i)
TNumericType *const memStartRef() const
void subResize(const size_t &_size)
constexpr const size_t subSize() const
DataBuffer(std::shared_ptr< DataBufferContainerType > _dataBuffer)
const std::tuple_element< _i, typename StateMapBaseCRTPTraits< TDerived >::LeafsTupleTypeExt >::type & sub() const
const MapTypeVirt data() const
const size_t & subSize() const
DataBufferVector(std::shared_ptr< ContainerType > _dataBuffer)