From d2a1286d170654c29eb64dff16d0c97e225f899e Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 4 Aug 2017 14:57:19 +0200 Subject: [PATCH] ... compiles now --- src/index_base.cc | 4 ++-- src/index_base.h | 7 +++--- src/index_unit_test.cc | 39 ++++++++++++++++++++---------- src/multi_range.cc | 36 +++++++++++++++++++++++----- src/multi_range.h | 7 +++++- src/pack_num.h | 54 ++++++++++++++++++++++-------------------- src/range_base.h | 4 ++-- src/single_range.cc | 14 +++++------ src/single_range.h | 9 +++---- 9 files changed, 111 insertions(+), 63 deletions(-) diff --git a/src/index_base.cc b/src/index_base.cc index a59784d..e8263fe 100644 --- a/src/index_base.cc +++ b/src/index_base.cc @@ -41,7 +41,7 @@ namespace MultiArrayTools **********************/ template - IndexInterface::IndexInterface(const RangeBase& range, size_t pos) : - IndexBase(range, pos) {} + IndexInterface::IndexInterface(const std::shared_ptr& rangePtr, size_t pos) : + IndexBase(rangePtr, pos) {} } diff --git a/src/index_base.h b/src/index_base.h index 3f31cf9..1e2ddba 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -48,10 +48,11 @@ namespace MultiArrayTools { public: - IndexInterface(const RangeBase& range, size_t pos); + DEFAULT_MEMBERS(IndexInterface); - MetaType& meta() = 0; - const MetaType& meta() const = 0; + IndexInterface(const std::shared_ptr& rangePtr, size_t pos); + virtual MetaType meta() const = 0; + virtual IndexInterface& at(const MetaType& meta) = 0; }; } diff --git a/src/index_unit_test.cc b/src/index_unit_test.cc index 7f85253..b9a6842 100644 --- a/src/index_unit_test.cc +++ b/src/index_unit_test.cc @@ -11,6 +11,21 @@ namespace MAT = MultiArrayTools; namespace { using namespace MAT; + + template + void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) + { + std::vector tmp = ilist; + auto nptr = std::make_shared( tmp ); + fptr = nptr; + } + + template + void swapMFactory(std::shared_ptr& fptr, const Rs&... rs) + { + auto nptr = std::make_shared( rs... ); + fptr = nptr; + } class IndexTest : public ::testing::Test { @@ -30,21 +45,21 @@ namespace { IndexTest() { - rfbptr.swap( std::make_shared( { 'e', 'b', 'n' } ) ); - sr1ptr = std::dynamic_pointer_cast( rfbptr.create() ); + swapFactory(rfbptr, { 'e', 'b', 'n' } ); + sr1ptr = std::dynamic_pointer_cast( rfbptr->create() ); - rfbptr.swap( std::make_shared( { 'x', 'y', 'l', 'f' } ) ); - sr2ptr = std::dynamic_pointer_cast( rfbptr.create() ); + swapFactory(rfbptr, { 'x', 'y', 'l', 'f' } ); + sr2ptr = std::dynamic_pointer_cast( rfbptr->create() ); - rfbptr.swap( std::make_shared( { 'a', 'b' } ) ); - std::shared_ptr temp1 = std::dynamic_pointer_cast( rfbptr.create() ); - rfbptr.swap( std::make_shared( { '1' } ) ); - std::shared_ptr temp2 = std::dynamic_pointer_cast( rfbptr.create() ); - rfbptr.swap( std::make_shared( { '0', '7' } ) ); - std::shared_ptr temp3 = std::dynamic_pointer_cast( rfbptr.create() ); + swapFactory(rfbptr, { 'a', 'b' } ); + std::shared_ptr temp1 = std::dynamic_pointer_cast( rfbptr->create() ); + swapFactory(rfbptr, { '1' } ); + std::shared_ptr temp2 = std::dynamic_pointer_cast( rfbptr->create() ); + swapFactory(rfbptr, { '0', '7' } ); + std::shared_ptr temp3 = std::dynamic_pointer_cast( rfbptr->create() ); - rfbptr.swap( std::make_shared( temp1, temp2, temp3 ) ); - m3rptr = std::dynamic_pointer_cast( rfbptr.create() ); + swapMFactory(rfbptr, temp1, temp2, temp3 ); + m3rptr = std::dynamic_pointer_cast( rfbptr->create() ); } std::shared_ptr rfbptr; diff --git a/src/multi_range.cc b/src/multi_range.cc index eca0b61..266dd52 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -10,9 +10,9 @@ namespace MultiArrayTools using namespace MultiArrayHelper; } - /********************** - * MultiIndexBase * - **********************/ + /****************** + * MultiIndex * + ******************/ template MultiIndex::MultiIndex(const MultiIndex& in) : @@ -123,6 +123,18 @@ namespace MultiArrayTools return *this; } + template + bool MultiIndex::first() const + { + return IB::mPos == 0; + } + + template + bool MultiIndex::last() const + { + return IB::mPos == IB::mRangePtr->size() - 1; + } + /************************* * MultiRangeFactory * *************************/ @@ -130,13 +142,13 @@ namespace MultiArrayTools template MultiRangeFactory::MultiRangeFactory(const std::shared_ptr&... rs) { - mProd = std::make_shared< MultiRange >( rs... ); + mProd = std::shared_ptr< MultiRange >( new MultiRange( rs... ) ); } template MultiRangeFactory::MultiRangeFactory(const typename MultiRange::SpaceType& st) { - mProd = std::make_shared< MultiRange >( st ); + mProd = std::shared_ptr< MultiRange >( new MultiRange( st ) ); } template @@ -159,11 +171,23 @@ namespace MultiArrayTools template template auto MultiRange::get() const -> decltype( *std::get( mSpace ) )& - //typename std::tuple_element >::type const& MultiRange::getRange() const { return *std::get(mSpace); } + template + template + auto MultiRange::getPtr() const -> decltype( std::get( mSpace ) )& + { + return std::get(mSpace); + } + + template + size_t MultiRange::dim() const + { + return sdim; + } + template size_t MultiRange::size() const { diff --git a/src/multi_range.h b/src/multi_range.h index 0448691..c4042a5 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -54,6 +54,9 @@ namespace MultiArrayTools virtual MetaType meta() const override; virtual MultiIndex& at(const MetaType& metaPos) override; + + virtual bool first() const override; + virtual bool last() const override; virtual size_t dim() const override; }; @@ -103,7 +106,9 @@ namespace MultiArrayTools template auto get() const -> decltype( *std::get( mSpace ) )&; - //typename std::tuple_element...> >::type const& getRange() const; + + template + auto getPtr() const -> decltype( std::get( mSpace ) )&; virtual size_t dim() const override; virtual size_t size() const override; diff --git a/src/pack_num.h b/src/pack_num.h index 82215dd..c3f3227 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -43,9 +43,9 @@ namespace MultiArrayHelper static inline void pp(std::tuple...>& ip) { auto& si = *std::get(ip); - if(si.pos() == si.last()){ + if(si.last()){ si = 0; - PackNum::pp(index); + PackNum::pp(ip); } else { ++si; @@ -56,9 +56,9 @@ namespace MultiArrayHelper static inline void mm(std::tuple...>& ip) { auto& si = *std::get(ip); - if(si.pos() == si.atEdge()){ + if(si.first()){ si = si.max(); - PackNum::mm(index); + PackNum::mm(ip); } else { --si; @@ -68,12 +68,12 @@ namespace MultiArrayHelper template static size_t getSize(const RangeTuple& rt) { - return std::get(rt).size() * PackNum::getSize(rt); + return std::get(rt)->size() * PackNum::getSize(rt); } - template