33 #ifndef STATE_MAP_VECTOR_HPP 34 #define STATE_MAP_VECTOR_HPP 42 #include <eigen3/Eigen/Eigen> 46 template <
class TLeafType>
60 #ifdef USE_MAP_ALIGNMENT 61 std::vector<TLeafType, boost::alignment::aligned_allocator<TLeafType, MapAlignment>>
subs_;
70 template <
class TNumericType,
class TLeafType>
74 public DataBuffer<TNumericType, StateMapBaseCRTP<StateMapVector<TNumericType, TLeafType>>::MapSize>,
75 public std::conditional<!std::is_same<TLeafType, TNumericType>::value, ContainerSubStateMapVector<TLeafType>,
76 ContainerSubStateMapVectorEmpty>::type
91 using RootType =
typename StateMapBaseCRTPTraits<ImplType>::RootType;
123 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
130 , memStartRef_(nullptr)
137 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
143 , memStartRef_(nullptr)
155 , memStartRef_(nullptr)
168 , memStartRef_(nullptr)
169 , mapElementSize_(_rhs.mapElementSize_)
172 if (!_rhs.
root_->internalCopy_)
174 throw std::runtime_error(
"Copy-constructor not allowed");
183 template <
typename SubType =
LeafType,
187 subResize(_rhs.subs_.size());
188 for (
size_t i = 0; i < this->
subs_.size(); ++i)
190 this->
subs_[i].copyRhsData(_rhs.subs_[i]);
195 template <
typename SubType =
LeafType,
203 template <
typename SubType =
LeafType,
207 for (
size_t i = 0; i < this->
subs_.size(); ++i)
209 this->
subs_[i] = _rhs.subs_[i];
214 template <
typename SubType =
LeafType,
225 if (!root_->internalCopy_)
228 this->data() = _rhs.
data();
266 return dataImplCRTP();
272 return dataImplCRTP();
278 return subImplVirtDispatch(_i);
284 return subImplVirtDispatch(_i);
290 subResizeImplCRTP(_size);
296 bindToMemoryImplCRTP(_memRef);
302 return subSizeImplCRTP();
308 return memStartRefImplCRTP();
312 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
315 return subImplCRTP(_i);
319 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
322 return subImplCRTP(_i);
326 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
329 throw std::runtime_error(
"Access of numeric Leaf using sub function not allowed");
334 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
337 throw std::runtime_error(
"Access of numeric Leaf using sub function not allowed");
342 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
345 if (_size != this->
subs_.size())
347 const size_t mapElementSizeOld = mapElementSize_;
348 const auto distFromStart = std::distance(this->dataBuffer_->data(), memStartRef_);
349 root_->internalCopy_ =
true;
350 this->
subs_.resize(_size,
LeafType(root_, this->dataBuffer_));
351 root_->internalCopy_ =
false;
353 for (
const auto& subI : this->
subs_)
355 mapElementSize_ += subI.mapElementSize_;
357 const auto iteratorStart = this->dataBuffer_->begin() + distFromStart;
358 if (mapElementSize_ > mapElementSizeOld)
360 this->dataBuffer_->insert(iteratorStart + 1 * (mapElementSizeOld != 0), (mapElementSize_ - mapElementSizeOld),
363 else if (mapElementSize_ < mapElementSizeOld)
365 this->dataBuffer_->erase(iteratorStart + mapElementSize_, iteratorStart + mapElementSizeOld);
367 root_->bindToMemory(this->dataBuffer_->data());
372 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
375 if (_size != mapElementSize_)
377 const size_t mapElementSizeOld = mapElementSize_;
378 const auto distFromStart = std::distance(this->dataBuffer_->data(), memStartRef_);
379 mapElementSize_ = _size;
380 const auto iteratorStart = this->dataBuffer_->begin() + distFromStart;
381 if (mapElementSize_ > mapElementSizeOld)
383 this->dataBuffer_->insert(iteratorStart + 1 * (mapElementSizeOld != 0), (mapElementSize_ - mapElementSizeOld),
385 root_->bindToMemory(this->dataBuffer_->data());
387 else if (mapElementSize_ < mapElementSizeOld)
389 this->dataBuffer_->erase(iteratorStart + mapElementSize_, iteratorStart + mapElementSizeOld);
390 root_->bindToMemory(this->dataBuffer_->data());
396 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
399 size_t mapMemBeginShift(0);
400 for (
auto& subI : this->
subs_)
402 subI.bindToMemory(_memRef + mapMemBeginShift);
403 mapMemBeginShift += subI.mapElementSize_;
405 memStartRef_ = _memRef;
406 mapElementSize_ = mapMemBeginShift;
411 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
414 memStartRef_ = _memRef;
419 template <
bool dynamicMap = StateBaseCRTPType::MapSize == -1,
typename std::enable_if<(dynamicMap)>::type* =
nullptr>
422 new (&map_)
MapTypeCRTP(memStartRef_, mapElementSize_);
426 template <
bool dynamicMap = StateBaseCRTPType::MapSize == -1,
typename std::enable_if<(!dynamicMap)>::type* =
nullptr>
445 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
448 return this->
subs_[_i];
452 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
455 return this->
subs_[_i];
459 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
462 return this->
subs_[_i];
466 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
469 return this->
subs_[_i];
473 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
476 return this->
subs_.size();
480 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
483 return this->data()(_i);
487 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
490 return this->data()(_i);
494 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
497 return this->data()(_i);
501 template <size_t _i, bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
504 return this->data()(_i);
508 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
511 return mapElementSize_;
521 template <
class Derived2>
523 template <
class Derived2>
524 friend struct StateMapBaseCRTPTraits;
525 template <
class TNumericType2>
527 template <
class TNumericType2,
class... TLeafTypes2>
529 template <
class TNumericType2,
class TLeafType2>
531 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
533 template <
class TLeafType2>
534 friend struct LeafTypeContClass;
539 template <
class TNumericType,
class TLeafType>
540 struct StateMapBaseCRTPTraits<
StateMapVector<TNumericType, TLeafType>>
541 :
public std::conditional<std::is_same<TNumericType, TLeafType>::value, LeafTypeContNum<TNumericType>,
542 LeafTypeContClass<TLeafType>>::type
545 using LeafTypeExt = TLeafType;
546 using LeafsTupleType = EmptyLeafType;
547 using LeafsTupleTypeExt = EmptyLeafType;
549 static constexpr
const int subSize = -1;
550 static constexpr
const bool isDynamic =
true;
556 #endif // STATE_MAP_VECTOR_HPP
typename StateMapBaseCRTPTraits< ImplType >::RootType RootType
ContainerSubStateMapVector(size_t _size, const TLeafType &_vals)
std::vector< TLeafType > subs_
ContainerSubStateMapVector()
StateMapVector & operator=(const StateMapVector &_rhs)
void subResizeImplVirt(const size_t &_size) overridefinal
typename StateMapBaseVirt< NumericType >::StateBaseVirtualType StateBaseVirtualType
const MapTypeCRTP & dataImplCRTP() const
const size_t subSizeImplCRTP() const
Helper function needed to upgrade c++ 2011.
StateBaseVirtualType & subImplVirtDispatch(const size_t &_i)
StateBaseVirtualType & subImplVirt(const size_t &_i) overridefinal
NumericType *const memStartRefImplCRTP() const
void subResizeImplCRTP(const size_t &_size)
const LeafType & subImplCRTP() const
void bindToMemoryImplVirt(TNumericType *_memRef) overridefinal
typename DataBufferContainerClass::ContainerType DataBufferContainerType
NumericType *const memStartRefImplVirt() const overridefinal
void bindToMemoryImplCRTP(TNumericType *_memRef)
void copyRhsSubs(const StateMapVector &_rhs)
Eigen::Map< Eigen::Matrix< TNumericType, Eigen::Dynamic, 1 > > MapTypeVirt
static constexpr auto value
void copyRhsData(const StateMapVector &_rhs)
StateMapVector(const StateMapVector &_rhs)
typename DataBuffer< TNumericType, StateBaseCRTPType::MapSize >::DataBufferContainerType DataBufferContainterType
TNumericType * memStartRef_
MapTypeCRTP & dataImplCRTP()
StateMapVector(RootType *_root, std::shared_ptr< DataBufferContainterType > &_dataBuffer)
StateBaseVirtualType * root_
const LeafType & subImplCRTP(const size_t &_i) const
MapTypeVirt dataImplVirt() overridefinal
const MapTypeVirt dataImplVirt() const overridefinal
const size_t subSizeImplVirt() const overridefinal
LeafType & subImplCRTP(const size_t &_i)
const StateBaseVirtualType & subImplVirtDispatch(const size_t &_i) const
const StateBaseVirtualType & subImplVirt(const size_t &_i) const overridefinal
typename StateMapBaseCRTP< ImplType >::MapTypeCRTP MapTypeCRTP