33 #ifndef STATE_MAP_TUPLE_HPP 34 #define STATE_MAP_TUPLE_HPP 42 #include <eigen3/Eigen/Eigen> 46 template <
class TNumericType,
typename... TLeafTypes>
50 public DataBuffer<TNumericType, StateMapBaseCRTP<StateMapTuple<TNumericType, TLeafTypes...>>::MapSize>
65 using RootType =
typename StateMapBaseCRTPTraits<ImplType>::RootType;
93 std::tuple<TLeafTypes...>
subs_;
103 typename std::enable_if<!numericLeaf && (mapSize != Eigen::Dynamic)>::type* =
nullptr>
109 , memStartRef_(nullptr)
111 ,
subs_(
std::make_tuple(TLeafTypes(this, this->dataBuffer_)...))
124 typename std::enable_if<!numericLeaf && (mapSize == Eigen::Dynamic)>::type* =
nullptr>
130 , memStartRef_(nullptr)
132 ,
subs_(
std::make_tuple(TLeafTypes(this, this->dataBuffer_)...))
139 mapElementSize_ += subI.mapElementSize_;
141 if (mapElementSize_ > 0)
143 this->dataBuffer_->resize(mapElementSize_);
150 typename std::enable_if<!numericLeaf && (mapSize != Eigen::Dynamic)>::type* =
nullptr>
156 , memStartRef_(nullptr)
158 ,
subs_(
std::make_tuple(TLeafTypes(_root, _dataBuffer)...))
170 typename std::enable_if<!numericLeaf && (mapSize == Eigen::Dynamic)>::type* =
nullptr>
176 , memStartRef_(nullptr)
178 ,
subs_(
std::make_tuple(TLeafTypes(_root, _dataBuffer)...))
185 mapElementSize_ += subI.mapElementSize_;
196 , memStartRef_(nullptr)
197 , mapElementSize_(_rhs.mapElementSize_)
201 if (!_rhs.
root_->internalCopy_)
203 throw std::runtime_error(
"Copy-constructor not allowed");
215 for_each_2_tuples(_rhs.
subs_,
subs_, [](
auto& _subIRhs,
auto& _subI)
217 _subI.copyRhsData(_subIRhs);
226 if (!root_->internalCopy_)
282 StateBaseVirtualType&
subImplVirt(
const size_t& _i)
override final 288 const StateBaseVirtualType&
subImplVirt(
const size_t& _i)
const override final 296 throw std::runtime_error(
"Cannot resize a tuple");
318 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
325 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
332 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
335 throw std::runtime_error(
"Access of numeric Leaf using sub function not allowed");
340 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
343 throw std::runtime_error(
"Access of numeric Leaf using sub function not allowed");
348 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(!numericLeaf)>::type* =
nullptr>
351 size_t mapMemBeginShift(0);
352 memStartRef_ = _memRef;
355 subI.bindToMemory(memStartRef_ + mapMemBeginShift);
356 mapMemBeginShift += subI.mapElementSize_;
358 mapElementSize_ = mapMemBeginShift;
363 template <bool numericLeaf = HasNumericLeaf, typename std::enable_if<(numericLeaf)>::type* =
nullptr>
366 memStartRef_ = _memRef;
398 typename std::tuple_element<_i, std::tuple<TLeafTypes...>>::type&
subImplCRTP()
400 return std::get<_i>(this->
subs_);
405 const typename std::tuple_element<_i, std::tuple<TLeafTypes...>>::type&
subImplCRTP()
const 407 return std::get<_i>(this->
subs_);
413 return sizeof...(TLeafTypes);
423 template <
class Derived2>
425 template <
class Derived2>
427 template <
class TNumericType2>
429 template <
class TNumericType2,
class... TLeafTypes2>
431 template <
class TNumericType2,
class TLeafType2>
433 template <
class TNumericType2,
class TLeafType2,
size_t TN2>
435 template <
class TLeafType2>
441 template <
class TNumericType,
class... TLeafTypes>
446 using LeafTypeExt = EmptyLeafType;
447 using LeafsTupleType = std::tuple<
typename TLeafTypes::ImplType...>;
448 using LeafsTupleTypeExt = std::tuple<TLeafTypes...>;
450 static constexpr
const int subSize =
sizeof...(TLeafTypes);
451 static constexpr
const bool isDynamic =
false;
457 #endif // STATE_MAP_TUPLE_HPP std::tuple< TLeafTypes... > subs_
friend struct StateMapBaseCRTPTraits
StateMapTuple & operator=(const StateMapTuple &_rhs)
void bindToMemoryImplVirt(TNumericType *_memRef) overridefinal
typename StateMapBaseCRTPTraits< StateMapTuple< TNum, TLeafTypes... > >::NumericType NumericType
typename StateMapBaseCRTP< StateMapTuple< NumericType, TLeafTypes... >>::MapTypeCRTP MapTypeCRTP
void copyRhsData(const StateMapTuple &_rhs)
typename StateMapBaseCRTPTraits< StateMapTuple< TNum, TLeafTypes... > >::LeafTypeExt LeafType
Helper function needed to upgrade c++ 2011.
const StateBaseVirtualType & subImplVirt(const size_t &_i) const overridefinal
void bindToMemoryImplCRTP(TNumericType *_memRef)
TNumericType * memStartRef_
virtual ~StateMapTuple()=default
static constexpr const int MapSize
friend struct LeafTypeContClass
std::tuple_element< _i, std::tuple< TLeafTypes... > >::type & subImplCRTP()
tuw::StateMapTuple< TNum, StateMapBase< TNum, TStateNm< TNum, TNum >, TStateCf< TNum, TNum > >, StateGradMapBase< TNum, StateGradWithMatMap< TNum, TStateNm< TNum, TOptVarStruct< TNum, TNum > > >, StateGradWithMatMap< TNum, TStateCf< TNum, TOptVarStruct< TNum, TNum > > > > >::DataBufferContainterType typename DataBuffer< TNum, StateBaseCRTPType::MapSize >::DataBufferContainerType DataBufferContainterType
typename StateMapBaseVirt< NumericType >::MapTypeVirt MapTypeVirt
Eigen::Map< MatrixTypeCRTP > MapTypeCRTP
constexpr std::enable_if< II==sizeof...(Tp), void >::type for_each_tuple(std::tuple< Tp... > &, FuncT)
typename DataBufferContainerClass::ContainerType DataBufferContainerType
StateBaseVirtualType & subImplVirt(const size_t &_i) overridefinal
MapTypeVirt dataImplVirt() overridefinal
const StateBaseVirtualType & subImplVirtDispatch(const size_t &_i) const
MapTypeCRTP & dataImplCRTP()
NumericType *const memStartRefImplVirt() const overridefinal
typename StateMapBaseVirt< NumericType >::StateBaseVirtualType StateBaseVirtualType
StateMapTuple(RootType *_root, std::shared_ptr< TDataBuffer > &_dataBuffer)
typename StateMapBaseCRTPTraits< StateMapTuple< TNum, TLeafTypes... > >::RootType RootType
Eigen::Map< Eigen::Matrix< TNum, Eigen::Dynamic, 1 > > MapTypeVirt
static constexpr auto value
void bindToMemory(TNumericType *_memRef)
NumericType *const memStartRefImplCRTP() const
static constexpr const bool HasNumericLeaf
StateMapTuple(const StateMapTuple &_rhs)
TNumericType *const memStartRef() const
const MapTypeVirt dataImplVirt() const overridefinal
std::array< StateBaseVirtualType *, sizeof...(TLeafTypes)> subsBase_
constexpr const size_t subSizeImplCRTP() const
const MapTypeCRTP & dataImplCRTP() const
void subResize(const size_t &_size)
StateBaseVirtualType & subImplVirtDispatch(const size_t &_i)
const size_t subSizeImplVirt() const overridefinal
const std::tuple_element< _i, std::tuple< TLeafTypes... > >::type & subImplCRTP() const
StateBaseVirtualType * root_
void subResizeImplVirt(const size_t &_size) overridefinal
const size_t & subSize() const