diff --git a/src/container_range.cc b/src/container_range.cc index 9e47e97..a8cf1b9 100644 --- a/src/container_range.cc +++ b/src/container_range.cc @@ -9,6 +9,167 @@ namespace MultiArrayTools { using namespace MultiArrayHelper; } + + /***************************** + * ContainerRangeFactory * + *****************************/ + + template + ContainerRangeFactory::ContainerRangeFactory(const std::shared_ptr&... rs) + { + mProd = std::make_shared >( rs... ); + } + template + ContainerRangeFactory::ContainerRangeFactory(const ContainerRange::SpaceType& space) + { + mProd = std::make_shared >( space ); + } + + template + std::shared_ptr ContainerRangeFactory::create() + { + setSelf(); + return mProd; + } + + /********************** + * ContainerRange * + **********************/ + + template + ContainerRange::ContainerRange(const std::shared_ptr&... rs) : + mSpace( std::make_tuple( rs... ) ) {} + + template + ContainerRange::ContainerRange(const SpaceType& space) : mSpace( space ) {} + + template + size_t ContainerRange::dim() const + { + return sizeof...(Ranges); + } + + template + size_t ContainerRange::size() const + { + return PackNum::getSize(mSpace); + } + + template + typename IndexType ContainerRange::begin() const + { + ContainerIndex + i( std::dynamic_pointer_cast >( mThis ) ); + return i = 0; + } + + template + typename IndexType ContainerRange::end() const + { + ContainerIndex + i( std::dynamic_pointer_cast >( mThis ) ); + return i = size(); + } + + template + std::shared_ptr ContainerRange::index() const + { + return std::make_shared > + ( std::dynamic_pointer_cast >( mThis ) ); + } + + + /********************** + * ContainerIndex * + **********************/ + + template + ContainerIndex::ContainerIndex(const ContainerIndex& in) : + IndexInterface >(in) + { + PackNum::copy(mIPack, in); + mPos = PackNum::makePos(mIPack); + } + + template + ContainerIndex& ContainerIndex::operator=(const ContainerIndex& in) + { + IndexI::operator=(in); + PackNum::copy(mIPack, in); + mPos = PackNum::makePos(mIPack); + return *this; + } + + template + template + ContainerIndex::ContainerIndex(const std::shared_ptr& range) + { + PackNum::construct(mIPack, *range); + mPos = PackNum::makePos(mIPack); + } + + template + ContainerIndex& ContainerIndex::operator++() + { + PackNum::pp( mIPack ); + ++mPos; + return *this; + } + + template + ContainerIndex& ContainerIndex::operator--() + { + PackNum::mm( mIPack ); + --mPos; + return *this; + + } + + template + ContainerIndex& ContainerIndex::operator=(size_t pos) + { + mPos = pos; + PackNum::setIndexPack(mIPack, pos); + return *this; + } + + template + typename ContainerIndex::MetaType ContainerIndex::meta() const + { + MetaType metaTuple; + PackNum::getMetaPos(metaTuple, mIPack); + return metaTuple; + } + + template + ContainerIndex& ContainerIndex::at(const MetaType& metaPos) + { + PackNum::setMeta(mIPack, metaPos); + return *this; + } + + template + size_t ContainerIndex::dim() const + { + return sizeof...(Indices); + } + + template + size_t ContainerIndex::pos() const + { + if(mExternControl){ + mPos = PackNum::makePos(mIPack); + } + return mPos; + } + + template + ContainerIndex& ContainerIndex::operator()(const std::shared_ptr&... inds) + { + PackNum::swapIndices(mIPack, inds...); + mExternControl = true; + return *this; + } } // end namespace MultiArrayTools diff --git a/src/container_range.h b/src/container_range.h index c687751..a31b969 100644 --- a/src/container_range.h +++ b/src/container_range.h @@ -15,9 +15,9 @@ namespace MultiArrayTools public: ContainerRangeFactory() = delete; - ContainerRangeFactory(const std::shared_ptr& rs); + ContainerRangeFactory(const std::shared_ptr&... rs); ContainerRangeFactory(const ContainerRange::SpaceType& space); - + virtual std::shared_ptr create() override; protected: @@ -49,7 +49,7 @@ namespace MultiArrayTools ContainerRange() = default; ContainerRange(const ContainerRange& in) = delete; - ContainerRange(const std::shared_ptr& rs); + ContainerRange(const std::shared_ptr&... rs); ContainerRange(const SpaceType& space); SpaceType mSpace; @@ -84,8 +84,8 @@ namespace MultiArrayTools ContainerIndex& operator()(const std::shared_ptr&... inds); // control via external indices protected: - - bool externControl = false; + + bool mExternControl = false; IndexPack mIPack; }; diff --git a/src/multi_range.cc b/src/multi_range.cc index f3cab13..8aa5fa6 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -69,7 +69,7 @@ namespace MultiArrayTools MultiIndex& MultiIndex::up() { static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices"); - mPos += /*!!!*/; + mPos += PackNum::blockSize( mIPack ); PackNum::pp( mIPack ); return *this; } @@ -79,7 +79,7 @@ namespace MultiArrayTools MultiIndex& MultiIndex::down() { static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices"); - mPos -= /*!!!*/; + mPos -= PackNum::blockSize( mIPack ); PackNum::mm( mIPack ); return *this; } diff --git a/src/pack_num.h b/src/pack_num.h index 4236a81..7822390 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -9,8 +9,8 @@ namespace MultiArrayHelper template struct PackNum { - template - static IndexBase& getIndex(MultiIndex& in, size_t n) + template + static IndexBase& getIndex(IndexType& in, size_t n) { if(n == N){ return in.getIndex(); @@ -20,8 +20,8 @@ namespace MultiArrayHelper } } - template - static const IndexBase& getIndex(const MultiIndex& in, size_t n) + template + static const IndexBase& getIndex(const IndexType& in, size_t n) { if(n == N){ return in.getIndex(); @@ -63,17 +63,16 @@ namespace MultiArrayHelper return std::get(rt).size() * PackNum::getSize(rt); } - template + template