33 #ifndef STATE_MAP_ARRAY_HPP 34 #define STATE_MAP_ARRAY_HPP 41 #include <eigen3/Eigen/Eigen> 45 template <
class TLeafType,
size_t TN>
49 std::array<std::shared_ptr<TLeafType>, TN>
subs_;
55 template <
class TNumericType,
class TLeafType,
size_t TN>
59 public DataBuffer<TNumericType, StateMapBaseCRTP<StateMapArray<TNumericType, TLeafType, TN>>::MapSize>,
60 public std::conditional<!std::is_same<TLeafType, TNumericType>::value, ContainerSubStateMapArray<TLeafType, TN>,
61 ContainerSubStateMapArrayEmpty>::type
76 using RootType =
typename StateMapBaseCRTPTraits<ImplType>::RootType;
108 template <
bool numericLeaf = HasNumericLeaf,
int mapSize = StateBaseCRTPType::MapSize,
109 typename std::enable_if<!numericLeaf && (mapSize != Eigen::Dynamic)>::type* =
nullptr>
115 , memStartRef_(nullptr)
119 for (
auto& subI : this->
subs_)
121 subI = std::shared_ptr<LeafType>(
new LeafType(
this, this->dataBuffer_));
123 this->bindToMemory(this->dataBuffer_->data());
127 template <
bool numericLeaf = HasNumericLeaf,
int mapSize = StateBaseCRTPType::MapSize,
128 typename std::enable_if<!numericLeaf && (mapSize == Eigen::Dynamic)>::type* =
nullptr>
134 , memStartRef_(nullptr)
138 for (
auto& subI : this->
subs_)
140 subI = std::shared_ptr<LeafType>(
new LeafType(
this, this->dataBuffer_));
141 mapElementSize_ += subI->mapElementSize_;
143 if (mapElementSize_ > 0)
145 this->dataBuffer_->resize(mapElementSize_);
146 this->bindToMemory(this->dataBuffer_->data());
151 template <
bool numericLeaf = HasNumericLeaf,
int mapSize = StateBaseCRTPType::MapSize,
152 typename std::enable_if<numericLeaf && (mapSize != -1)>::type* =
nullptr>
158 , memStartRef_(
nullptr)
159 , mapElementSize_(StateBaseCRTPType::MapSize)
162 this->bindToMemory(this->dataBuffer_->data());
167 template <
bool numericLeaf = HasNumericLeaf,
int mapSize = StateBaseCRTPType::MapSize,
typename TDataBuffer,
168 typename std::enable_if<!numericLeaf && (mapSize != Eigen::Dynamic)>::type* =
nullptr>
174 , memStartRef_(nullptr)
178 for (
auto& subI : this->
subs_)
180 subI = std::shared_ptr<LeafType>(
new LeafType(_root, _dataBuffer));
185 template <
bool numericLeaf = HasNumericLeaf,
int mapSize = StateBaseCRTPType::MapSize,
typename TDataBuffer,
186 typename std::enable_if<!numericLeaf && (mapSize == Eigen::Dynamic)>::type* =
nullptr>
192 , memStartRef_(nullptr)
196 for (
auto& subI : this->
subs_)
198 subI = std::shared_ptr<LeafType>(
new LeafType(_root, _dataBuffer));
199 mapElementSize_ += subI->mapElementSize_;
204 template <
bool numericLeaf = HasNumericLeaf,
int mapSize = StateBaseCRTPType::MapSize,
typename TDataBuffer,
205 typename std::enable_if<numericLeaf && (mapSize != Eigen::Dynamic)>::type* =
nullptr>
211 , memStartRef_(nullptr)
224 , memStartRef_(nullptr)
225 , mapElementSize_(_rhs.mapElementSize_)
228 if (!_rhs.
root_->internalCopy_)
230 throw std::runtime_error(
"Copy-constructor not allowed");
239 template <
typename SubType =
LeafType,
243 for (
size_t i = 0; i < this->
subs_.size(); ++i)
245 this->
subs_[i]->copyRhsData(*_rhs.subs_[i]);
250 template <
typename SubType =
LeafType,
257 template <
typename SubType =
LeafType,
261 for (
size_t i = 0; i < this->
subs_.size(); ++i)
263 this->
subs_[i] = std::shared_ptr<LeafType>(
new LeafType(*_rhs.subs_[i].get()));
268 template <
typename SubType =
LeafType,
275 template <
typename SubType =
LeafType,
279 for (
size_t i = 0; i < this->
subs_.size(); ++i)
281 this->
subs_[i] = std::shared_ptr<LeafType>(
new LeafType(*_rhs.subs_[i].get()));
286 template <
typename SubType =
LeafType,
297 if (!root_->internalCopy_)
300 this->data() = _rhs.
data();
305 createCopyRhsSubs(_rhs);
348 StateBaseVirtualType&
subImplVirt(
const size_t& _i)
override final 350 return subImplVirtDispatch(_i);
354 const StateBaseVirtualType&
subImplVirt(
const size_t& _i)
const override final 356 return subImplVirtDispatch(_i);
362 throw std::runtime_error(
"Cannot resize an array");
368 bindToMemoryImplCRTP(_memRef);
374 return subSizeImplCRTP();
380 return memStartRefImplCRTP();
384 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
387 return subImplCRTP(_i);
391 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
394 return subImplCRTP(_i);
398 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
401 throw std::runtime_error(
"Access of numeric Leaf using virtual \"sub\" function not allowed");
406 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
409 throw std::runtime_error(
"Access of numeric Leaf using virtual \"sub\" function not allowed");
414 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
417 size_t mapMemBeginShift(0);
418 for (
auto& subI : this->
subs_)
420 subI->bindToMemory(_memRef + mapMemBeginShift);
421 mapMemBeginShift += subI->mapElementSize_;
423 memStartRef_ = _memRef;
424 mapElementSize_ = mapMemBeginShift;
429 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
432 memStartRef_ = _memRef;
437 template <
bool dynamicMap = StateBaseCRTPType::MapSize == -1,
typename std::enable_if<(dynamicMap)>::type* =
nullptr>
440 new (&map_)
MapTypeCRTP(memStartRef_, mapElementSize_);
444 template <
bool dynamicMap = StateBaseCRTPType::MapSize == -1,
typename std::enable_if<(!dynamicMap)>::type* =
nullptr>
463 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
466 return *this->
subs_[_i];
470 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
473 return *this->
subs_[_i];
477 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
480 return *this->
subs_[_i];
484 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
487 return *this->
subs_[_i];
491 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
494 return this->
subs_.size();
498 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
501 return this->data()(_i);
505 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
508 return this->data()(_i);
512 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
515 return this->data()(_i);
519 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
522 return this->data()(_i);
526 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
529 return mapElementSize_;
539 template <
class Derived2>
541 template <
class Derived2>
542 friend struct StateMapBaseCRTPTraits;
543 template <
class TNumericType2>
545 template <
class TNumericType2,
class... TLeafTypes2>
547 template <
class TNumericType2,
class TLeafType2>
549 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
551 template <
class TLeafType2>
552 friend struct LeafTypeContClass;
557 template <
class TNumericType,
class TLeafType,
size_t TN>
558 struct StateMapBaseCRTPTraits<
StateMapArray<TNumericType, TLeafType, TN>>
559 :
public std::conditional<std::is_same<TNumericType, TLeafType>::value, LeafTypeContNum<TNumericType>,
560 LeafTypeContClass<TLeafType>>::type
563 using LeafTypeExt = TLeafType;
564 using LeafsTupleType = EmptyLeafType;
565 using LeafsTupleTypeExt = EmptyLeafType;
567 static constexpr
const int subSize = TN;
568 static constexpr
const bool isDynamic =
false;
574 #endif // STATE_MAP_ARRAY_HPP
void bindToMemoryImplCRTP(TNumericType *_memRef)
StateMapArray & operator=(const StateMapArray &_rhs)
StateMapArray(RootType *_root, std::shared_ptr< TDataBuffer > &_dataBuffer)
const MapTypeVirt dataImplVirt() const overridefinal
std::array< std::shared_ptr< TLeafType >, TN > subs_
Helper function needed to upgrade c++ 2011.
LeafType & subImplCRTP(const size_t &_i)
const size_t subSizeImplCRTP() const
const StateBaseVirtualType & subImplVirtDispatch(const size_t &_i) const
NumericType *const memStartRefImplCRTP() const
StateBaseVirtualType & subImplVirtDispatch(const size_t &_i)
typename StateMapBaseCRTP< ImplType >::MapTypeCRTP MapTypeCRTP
typename StateMapBaseVirt< NumericType >::MapTypeVirt MapTypeVirt
typename DataBufferContainerClass::ContainerType DataBufferContainerType
void copyRhsData(const StateMapArray &_rhs)
void subResizeImplVirt(const size_t &_size) overridefinal
Eigen::Map< Eigen::Matrix< TNumericType, Eigen::Dynamic, 1 > > MapTypeVirt
static constexpr auto value
typename DataBuffer< TNumType, StateBaseCRTPType::MapSize >::DataBufferContainerType DataBufferContainterType
typename StateMapBaseCRTPTraits< ImplType >::RootType RootType
void bindToMemoryImplVirt(TNumericType *_memRef) overridefinal
NumericType *const memStartRefImplVirt() const overridefinal
const LeafType & subImplCRTP() const
const StateBaseVirtualType & subImplVirt(const size_t &_i) const overridefinal
void copyRhsSubs(const StateMapArray &_rhs)
MapTypeVirt dataImplVirt() overridefinal
const size_t subSizeImplVirt() const overridefinal
TNumericType * memStartRef_
void createCopyRhsSubs(const StateMapArray &_rhs)
StateMapArray(const StateMapArray &_rhs)
StateBaseVirtualType * root_
const MapTypeCRTP & dataImplCRTP() const
const LeafType & subImplCRTP(const size_t &_i) const
MapTypeCRTP & dataImplCRTP()
StateBaseVirtualType & subImplVirt(const size_t &_i) overridefinal