diff --git a/src/include/base/types.h b/src/include/base/types.h index 385e664..f66f028 100644 --- a/src/include/base/types.h +++ b/src/include/base/types.h @@ -81,27 +81,45 @@ namespace CNORXZ template class Allocator; - // definition: ranges/xfor/exttype.h - class VPosBase; + // definition: ranges/xfor/pos_type.h + template + class CPosInterface; - // definition: ranges/xfor/exttype.h + // definition: ranges/xfor/pos_type.h template class PosInterface; - // definition: ranges/xfor/exttype.h - class DPos; + // definition: ranges/xfor/pos_type.h + class VPosBase; - // definition: ranges/xfor/exttype.h + // definition: ranges/xfor/pos_type.h template class VPos; - // definition: ranges/xfor/exttype.h + // definition: ranges/xfor/pos_type.h + template + class VPosRef; + + // definition: ranges/xfor/pos_type.h + class DPos; + + // definition: ranges/xfor/pos_type.h + class DPosRef; + + // definition: ranges/xfor/pos_type.h template class MPos; - // definition: ranges/xfor/exttype.h - class NPos; - + // definition: ranges/xfor/pos_type.h + template + class FMPos; + + // definition: ranges/xfor/pos_type.h + class UPos; + + // definition: ranges/xfor/pos_type.h + class FPos; + // definition: ranges/range_base.h class RangeBase; @@ -171,6 +189,10 @@ namespace CNORXZ class PIndex; // partial index (index over sub-ranges and permutations) // there should be also a static analogue + + // definition: ranges/lindex.h + template + class LIndex; /********************* * derived types * diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 1a3bdbf..d9245db 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -36,7 +36,6 @@ namespace CNORXZ SizeT dim() const; // = 1 Sptr range() const; SizeT getStepSize(PtrId iptr) const; - Int getOffset(PtrId iptr) const; String stringMeta() const; SizeT meta() const; diff --git a/src/include/ranges/lindex.cc.h b/src/include/ranges/lindex.cc.h new file mode 100644 index 0000000..2370389 --- /dev/null +++ b/src/include/ranges/lindex.cc.h @@ -0,0 +1,36 @@ + +#include "lindex.h" + +namespace CNORXZ +{ + template + LIndex::LIndex(const Index& i) : + Index(i) {} + + template + LIndex::LIndex(Index&& i) : + Index(i) {} + + template + template + auto LIndex::getStaticStepSize(PtrId iptr) const + { + if constexpr(L == 0 or L1 == 0){ + return this->getStepSize(iptr); + } + else { + if constexpr(L == L1){ + CXZ_ASSERT(iptr == this->ptrId(), + "got two different indices with the same static label " << L); + return SPos<1>(); + } + else { + CXZ_ASSERT(iptr == this->ptrId(), + "got two equal indices with the different static label " << L + << " and " << L1); + return SPos<0>(); + } + } + } + +} diff --git a/src/include/ranges/lindex.h b/src/include/ranges/lindex.h new file mode 100644 index 0000000..3933658 --- /dev/null +++ b/src/include/ranges/lindex.h @@ -0,0 +1,29 @@ + +#ifndef __cxz_lindex_h__ +#define __cxz_lindex_h__ + +#include "base/base.h" +#include "ranges/index_base.h" +#include "ranges/range_base.h" + +namespace CNORXZ +{ + // static label to enforce loop unrolling + template + class LIndex : public Index + { + public: + typedef Index::IB IB; + typedef Index::RangeType RangeType; + + DEFAULT_MEMBERS(LIndex); + LIndex(const Index& i); + LIndex(Index&& i); + + template + auto getStaticStepSize(PtrId iptr) const; + + }; +} + +#endif diff --git a/src/include/ranges/xfor/exttype.h b/src/include/ranges/xfor/exttype.h deleted file mode 100644 index 86c6caf..0000000 --- a/src/include/ranges/xfor/exttype.h +++ /dev/null @@ -1,427 +0,0 @@ - -#ifndef __cxz_exttype_h__ -#define __cxz_exttype_h__ - -#include "base/base.h" - -namespace CNORXZ -{ - - // Dynamic Ext: ObjHandl - // In For Expr: try to resolve until some upper limit - - class VPosBase - { - public: - DEFAULT_MEMBERS(VPosBase); - - virtual Uptr copy() const = 0; - virtual SizeT vsize() const = 0; - virtual const SizeT& vval() const = 0; - virtual const VPosBase* vnext() const = 0; - virtual Uptr vplus(const VPosBase* a) const = 0; - virtual Uptr vtimes(SizeT a) const = 0; - virtual Uptr vextend(const DPos& a) const = 0; - virtual Uptr vextend(const UPos& a) const = 0; - virtual Uptr vextend(const FPos& a) const = 0; - }; - - template - class CPosInterface - { - public: - DEFAULT_MEMBERS(CPosInterface); - - PosT& THIS() { return static_cast(*this); } - const PosT& THIS() const { return static_cast(*this); } - - inline SizeT size() const { return THIS().size(); } - inline const SizeT& val() const { return THIS().val(); } - inline const auto& next() const { return THIS().next(); } - inline bool operator==(const CPosInterface& a) const { return val() == a.val() and next() == a.next(); } - inline bool operator!=(const CPosInterface& a) const { return val() != a.val() or next() != a.next(); } - inline bool operator==(SizeT a) const { return val() == a and next() == a; } - inline bool operator!=(SizeT a) const { return val() != a or next() != a; } - inline CPosInterface operator+(const CPosInterface& a) const - { return THIS() + a.THIS(); } - inline CPosInterface operator*(SizeT a) const { return THIS() * a; } - - template - inline auto extend(const CPosInterface

& a) const { return THIS().extend(a); } - }; - - template - class PosInterface : public CPosInterface - { - public: - typedef CPosInterface PI; - - DEFAULT_MEMBERS(PosInterface); - - template - inline PosInterface& set(const CPosInterface& a, const CPosInterface& b, sizeT c) - { return PI::THIS().set(a,b,c); } - - template - inline PosInterface& operator()(const CPosInterface& a, const CPosInterface& b, sizeT c) - { return set(a,b,c); } - }; - - template - class VPos : public VPosBase, public PosT - { - private: - VPosRef mNextRef; - public: - - DEFAULT_MEMBERS(VPos); - - VPos(const PosInterface& a) : PosT(a.THIS()), mNextRef(&PosT::THIS().next()) {} - - virtual Uptr copy() const override final { return std::make_unique(*this); } - virtual SizeT vsize() const override final { return PosT::THIS().size(); } - virtual const SizeT& vval() const override final { return PosT::THIS().val(); } - virtual const VPosRef& vnext() const override final - { return mNextRef; } - virtual Uptr vextend(const DPos& a) const override final - { return std::make_unique> - ( PosT::THIS().extend(a) ); } - virtual Uptr vextend(const UPos& a) const override final - { return std::make_unique> - ( PosT::THIS().extend(a) ); } // ??? if that works it would be a miracle ??? - virtual Uptr vextend(const FPos& a) const override final - { return std::make_unique> - ( PosT::THIS().extend(a) ); } // ??? if that works it would be a miracle ??? - // .... probably I need to define a static instanciation limit... - - }; - - template - class VPosRef : public VPosBase - { - private: - const PosT* mC; - public: - DEFAULT_MEMBERS(VPosRef); - - VPosRef(const PosT* c) : mC(c) {} - }; - - // defined as empty since they should never instanciated - template <> - class VPos - {}; - - // defined as empty since they should never instanciated - template <> - class VPos - {}; - - class DPosRef : public CPosInterface - { - private: - DPosRef mNextRef; - const VPosBase* mC; - public: - DEFAULT_MEMBERS(DPosRef); - DPosRef(const VPosBase* c) : mC(c), mNextRef(mC->vnext()) {} - - const T& operator*() const { return *mC; } - const T* operator->() const { return mC; } - - inline sizeT size() const { return mC->vsize(); } - inline const SizeT& val() const { return mC->vsize(); } - inline const DPosRef& next() const { return mNextRef; } - - template - inline auto operator+(const MPos& a) const - { return MPos(val()+a.val(), next()+a.next()); } - - inline auto operator+(const UPos& a) const - { return UPos(val()+a.val()); } - - inline auto operator+(const DPos& a) const - { return DPos((*mC)+(*a)); } - - inline auto operator+(const DPosRef& a) const - { return DPos((*mC)+(*a)); } - - inline auto operator*(SizeT a) const - { return DPos((*mC)*a); } - - }; - - class DPos : public ObjHandle, - public PosInterface - { - private: - DPosRef mNextRef; - public: - DEFAULT_MEMBERS(DPos); - DPos(Uptr&& a) : - ObjHandle(std::forward>(a)), - mNextRef(mC->next()) - {} - - template - DPos(const PosT& a) : ObjHandle( std::make_unique(a) ) {} - - inline SizeT size() const { return mC->vsize(); } - inline const SizeT& val() const { return mC->vval(); } - inline const DPosRef& next() const { return mNextRef; } - - template - inline auto operator+(const MPos& a) const - { return MPos(val()+a.val(), next()+a.next()); } - - inline auto operator+(const UPos& a) const - { return UPos(mC->val() + a.val()); } - - inline auto operator+(const DPos& a) const - { return DPos((*mC) + (*a)); } - - inline auto operator+(const DPosRef& a) const - { return DPos((*mC) + (*a)); } - - inline auto operator*(SizeT a) const - { return DPos((*mC)*a); } - - template - inline PosInterface& set(const CPosInterface& a, const CPosInterface& b, sizeT c) - { mC->setVal( a.val() + b.val()*c ) ; mC->vnext()->set(a.next(),b.next(),c); return *this; } - }; - - template - class MPos - { - private: - - SizeT mExt = 0u; - PosT mNext; - - public: - - //static constexpr SizeT NUM = PosT::SIZE; - //static constexpr SizeT SIZE = NUM + 1; - - DEFAULT_MEMBERS(MPos); - - inline MPos(SizeT ext, PosT next); - - template - inline MPos(SizeT y, const CPosInterface& z); - - template - inline MPos(const CPosInterface& y, const CPosInterface& z); - - template - inline MPos(const MPos& y); - - inline const SizeT& val() const; - inline const PosT& next() const; - - inline auto operator+(const MPos& in) const; - //inline MPos operator+(const UPos& in) const; - inline auto operator*(SizeT in) const; - - template - inline auto extend(const PosInterface& y) const -> MPos - { return MPos(mExt, mNext.extend(y)); } - - template - inline PosInterface& set(const CPosInterface& a, const CPosInterface& b, sizeT c) - { return *this = a + b*c; } - //{ mExt = a.val() + b.val()*c ; mNext.set(a.next(),b.next(),c); return *this; } - }; - - template - class FMPos : public PosInterface> - { - private: - SizeT mExt = 0; - const Vector* mMap; - PosT mNext; - - public: - - DEFAULT_MEMBERS(FMPos); - - template - inline auto operator+(const PosT2& a) const { return MPos(mExt,mNext) + a; } - - inline auto operator*(SizeT a) const { return MPos(mExt*(*mMap)[a], mNext*a); } - }; - - class UPos : public PosInterface - { - private: - SizeT mExt = 0; - public: - - DEFAULT_MEMBERS(NPos); - - template - NPos(const Y& y) {} - - //static constexpr SizeT SIZE = 0; - - inline const SizeT& val() const { return mExt; } - inline SizeT size() const { return 1; } - inline const SizeT& next() { static SizeT dummy = 0; return dummy; } - inline UPos operator+(const UPos& in) const { return UPos(mExt + in.val()); } - inline UPos operator*(size_t in) const { return UPos(mExt * in); } - - template - inline auto extend(const Y& y) const - { return MPos(mExt, y); } - - }; - - class FPos : public PosInterface - { - private: - SizeT mExt = 0; - const Vector* mMap; - - public: - - DEFAULT_MEMBERS(FMPos); - - template - inline auto operator+(const PosT2& a) const { return UPos(mExt) + a; } - - inline auto operator*(SizeT a) const { return UPos(mExt*(*mMap)[a]); } - }; - - inline MPos mkExt(SizeT s) { return MPos(s); } - - /* - template - auto getX(const MPos& et) - { - if constexpr(I == 0){ - return et; - } - else { - return getX(et.next()); - } - } - - template - auto getX(const DVPosX& et) - { - if constexpr(I == 0){ - return et; - } - else { - return getX(et.next()); - } - } - - template - auto getX(const NPos& et) - { - static_assert(I == 0); - return et; - } - - template - size_t get(const MPos& et) - { - return getX(et).get(); - } - - template - size_t get(const DVPosX& et) - { - return getX(et).get(); - } - - template - size_t get(const NPos& et) - { - return getX(et).get(); - } - */ - -} // end namespace CNORXZInternal - -/* ========================= * - * --- TEMPLATE CODE --- * - * ========================= */ - -namespace CNORXZ -{ - - template - inline MPos::MPos(size_t ext, X next) : mExt(ext), mNext(next) {} - /* - template - template - inline MPos::MPos(const std::array& arr) : - mExt(std::get(arr)), mNext(arr) {} - */ - template - template - inline MPos::MPos(size_t y, const Z& z) : - mExt(z.val()), mNext(z.val(), z.next()) {} - - template - template - inline MPos::MPos(const Y& y, const Z& z) : - mExt(y.val()), mNext(y.next(), z) {} - - template - template - inline MPos::MPos(const MPos& y) : - mExt(y.val()), mNext(y.next()) {} - - template - inline const size_t& MPos::val() const - { - return mExt; - } - - template - inline const X& MPos::next() const - { - return mNext; - } - - template - inline void MPos::zero() - { - mExt = 0u; - mNext.zero(); - } - /* - template - template - inline auto MPos::nn() const - { - return getX(*this); - } - */ - template - inline MPos MPos::operator+(const MPos& in) const - { - return MPos(mExt + in.val(), mNext + in.next()); - } - - template - inline MPos MPos::operator+(const UPos& in) const - { - return MPos(mExt + in.val(), mNext); - } - - template - inline MPos MPos::operator*(SizeT in) const - { - return MPos(mExt * in, mNext * in); - } - - -} // end namespace CNORXZInternal - - -#endif diff --git a/src/include/ranges/xfor/pos_type.cc.h b/src/include/ranges/xfor/pos_type.cc.h new file mode 100644 index 0000000..e373f81 --- /dev/null +++ b/src/include/ranges/xfor/pos_type.cc.h @@ -0,0 +1,382 @@ + +#ifndef __cxz_pos_type_cc_h__ +#define __cxz_pos_type_cc_h__ + +#include "pos_type.h" + +namespace CNORXZ +{ + + /************ + * SPos * + ************/ + + template + constexpr SizeT SPos::size() const + { + return 1; + } + + template + constexpr SizeT SPos::val() const + { + return N; + } + + template + template + constexpr auto SPos::operator+(const SPos& a) const + { + return SPos(); + } + + template + template + constexpr auto SPos::operator*(const SPos& a) const + { + return SPos(); + } + + template + constexpr auto SPos::operator+(const UPos& a) const + { + return UPos(N+a.val()); + } + + template + constexpr auto SPos::operator*(const UPos& a) const + { + return UPos(N*a.val()); + } + + template + template + constexpr auto SPos::extend(const CPosInterface& a) const + { + return MPos,PosT>(*this,a); + } + + /************ + * UPos * + ************/ + + constexpr UPos::UPos(SizeT ext) : mExt(ext) {} + + inline SizeT UPos::size() const + { + return 1; + } + + inline const SizeT& UPos::val() const + { + return mExt; + } + + template + constexpr UPos UPos::operator+(const CPosInterface& in) const + { + return UPos(mExt + in.val()); + } + + template + constexpr UPos UPos::operator*(const CPosInterface& in) const + { + return UPos(mExt * in.val()); + } + + template + constexpr auto UPos::extend(const CPosInterface& p1) const + { + return MPos(*this, p1); + } + + template + inline UPos& UPos::set(const CPosInterface& a, const CPosInterface& b, + const CPosInterface& c) + { + (*this) = a + b*c; + return *this; + } + + /************ + * FPos * + ************/ + + inline FPos::FPos(SizeT ext, const SizeT* map) : mExt(ext), mMap(map) {} + + constexpr SizeT FPos::size() const + { + return 1; + } + + inline const SizeT& FPos::val() const + { + return mExt; + } + + template + inline UPos FPos::operator+(const CPosInterface& a) const + { + return UPos(mExt + a.val()); + } + + inline UPos FPos::operator*(const CPosInterface& a) const + { + return UPos(mExt * mMap[a.val()]); + } + + template + inline auto FPos::extend(const CPosInterface& a) const + { + return MPos(*this,a); + } + + /************* + * SFPos * + *************/ + + template + constexpr SizeT SFPos::size() const + { + return 1; + } + + template + constexpr SizeT SFPos::val() const + { + return N; + } + + template + template + constexpr auto SFPos::operator+(const SPos& a) const + { + return SPos(); + } + + template + template + constexpr auto SFPos::operator*(const SPos& a) const + { + static constexpr Array ms({ Ms... }); + return SPos(ms)>; + } + + template + constexpr auto SFPos::operator+(const UPos& a) const + { + return UPos(N + a.val()); + } + + template + constexpr auto SFPos::operator*(const UPos& a) const + { + static constexpr Array ms({ Ms... }); + return UPos(N * ms[a.val()]); + } + + template + template + constexpr auto SFPos::extend(const CPosInterface& a) const + { + return MPos,PosT>(*this,a); + } + + + /************ + * DPos * + ************/ + + inline DPos::DPos(Uptr&& a) : + ObjHandle(std::forward>(a)), + mNextRef(mC->next()) + {} + + template + inline DPos::DPos(const PosT& a) : + ObjHandle( std::make_unique(a) ) + {} + + inline SizeT DPos::size() const + { + return mC->vsize(); + } + + inline const SizeT& DPos::val() const + { + return mC->vval(); + } + + inline const DPosRef& DPos::next() const + { + return mNextRef; + } + + template + inline auto DPos::operator+(const MPos& a) const + { + return MPos(val()+a.val(), next()+a.next()); + } + + inline auto DPos::operator+(const UPos& a) const + { + return UPos(mC->val() + a.val()); + } + + inline auto DPos::operator+(const DPos& a) const + { + return DPos((*mC) + (*a)); + } + + inline auto DPos::operator+(const DPosRef& a) const + { + return DPos((*mC) + (*a)); + } + + inline auto DPos::operator*(SizeT a) const + { + return DPos((*mC)*a); + } + + template + inline DPos DPos::extend(const PosT1& a) const + { + Uptr out = mC->vextend() + + } + + template + inline PosInterface& DPos::set(const CPosInterface& a, const CPosInterface& b, sizeT c) + { + mC->setVal( a.val() + b.val()*c ) ; + mC->vnext()->set(a.next(),b.next(),c); + return *this; + } + + /*************** + * DPosRef * + ***************/ + + inline DPosRef::DPosRef(const VPosBase* c) : + mC(c), mNextRef(mC->vnext()) + {} + + inline const T& DPosRef::operator*() const + { + return *mC; + } + + inline const T* DPosRef::operator->() const + { + return mC; + } + + inline sizeT DPosRef::size() const + { + return mC->vsize(); + } + + inline const SizeT& DPosRef::val() const + { + return mC->vsize(); + } + + inline const DPosRef& DPosRef::next() const + { + return mNextRef; + } + + template + inline auto DPosRef::operator+(const MPos& a) const + { + return MPos(val()+a.val(), next()+a.next()); + } + + inline auto DPosRef::operator+(const UPos& a) const + { + return UPos(val()+a.val()); + } + + inline auto DPosRef::operator+(const DPos& a) const + { + return DPos((*mC)+(*a)); + } + + inline auto DPosRef::operator+(const DPosRef& a) const + { + return DPos((*mC)+(*a)); + } + + inline auto DPosRef::operator*(SizeT a) const + { + return DPos((*mC)*a); + } + + /************ + * MPos * + ************/ + + template + inline MPos::MPos(SizeT ext, PosT next) : mExt(ext), mNext(next) {} + + template + template + inline MPos::MPos(SizeT y, const PosT1& z) : + mExt(z.val()), mNext(z.val(), z.next()) {} + + template + template + inline MPos::MPos(const PosT1& y, const PosT2& z) : + mExt(y.val()), mNext(y.next(), z) {} + + template + template + inline MPos::MPos(const MPos& y) : + mExt(y.val()), mNext(y.next()) {} + + template + inline const SizeT& MPos::val() const + { + return mExt; + } + + template + inline const PosT& MPos::next() const + { + return mNext; + } + + template + inline MPos MPos::operator+(const MPos& in) const + { + return MPos(mExt + in.val(), mNext + in.next()); + } + + template + inline MPos MPos::operator+(const UPos& in) const + { + return MPos(mExt + in.val(), mNext); + } + + template + inline MPos MPos::operator*(SizeT in) const + { + return MPos(mExt * in, mNext * in); + } + + template + template + inline auto MPos::extend(const PosInterface& y) const + { return MPos(mExt, mNext.extend(y)); } + + template + template + inline PosInterface& MPos::set(const CPosInterface& a, + const CPosInterface& b, sizeT c) + { return *this = a + b*c; } + //{ mExt = a.val() + b.val()*c ; mNext.set(a.next(),b.next(),c); return *this; } + + +} + +#endif diff --git a/src/include/ranges/xfor/pos_type.h b/src/include/ranges/xfor/pos_type.h new file mode 100644 index 0000000..51f0439 --- /dev/null +++ b/src/include/ranges/xfor/pos_type.h @@ -0,0 +1,238 @@ + +#ifndef __cxz_pos_type_h__ +#define __cxz_pos_type_h__ + +#include "base/base.h" + +namespace CNORXZ +{ + + template + class CPosInterface + { + public: + DEFAULT_MEMBERS(CPosInterface); + + PosT& THIS() { return static_cast(*this); } + const PosT& THIS() const { return static_cast(*this); } + + inline SizeT size() const { return THIS().size(); } + inline auto val() const { return THIS().val(); } + inline CPosInterface operator+(const CPosInterface& a) const + { return THIS() + a.THIS(); } + inline CPosInterface operator*(const CPosInterface& a) const + { return THIS() * a.THIS(); } + + template + inline auto extend(const CPosInterface

& a) const { return THIS().extend(a); } + }; + + template + class PosInterface : public CPosInterface + { + public: + typedef CPosInterface PI; + + DEFAULT_MEMBERS(PosInterface); + + template + inline PosInterface& set(const CPosInterface& a, const CPosInterface& b, + const CPosInterface& c) + { return PI::THIS().set(a,b,c); } + + template + inline PosInterface& operator()(const CPosInterface& a, const CPosInterface& b, + const CPosInterface& c) + { return set(a,b,c); } + }; + + template + class SPos : public CPosInterface + { + public: + constexpr SPos() = default; + + constexpr SizeT size() const; + constexpr SizeT val() const; + + template + constexpr auto operator+(const SPos& a) const; + template + constexpr auto operator*(const SPos& a) const; + + constexpr auto operator+(const UPos& a) const; + constexpr auto operator*(const UPos& a) const; + + template + constexpr auto extend(const CPosInterface& a) const; + }; + + class UPos : public PosInterface + { + private: + SizeT mExt = 0; + public: + + DEFAULT_MEMBERS(UPos); + + constexpr UPos(SizeT ext); + + inline SizeT size() const; + inline const SizeT& val() const; + + template + constexpr UPos operator+(const CPosInterface& a) const; + + template + constexpr UPos operator*(const CPosInterface& a) const; + + template + constexpr auto extend(const CPosInterface& y) const; + + template + inline UPos& set(const CPosInterface& a, const CPosInterface& b, + const CPosInterface& c); + }; + + class FPos : public CPosInterface + { + private: + SizeT mExt = 0; + const SizeT* mMap = nullptr; + + public: + DEFAULT_MEMBERS(FPos); + + inline FPos(SizeT ext, const SizeT* map); + + constexpr SizeT size() const; + inline const SizeT& val() const; + + template + inline UPos operator+(const CPosInterface& a) const; + + template + inline UPos operator*(const CPosInterface& a) const; + + template + inline auto extend(const CPosInterface& a) const; + }; + + template + class SFPos : public CPosInterface + { + public: + constexpr SFPos() = default; + + constexpr SizeT size() const; + constexpr SizeT val() const; + + template + constexpr auto operator+(const SPos& a) const; + template + constexpr auto operator*(const SPos& a) const; + + constexpr auto operator+(const UPos& a) const; + constexpr auto operator*(const UPos& a) const; + + template + constexpr auto extend(const CPosInterface& a) const; + }; + + class DPos : public ObjHandle, + public PosInterface + { + private: + DPosRef mNextRef; + public: + DEFAULT_MEMBERS(DPos); + inline DPos(Uptr&& a); + + template + inline DPos(const PosT& a); + + inline SizeT size() const; + inline const SizeT& val() const; + inline const DPosRef& next() const; + + template + inline auto operator+(const MPos& a) const; + + inline auto operator+(const UPos& a) const; + inline auto operator+(const DPos& a) const; + inline auto operator+(const DPosRef& a) const; + inline auto operator*(SizeT a) const; + + template + inline DPos extend(const PosT1& a) const; + + template + inline PosInterface& set(const CPosInterface& a, + const CPosInterface& b, sizeT c); + }; + + class DPosRef : public CPosInterface + { + private: + DPosRef mNextRef; + const VPosBase* mC; + public: + DEFAULT_MEMBERS(DPosRef); + inline DPosRef(const VPosBase* c); + + inline const T& operator*() const; + inline const T* operator->() const; + + inline sizeT size() const; + inline const SizeT& val() const; + inline const DPosRef& next() const; + + template + inline auto operator+(const MPos& a) const; + + inline auto operator+(const UPos& a) const; + inline auto operator+(const DPos& a) const; + inline auto operator+(const DPosRef& a) const; + inline auto operator*(SizeT a) const; + + template + inline DPos extend(const PosT1& a) const; + }; + + template + class MPos : public PosInterface> + { + private: + + PosT1 mFirst; + PosT2 mNext; + + public: + + //static constexpr SizeT NUM = PosT::SIZE; + //static constexpr SizeT SIZE = NUM + 1; + + DEFAULT_MEMBERS(MPos); + + constexpr MPos(const CPosInterface& first, + const CPosInterface& next); + + inline const SizeT& val() const; + inline const PosT& next() const; + + inline auto operator+(const MPos& in) const; + inline auto operator*(SizeT in) const; + + template + inline auto extend(const PosInterface& y) const; + + template + inline PosInterface& set(const CPosInterface& a, + const CPosInterface& b, sizeT c); + }; + + +} // end namespace CNORXZInternal + + +#endif diff --git a/src/include/ranges/xfor/vpos_type.cc.h b/src/include/ranges/xfor/vpos_type.cc.h new file mode 100644 index 0000000..4e42dd8 --- /dev/null +++ b/src/include/ranges/xfor/vpos_type.cc.h @@ -0,0 +1,262 @@ + +#ifndef __cxz_vpos_type_cc_h__ +#define __cxz_vpos_type_cc_h__ + +#include "vpos_type.h" + +namespace CNORXZ +{ + /**************** + * VPosBase * + ****************/ + + template + UPtr VPosBase::vextend(const SPos& a) const + { + return this->vextend(UPos(N)); + } + + /************ + * VPos * + ************/ + + template + VPos::VPos(const PosInterface& a) : + PosT(a.THIS()), + {} + + template + Uptr VPos::copy() const + { + return std::make_unique(*this); + } + + template + SizeT VPos::vsize() const + { + return PosT::THIS().size(); + } + + template + const SizeT& VPos::vval() const + { + return PosT::THIS().val(); + } + + template + const VPosBase* VPos::vget() const + { + return this; + } + + template + const VPosBase* VPos::vnext() const + { + return nullptr; + } + + template + Uptr VPos::vextend(const DPos& a) const + { + return std::make_unique>(*this,a); + } + + template + Uptr VPos::vextend(const UPos& a) const + { + return std::make_unique>(*this,a); + } + + template + Uptr VPos::vextend(const FPos& a) const + { + return std::make_unique>(*this,a); + } + // .... probably I need to define a static instanciation limit... + + /****************** + * VPos * + ******************/ + + template + VPos>::VPos(const PosInterface>& a) : + MPos(a.THIS()), + mFRef(&mFirst), mNRef(&mNext) + {} + + template + Uptr VPos>::copy() const + { + return std::make_unique>(*this); + } + + template + SizeT VPos>::vsize() const + { + return this->size(); + } + + template + SizeT VPos>::vval() const + { + return this->val(); + } + + template + const VPosBase* VPos>::vget() const + { + return mFRef; + } + + template + const VPosBase* VPos>::vnext() const + { + return mNRef; + } + + template + Uptr VPos>::vextend(const DPos& a) const + { + return std::make_unique>(*this,a); + } + + template + Uptr VPos>::vextend(const DPosRef& a) const + { + return std::make_unique>(*this,a); + } + + template + Uptr VPos>::vextend(const UPos& a) const + { + return std::make_unique>(*this,a); + } + + template + Uptr VPos>::vextend(const FPos& a) const + { + return std::make_unique>(*this,a); + } + + /*************** + * VPosRef * + ***************/ + + template + VPosRef::VPosRef(const PosT* c) : + mC(c), mNextRef(&mC->next()) + {} + + template + Uptr VPosRef::copy() const + { + return std::make_unique>(*mC); + } + + template + SizeT VPosRef::vsize() const + { + return mC->size(); + } + + template + const SizeT& VPosRef::vval() const + { + return mC->val(); + } + + template + const VPosBase& VPosRef::vget() const + { + return this; + } + + template + const VPosBase& VPosRef::vnext() const + { + return nullptr; + } + + template + Uptr VPosRef::vextend(const DPos& a) const + { + return std::make_unique>(*mC,a); + } + + template + Uptr VPosRef::vextend(const UPos& a) const + { + return std::make_unique>(*mC,a); + } + + template + Uptr VPosRef::vextend(const FPos& a) const + { + return std::make_unique>(*mC,a); + } + + /********************* + * VPosRef * + *********************/ + + template + VPosRef>::VPosRef(const PosT* c) : + mC(c), mFRef(&c->get()), mNRef(&c->next()) + {} + + template + Uptr VPosRef>::copy() const + { + return std::make_unique>(*mFRef,*mNRef); + } + + template + SizeT VPosRef>::vsize() const + { + return mC->size(); + } + + template + SizeT VPosRef>::vval() const + { + return mC->val(); + } + + template + const VPosBase* VPosRef>::vget() const + { + return mFRef; + } + + template + const VPosBase* VPosRef>::vnext() const + { + return mNRef; + } + + template + Uptr VPosRef>::vextend(const DPos& a) const + { + return std::make_unique>(*mC,a); + } + + template + Uptr VPosRef>::vextend(const DPosRef& a) const + { + return std::make_unique>(*mC,a); + } + + template + Uptr VPosRef>::vextend(const UPos& a) const + { + return std::make_unique>(*mC,a); + } + + template + Uptr VPosRef>::vextend(const FPos& a) const + { + return std::make_unique>(*mC,a); + } +} + +#endif diff --git a/src/include/ranges/xfor/vpos_type.h b/src/include/ranges/xfor/vpos_type.h new file mode 100644 index 0000000..068f478 --- /dev/null +++ b/src/include/ranges/xfor/vpos_type.h @@ -0,0 +1,145 @@ + +#ifndef __cxz_vpos_type_h__ +#define __cxz_vpos_type_h__ + +#include "base/base.h" + +namespace CNORXZ +{ + class VPosBase + { + public: + DEFAULT_MEMBERS(VPosBase); + + virtual Uptr copy() const = 0; + virtual SizeT vsize() const = 0; + virtual const SizeT& vval() const = 0; + virtual const VPosBase* vget() const = 0; + virtual const VPosBase* vnext() const = 0; + virtual Uptr vplus(const VPosBase* a) const = 0; + virtual Uptr vtimes(SizeT a) const = 0; + virtual Uptr vextend(const DPos& a) const = 0; + virtual Uptr vextend(const DPosRef& a) const = 0; + virtual Uptr vextend(const UPos& a) const = 0; + virtual Uptr vextend(const FPos& a) const = 0; + + template + UPtr vextend(const SPos& a) const + { + return this->vextend(UPos(N)); + } + }; + + template + class VPos : public VPosBase, public PosT + { + public: + + DEFAULT_MEMBERS(VPos); + VPos(const PosInterface& a); + + virtual Uptr copy() const override final; + virtual SizeT vsize() const override final; + virtual SizeT vval() const override final; + virtual const VPosBase* vget() const override final; + virtual const VPosBase* vnext() const override final; + virtual Uptr vextend(const DPos& a) const override final; + virtual Uptr vextend(const DPosRef& a) const override final; + virtual Uptr vextend(const UPos& a) const override final; + virtual Uptr vextend(const FPos& a) const override final; + }; + + template + class VPos> : public VPosBase, public MPos + { + private: + VPosRef mFRef; + VPosRef mNRef; + public: + typedef MPos MPosT; + + DEFAULT_MEMBERS(VPos); + VPos(const PosInterface>& a); + + virtual Uptr copy() const override final; + virtual SizeT vsize() const override final; + virtual SizeT vval() const override final; + virtual const VPosBase* vget() const override final; + virtual const VPosBase* vnext() const override final; + virtual Uptr vextend(const DPos& a) const override final; + virtual Uptr vextend(const DPosRef& a) const override final; + virtual Uptr vextend(const UPos& a) const override final; + virtual Uptr vextend(const FPos& a) const override final; + }; + + template + class VPosRef : public VPosBase + { + private: + const PosT* mC = nullptr; + + public: + DEFAULT_MEMBERS(VPosRef); + VPosRef(const PosT* c); + + virtual Uptr copy() const override final; + virtual SizeT vsize() const override final; + virtual SizeT vval() const override final; + virtual const VPosBase* vget() const override final; + virtual const VPosBase* vnext() const override final; + virtual Uptr vextend(const DPos& a) const override final; + virtual Uptr vextend(const DPosRef& a) const override final; + virtual Uptr vextend(const UPos& a) const override final; + virtual Uptr vextend(const FPos& a) const override final; + + }; + + template + class VPosRef> : public VPosBase + { + private: + const MPos* mC = nullptr; + VPosRef mFRef; + VPosRef mNRef; + public: + typedef MPos MPosT; + + DEFAULT_MEMBERS(VPosRef); + VPosRef(const PosT* c); + + virtual Uptr copy() const override final; + virtual SizeT vsize() const override final; + virtual SizeT vval() const override final; + virtual const VPosBase* vget() const override final; + virtual const VPosBase* vnext() const override final; + virtual Uptr vextend(const DPos& a) const override final; + virtual Uptr vextend(const DPosRef& a) const override final; + virtual Uptr vextend(const UPos& a) const override final; + virtual Uptr vextend(const FPos& a) const override final; + }; + + + // defined as empty since they should never instanciated + template <> + class VPos + {}; + + // defined as empty since they should never instanciated + template <> + class VPosRef + {}; + + // defined as empty since they should never instanciated + template <> + class VPos + {}; + + // defined as empty since they should never instanciated + template <> + class VPosRef + {}; + + +} + +#endif