diff --git a/src/include/base/types.h b/src/include/base/types.h index 505fbad..385e664 100644 --- a/src/include/base/types.h +++ b/src/include/base/types.h @@ -67,6 +67,7 @@ namespace CNORXZ R = Rank A = (const) Array B = (mutable) Array + F = Functional, Map,... ***/ // definition: base/dtype.h diff --git a/src/include/ranges/xfor/exttype.h b/src/include/ranges/xfor/exttype.h index ff98c95..86c6caf 100644 --- a/src/include/ranges/xfor/exttype.h +++ b/src/include/ranges/xfor/exttype.h @@ -18,116 +18,178 @@ namespace CNORXZ virtual Uptr copy() const = 0; virtual SizeT vsize() const = 0; virtual const SizeT& vval() const = 0; - virtual VPosBase& vzero() = 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 MPos& a) const = 0; + virtual Uptr vextend(const UPos& a) const = 0; + virtual Uptr vextend(const FPos& a) const = 0; }; template - class PosInterface + class CPosInterface { public: - DEFAULT_MEMBERS(PosInterface); + 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 auto next() const { return THIS().next(); } - inline bool operator==(const PosInterface& a) const { return val() == a.val() and next() == a.next(); } - inline bool operator!=(const PosInterface& a) const { return val() != a.val() or next() != a.next(); } + 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 PosInterface operator+(const PosInterface& a) const { return PosT(val()+a.val(), next()+a.next()); } - inline PosInterface operator*(SizeT a) const { return PosT(val()*a, next()*a); } - inline PosInterface& zero() { return THIS().zero(); } + 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 PosInterface

& a) const { return THIS().extend(a); } + 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)) {} + 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 DPos& zero() { mC->vzero(); return *this; } + inline const DPosRef& next() const { return mNextRef; } - template - inline DPos extend(const PosInterface

& a) const - { return DPos();/* append MPos in static for loop over entries */ } + 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 VPos : public VPosBase - { - private: - PosT mExt; - public: - - DEFAULT_MEMBERS(VPos); - - VPos(const PosT& in) : mExt(in) {} - - virtual SizeT size() const override final { return sizeof(PosT)/sizeof(size_t); } - //const PosT& ext() const { return mExt; } - virtual const SizeT& val() const override final { return mExt.val(); } - virtual void zero() override final { mExt.zero(); } - - virtual bool operator==(const VPosBase& in) const override final - { return mExt == dynamic_cast&>(in).mExt; } - - virtual bool operator==(SizeT in) const override final - { return mExt == in; } - - virtual DExt operator+(const VPosBase& in) const override final - { return std::make_shared>( mExt + dynamic_cast&>(in).mExt ); } - virtual DExt operator*(size_t in) const override final - { return std::make_shared>( mExt * in ); } - - }; - */ - template - class VPos : public VPosBase, public PosT - { - public: - - DEFAULT_MEMBERS(VPos); - - VPos(const PosInterface& a) : PosT(a.THIS()) {} - - 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 VPos& vzero() override final { PosT::THIS().zero(); return *this; } - virtual Uptr vextend(const DPos& a) const override final - { return std::make_unique( PosT::THIS().extend(a) ); } - virtual Uptr vextend(const MPos& 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 - DPos mkDExt(const VPos& in) - { - return std::make_shared>(in); - } - - template - VPos mkVPos(const PosT& in) - { - return VPos(in); - } template class MPos @@ -146,50 +208,54 @@ namespace CNORXZ inline MPos(SizeT ext, PosT next); - template - inline MPos(SizeT y, const Z& z); + template + inline MPos(SizeT y, const CPosInterface& z); - template - inline MPos(const Y& y, const Z& z); + template + inline MPos(const CPosInterface& y, const CPosInterface& z); - template - inline MPos(const Arr& arr); + template + inline MPos(const MPos& y); - template - inline MPos(const MPos& y); - - inline void zero(); - inline const SizeT& val() const; inline const PosT& next() const; - template - inline auto nn() const; + inline auto operator+(const MPos& in) const; + //inline MPos operator+(const UPos& in) const; + inline auto operator*(SizeT in) const; - inline bool operator==(const MPos& in) const - { - return mExt == in.mExt and mNext == in.mNext; - } - - inline bool operator==(size_t in) const - { - return mExt == in and mNext == in; - } - - inline MPos operator+(const MPos& in) const; - inline MPos operator+(const NPos& in) const; - inline MPos operator*(size_t in) const; - - template - auto extend(const Y& y) const -> MPos + 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; } }; - class NPos : public PosInterface + template + class FMPos : public PosInterface> { private: - SizeT VAL = 0; + 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); @@ -199,75 +265,34 @@ namespace CNORXZ //static constexpr SizeT SIZE = 0; - inline const SizeT& val() const { assert(0); return VAL; } - inline bool operator==(const NPos& in) const { return true; } - inline bool operator==(SizeT in) const { return true; } - inline NPos operator+(const NPos& in) const { return NPos(); } - inline NPos operator*(size_t in) const { return NPos(); } - inline void zero() {} + 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 - Y extend(const Y& y) const - { return y; } + inline auto extend(const Y& y) const + { return MPos(mExt, y); } }; - template <> - class MPos : public PosInterface> + class FPos : public PosInterface { private: - SizeT mExt = 0u; - + SizeT mExt = 0; + const Vector* mMap; + public: - //static constexpr size_t NUM = 0; - //static constexpr size_t SIZE = NUM + 1; - - DEFAULT_MEMBERS(MPos); - - inline MPos(size_t ext); - inline MPos(size_t y, const NPos& z) : mExt(y) {} + DEFAULT_MEMBERS(FMPos); - template - inline MPos(size_t y, const Z& z); + template + inline auto operator+(const PosT2& a) const { return UPos(mExt) + a; } - template - inline MPos(const Y& y, const Z& z); + inline auto operator*(SizeT a) const { return UPos(mExt*(*mMap)[a]); } + }; - template - inline MPos(const std::array& arr); - - template - inline MPos(const MPos& y); - - inline bool operator==(const MPos& in) const - { - return mExt == in.mExt; - } - - inline bool operator==(size_t in) const - { - return mExt == in; - } - - inline const size_t& val() const; - inline NPos next() const { return NPos(); } - - inline void zero(); - - template - inline auto nn() const; - - inline MPos operator+(const MPos& in) const; - inline MPos operator+(const NPos& in) const; - inline MPos operator*(size_t in) const; - - template - auto extend(const Y& y) const -> MPos - { return MPos(mExt,y); } - - }; - inline MPos mkExt(SizeT s) { return MPos(s); } /* @@ -384,83 +409,18 @@ namespace CNORXZ } template - inline MPos MPos::operator+(const NPos& in) const + inline MPos MPos::operator+(const UPos& in) const { - return *this; + return MPos(mExt + in.val(), mNext); } template - inline MPos MPos::operator*(size_t in) const + inline MPos MPos::operator*(SizeT in) const { return MPos(mExt * in, mNext * in); } - //template <> - inline MPos::MPos(size_t ext) : mExt(ext) {} - - - //template <> - template - inline MPos::MPos(size_t y, const Z& z) : - mExt(z.val()) {} - - //template <> - template - inline MPos::MPos(const Y& y, const Z& z) : - mExt(y.val()) {} - - /* - //template <> - template - inline MPos::MPos(const std::array& arr) : - mExt(std::get(arr)) {} - */ - template - inline MPos::MPos(const MPos& y) : - mExt(y.val()) {} - - //template <> - inline void MPos::zero() - { - mExt = 0u; - } - /* - template - inline auto MPos::nn() const - { - return getX(*this); - } - */ - inline const size_t& MPos::val() const - { - return mExt; - } - - //template <> - inline MPos MPos::operator+(const MPos& in) const - { - return MPos(mExt + in.val()); - } - - inline MPos MPos::operator+(const NPos& in) const - { - return *this; - } - - //template <> - inline MPos MPos::operator*(size_t in) const - { - return MPos(mExt * in); - } - /* - template - template - inline auto DVPosX::nn() const - { - return getX(*this); - } - */ } // end namespace CNORXZInternal