From f691c9ea6620d9c2e68c57cd5d2fcdb061395ee6 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 12 Dec 2017 11:15:39 +0100 Subject: [PATCH] fixing some of the compile errors --- src/container_range.h | 43 +++++++++++++++++++++++++++++++------------ src/index_base.h | 18 ++++++++++-------- src/multi_range.h | 43 +++++++++++++++++++++++++++++++------------ src/single_range.h | 33 +++++++++++++++++++++------------ 4 files changed, 93 insertions(+), 44 deletions(-) diff --git a/src/container_range.h b/src/container_range.h index 5efa01e..5ffbef3 100644 --- a/src/container_range.h +++ b/src/container_range.h @@ -42,9 +42,14 @@ namespace MultiArrayTools template ContainerIndex(const std::shared_ptr& range); + ContainerIndex& operator=(size_t pos) { IB::operator=(pos) ; return *this; } + template auto get() const -> decltype( *std::get( mIPack ) )&; + template + auto getPtr() const -> decltype( std::get( mIPack ) )&; + ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true ContainerIndex& operator()(const std::shared_ptr&... inds); // control via external indices ContainerIndex& operator()(); // -> sync; just to shorten the code @@ -56,7 +61,7 @@ namespace MultiArrayTools // ==== >>>>> STATIC POLYMORPHISM <<<<< ==== - static IndexType S_type(ContainerIndex* i) { return IndexType::CONT; } + static IndexType S_type(ContainerIndex const* i) { return IndexType::CONT; } static ContainerIndex& S_pp_op(ContainerIndex* i) { @@ -100,7 +105,7 @@ namespace MultiArrayTools return tmp; } - static MetaType S_meta(ContainerIndex* i) + static MetaType S_meta(ContainerIndex const* i) { MetaType metaTuple; PackNum::getMetaPos(metaTuple, i->mIPack); @@ -114,28 +119,33 @@ namespace MultiArrayTools return *i; } - static size_t S_dim(ContainerIndex* i) + static size_t S_dim(ContainerIndex const* i) { return sizeof...(Indices); } - static bool S_first(ContainerIndex* i) + static bool S_first(ContainerIndex const* i) { return i->pos() == 0; } - static bool S_last(ContainerIndex* i) + static bool S_last(ContainerIndex const* i) { return i->pos() == i->mMax - 1; } + + static std::shared_ptr S_range(ContainerIndex const* i) + { + return std::dynamic_pointer_cast( i->mRangePtr ); + } template - static auto S_getPtr(ContainerIndex* i) -> decltype( std::get( mIPack ) )& + static auto S_getPtr(ContainerIndex const* i) -> decltype( std::get( mIPack ) )& { return std::get( i->mIPack ); } - static std::shared_ptr S_getVPtr(ContainerIndex* i, size_t n) + static std::shared_ptr S_getVPtr(ContainerIndex const* i, size_t n) { if(n >= sizeof...(Indices)){ assert(0); @@ -145,7 +155,7 @@ namespace MultiArrayTools return PackNum::getIndexPtr(*t, n); } - static size_t S_getStepSize(ContainerIndex* i, size_t n) + static size_t S_getStepSize(ContainerIndex const* i, size_t n) { if(n >= sizeof...(Indices)){ assert(0); @@ -154,7 +164,7 @@ namespace MultiArrayTools return i->mBlockSizes[n+1]; } - static std::string S_id(ContainerIndex* i) { return std::string("con") + std::to_string(IB::mId); } + static std::string S_id(ContainerIndex const* i) { return std::string("con") + std::to_string(i->mId); } }; @@ -182,7 +192,8 @@ namespace MultiArrayTools typedef RangeBase RB; typedef std::tuple...> SpaceType; - typedef typename RangeInterface >::IndexType IndexType; + typedef ContainerIndex IndexType; + //typedef typename RangeInterface >::IndexType IndexType; protected: ContainerRange() = default; @@ -264,6 +275,13 @@ namespace MultiArrayTools return *std::get( mIPack ); } + template + template + auto ContainerIndex::getPtr() const -> decltype( std::get( mIPack ) )& + { + return std::get( mIPack ); + } + template ContainerIndex& ContainerIndex::operator()(const std::shared_ptr&... inds) { @@ -368,8 +386,9 @@ namespace MultiArrayTools template std::shared_ptr ContainerRange::index() const { - return std::make_shared - ( std::make_shared > + typedef IndexWrapper IW; + return std::make_shared + ( std::make_shared ( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ) ); } diff --git a/src/index_base.h b/src/index_base.h index 53ecdb0..512808d 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -53,20 +53,20 @@ namespace MultiArrayTools } template - class IndexWrapper + class IndexWrapper : public VirtualIndexWrapperBase { public: DEFAULT_MEMBERS(IndexWrapper); - IndexWrapper(std::shared_ptr& idxPtr); + IndexWrapper(std::shared_ptr idxPtr); virtual IndexType type() const override { return mIdxPtr->type(); } virtual size_t dim() const override { return mIdxPtr->dim(); } virtual size_t pos() const override { return mIdxPtr->pos(); } virtual size_t max() const override { return mIdxPtr->max(); } - virtual std::shared_ptr rangePtr() const override { return mIdxPtr->rangePtr(); } - virtual std::shared_ptr getPtr(size_t n) const override { return mIdxPtr->getv(n); } + virtual std::shared_ptr rangePtr() const override { return mIdxPtr->vrange(); } + virtual std::shared_ptr getPtr(size_t n) const override { return mIdxPtr->getVPtr(n); } virtual intptr_t getPtrNum() const override { return static_cast( mIdxPtr.get() ); } virtual size_t getStepSize(size_t n) const override { return mIdxPtr->getStepSize(n); } @@ -78,7 +78,7 @@ namespace MultiArrayTools class IndexInterface { public: - typedef typename I::RangeType RangeType; + //typedef typename I::RangeType RangeType; //DEFAULT_MEMBERS(IndexInterface); @@ -106,12 +106,14 @@ namespace MultiArrayTools bool last() const { return I::S_last(THIS()); } bool first() const { return I::S_first(THIS()); } + std::shared_ptr vrange() const { return mRangePtr; } - std::shared_ptr range() const { return std::dynamic_pointer_cast(mRangePtr); } + /*auto range() const -> decltype( I::S_range(THIS()) ) { return I::S_range(THIS()); } template - auto getPtr() const -> decltype(I::S_get(THIS())) { return I::S_get(THIS()); } - + auto getPtr() const -> decltype(I::template S_get(THIS())) + { return I::template S_get(THIS()); } + */ std::shared_ptr getVPtr(size_t n) const { return I::S_getVPtr(THIS(),n); } size_t getStepSize(size_t n) const { return I::S_getStepSize(THIS(),n); } diff --git a/src/multi_range.h b/src/multi_range.h index 6ecf09d..560bd11 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -40,6 +40,8 @@ namespace MultiArrayTools public: MultiIndex() = delete; + + MultiIndex& operator=(size_t pos) { IB::operator=(pos) ; return *this; } // NO DEFAULT HERE !!! // ( have to assign sub-indices (ptr!) correctly ) @@ -59,6 +61,9 @@ namespace MultiArrayTools template auto get() const -> decltype( *std::get( mIPack ) )&; + template + auto getPtr() const -> decltype( std::get( mIPack ) )&; + // raplace instances (in contrast to its analogon in ContainerIndex // MultiIndices CANNOT be influences be its subindices, so there is // NO foreign/external controll) @@ -70,7 +75,7 @@ namespace MultiArrayTools friend IB; // ==== >>>>> STATIC POLYMORPHISM <<<<< ==== - static IndexType S_type(MultiIndex* i) { return IndexType::MULTI; } + static IndexType S_type(MultiIndex const* i) { return IndexType::MULTI; } static MultiIndex& S_ass_op(MultiIndex* i, size_t pos) { @@ -107,7 +112,7 @@ namespace MultiArrayTools return tmp; } - static MetaType S_meta(MultiIndex* i) + static MetaType S_meta(MultiIndex const* i) { MetaType metaTuple; PackNum::getMetaPos(metaTuple, i->mIPack); @@ -121,29 +126,34 @@ namespace MultiArrayTools return *i; } - static size_t S_dim(MultiIndex* i) + static size_t S_dim(MultiIndex const* i) { return sizeof...(Indices); } - static bool S_first(MultiIndex* i) + static bool S_first(MultiIndex const* i) { return i->mPos == 0; } - static bool S_last(MultiIndex* i) + static bool S_last(MultiIndex const* i) { return i->mPos == i->mMax - 1; } + static std::shared_ptr S_range(MultiIndex const* i) + { + return std::dynamic_pointer_cast( i->mRangePtr ); + } + template - static auto S_getPtr(MultiIndex* i) -> decltype( std::get( mIPack ) )& + static auto S_getPtr(MultiIndex const* i) -> decltype( std::get( mIPack ) )& { return std::get(i->mIPack); } //const IndexBase& get(size_t n); - static std::shared_ptr S_getVPtr(MultiIndex* i, size_t n) + static std::shared_ptr S_getVPtr(MultiIndex const* i, size_t n) { if(n >= sizeof...(Indices)){ assert(0); @@ -153,7 +163,7 @@ namespace MultiArrayTools return PackNum::getIndexPtr(*t, n); } - static size_t S_getStepSize(MultiIndex* i, size_t n) + static size_t S_getStepSize(MultiIndex const* i, size_t n) { if(n >= sizeof...(Indices)){ assert(0); @@ -162,7 +172,7 @@ namespace MultiArrayTools return i->mBlockSizes[n+1]; } - static std::string S_id(MultiIndex* i) { return std::string("mul") + std::to_string(IB::mId); } + static std::string S_id(MultiIndex const* i) { return std::string("mul") + std::to_string(i->mId); } }; /************************* @@ -193,7 +203,8 @@ namespace MultiArrayTools public: typedef RangeBase RB; typedef std::tuple...> SpaceType; - typedef typename RangeInterface >::IndexType IndexType; + typedef MultiIndex IndexType; + //typedef typename RangeInterface >::IndexType IndexType; protected: MultiRange() = delete; @@ -311,6 +322,13 @@ namespace MultiArrayTools return *std::get(mIPack); } + template + template + auto MultiIndex::getPtr() const -> decltype( std::get( mIPack ) )& + { + return std::get(mIPack); + } + template MultiIndex& MultiIndex::operator()(std::shared_ptr&... indices) { @@ -413,8 +431,9 @@ namespace MultiArrayTools template std::shared_ptr MultiRange::index() const { - return std::make_shared - ( std::make_shared > + typedef IndexWrapper IW; + return std::make_shared + ( std::make_shared ( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ) ); } diff --git a/src/single_range.h b/src/single_range.h index 785427b..1d69d64 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -27,13 +27,15 @@ namespace MultiArrayTools SingleIndex(const std::shared_ptr >& range); + SingleIndex& operator=(size_t pos) { IB::operator=(pos); return *this; } + private: friend IB; // ==== >>>>> STATIC POLYMORPHISM <<<<< ==== - static IndexType S_type(SingleIndex* i) + static IndexType S_type(SingleIndex const* i) { return IndexType::SINGLE; } @@ -68,46 +70,51 @@ namespace MultiArrayTools return 1; } - static U S_meta(SingleIndex* i) + static U S_meta(SingleIndex const* i) { return std::dynamic_pointer_cast const>( i->mRangePtr )->get( i->pos() ); } static SingleIndex& S_at(SingleIndex* i, const U& metaPos) { - operator=( std::dynamic_pointer_cast const>( i->mRangePtr )->getMeta( metaPos ) ); + (*i) = std::dynamic_pointer_cast const>( i->mRangePtr )->getMeta( metaPos ); return *i; } - static size_t S_dim(SingleIndex* i) // = 1 + static size_t S_dim(SingleIndex const* i) // = 1 { return 1; } - static bool S_last(SingleIndex* i) + static bool S_last(SingleIndex const* i) { return i->mPos == i->mMax - 1; } - static bool S_first(SingleIndex* i) + static bool S_first(SingleIndex const* i) { return i->mPos == 0; } + static std::shared_ptr S_range(SingleIndex const* i) + { + return std::dynamic_pointer_cast( i->mRangePtr ); + } + template static void S_getPtr(SingleIndex* i) {} - static std::shared_ptr S_getVPtr(SingleIndex* i, size_t n) + static std::shared_ptr S_getVPtr(SingleIndex const* i, size_t n) { return std::shared_ptr(); } - static size_t S_getStepSize(SingleIndex* i, size_t n) + static size_t S_getStepSize(SingleIndex const* i, size_t n) { return 1; } - static std::string S_id(SingleIndex* i) { return std::string("sin") + std::to_string(IB::mId); } + static std::string S_id(SingleIndex const* i) { return std::string("sin") + std::to_string(i->mId); } }; template @@ -128,7 +135,8 @@ namespace MultiArrayTools { public: typedef RangeBase RB; - typedef typename RangeInterface >::IndexType IndexType; + typedef SingleIndex IndexType; + //typedef typename RangeInterface >::IndexType IndexType; virtual size_t size() const override; virtual size_t dim() const override; @@ -246,8 +254,9 @@ namespace MultiArrayTools template std::shared_ptr SingleRange::index() const { - return std::make_shared - ( std::make_shared > + typedef IndexWrapper IW; + return std::make_shared + ( std::make_shared ( std::dynamic_pointer_cast > ( std::shared_ptr( RB::mThis ) ) ) ); }