diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index ce7a328..cc8720e 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -81,27 +81,35 @@ namespace CNORXZ * MIndex * **************/ + template + MIndex::MIndex(const MIndex& i) : + IndexInterface,Tuple>(i.pos()), + mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), + mBlockSizes(mkBlockSizes(), Isqr<0,NI>{}), + mRange(i.range()) + {} + + template + MIndex& MIndex::operator=(const MIndex& i) + { + IndexInterface,Tuple>::operator=(i); + mIPack = mkIPack(IB::mPos, Isqr<0,NI>{}); + mBlockSizes(mkBlockSizes(), Isqr<0,NI>{}); + mRange = i.range(); + return *this; + } + template template MIndex::MIndex(const Sptr& range, SizeT pos) : IndexInterface,Tuple>(0), mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), - mBlockSizes(mkBlockSizes(IB::mPos), Isqr<0,NI>{}), + mBlockSizes(mkBlockSizes(), Isqr<0,NI>{}), mRange(range), { (*this) = pos; } - template - MIndex& MIndex::operator()(const Sptr& mi) - { - mIPack = mi.mIPack; - IB::mPos = iter<0,NI> - ( [&](auto i) { return std::get(mIPack)*std::get(mBlockSizes); }, - [](const auto&... xs) { return (xs + ...); }); - return *this; - } - template MIndex& MIndex::operator=(SizeT pos) { @@ -130,6 +138,93 @@ namespace CNORXZ return *this; } + template + MIndex MIndex::operator+(Int n) const + { + MIndex o(*this); + return o += n; + } + + template + MIndex MIndex::operator-(Int n) const + { + MIndex o(*this); + return o -= n; + } + + template + MIndex& MIndex::operator+=(Int n) + { + if(-n > IB::mPos){ + (*this) = 0; + } + const SizeT p = IB::mPos + n; + if(p > max()){ + (*this) = max(); + } + (*this) = p; + return *this; + } + + template + MIndex& MIndex::operator-=(Int n) + { + if(n > IB::mPos){ + (*this) = 0; + } + const SizeT p = IB::mPos + n; + if(p > max()){ + (*this) = max(); + } + (*this) = p; + return *this; + } + + template + SizeT MIndex::max() const + { + return mRange->size(); + } + + template + IndexId<0> MIndex::id() const + { + return IndexId<0>(this->ptrId()); + } + + template + MetaType MIndex::operator*() const + { + return meta(); + } + + template + MetaType MIndex::operator->() const + { + return meta(); + } + + template + SizeT MIndex::dim() const + { + return NI; + } + + template + Sptr MIndex::range() const + { + return mRange; + } + + template + template + decltype(auto) MIndex::stepSize(const IndexId& id) const; + { + return iter<0,NI> + ( [&](auto i) { return std::get(mIPack)->stepSize(id) * std::get(mBlockSize); }, + [](const auto&... ss) { return ( ss + ... ); }); + } + template String MIndex::stringMeta() const { @@ -160,34 +255,35 @@ namespace CNORXZ return *this; } - template - SizeT MIndex::dim() - { - return NI; - } - - template - Sptr::RangeType> - MIndex::range() - { - return std::dynamic_pointer_cast( mRangePtr ); - } - - template - template - decltype(auto) MIndex::stepSize(const IndexId& id) const; - { - return iter<0,NI> - ( [&](auto i) { return std::get(mIPack)->stepSize(id) * std::get(mBlockSize); }, - [](const auto&... ss) { return ( ss + ... ); }); - } - template template constexpr decltype(auto) MIndex::ifor(const Xpr& xpr, F&& f) const { return mkIFor<0>(xpr, f); } + + template + MIndex& MIndex::operator()(const Sptr& mi) + { + mIPack = mi.mIPack; + IB::mPos = iter<0,NI> + ( [&](auto i) { return std::get(mIPack)*std::get(mBlockSizes); }, + [](const auto&... xs) { return (xs + ...); }); + return *this; + } + + template + const IndexPack& pack() const + { + return mIPack; + } + + template + const auto& blockSizes() const + { + return mBlockSizes; + } + /********************* * MRangeFactory * diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 0b584f0..e8ec9a3 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -26,19 +26,14 @@ namespace CNORXZ // NO DEFAULT HERE !!! // ( have to assign sub-indices (ptr!) correctly ) + MIndex() = default; MIndex(const MIndex& i); MIndex(MIndex&& i); - MIndex& operator=(const MIndex& i); - MIndex& operator=(MIndex&& i); + MIndex& operator=(const MIndex& i) = default; + MIndex& operator=(MIndex&& i) = default; MIndex(const RangePtr& range, SizeT pos = 0); - // replace sub-index instances; only use if you know what you are doing! - MIndex& operator()(const Sptr& mi); - - const IndexPack& pack() const { return mIPack; } - const auto& getBlockSizes() const { return mBlockSizes; } - MIndex& operator=(SizeT pos); MIndex& operator++(); MIndex& operator--(); @@ -46,29 +41,33 @@ namespace CNORXZ MIndex operator-(Int n) const; MIndex& operator+=(Int n); MIndex& operator-=(Int n); - - SizeT max() const; - decltype(auto) id() const; - - SizeT operator*() const; - SizeT operator->() const; - SizeT dim(); - Sptr range(); + SizeT max() const; + IndexId<0> id() const; + + MetaType operator*() const; + MetaType operator->() const; + + SizeT dim() const + Sptr range() const; template decltype(auto) stepSize(const IndexId& id) const; - + String stringMeta() const; MetaType meta() const; MIndex& at(const MetaType& metaPos); - + template constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; + // replace sub-index instances; only use if you know what you are doing! + MIndex& operator()(const Sptr& mi); + + const IndexPack& pack() const; + const auto& blockSizes() const; + private: - MIndex() = default; - IndexPack mIPack; typedef decltype(mkBlockSizes(Isqr<0,NI-1>{})) BlockTuple; BlockTuple mBlockSizes;