From e2baceada7cbb2379cbe46757cc8bf5d9faa19e0 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 13 Oct 2022 19:12:23 +0200 Subject: [PATCH] xpr_base --- src/include/ranges/xpr/xfor.h | 60 --------------------- src/include/ranges/xpr/xpr_base.cc.h | 76 +++++++++++++++++++++++++++ src/include/ranges/xpr/xpr_base.h | 78 ++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 60 deletions(-) create mode 100644 src/include/ranges/xpr/xpr_base.cc.h create mode 100644 src/include/ranges/xpr/xpr_base.h diff --git a/src/include/ranges/xpr/xfor.h b/src/include/ranges/xpr/xfor.h index dadd253..1507e74 100644 --- a/src/include/ranges/xpr/xfor.h +++ b/src/include/ranges/xpr/xfor.h @@ -14,67 +14,7 @@ namespace CNORXZ // 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o. // (NO COUNTING OF MASTER POSITION !!!!!) - template - class ExprInterface - { - public: - DEFAULT_MEMBERS(ExprInterface); - Xpr& THIS() { return static_cast(*this); } - const Xpr& THIS() const { return static_cast(*this); } - - //Sptr copy() const { THIS().copy(); } - - void operator()(SizeT mlast, PosT last) { THIS()(mlast, last); } - void operator()(SizeT mlast = 0) { THIS()(mlast); } - - PosT rootSteps(PtrId ptrId = 0) const { return THIS().rootSteps(ptrId); } - PosT extension() const { return THIS().extenrion(); } - }; - - class VExprBase - { - public: - DEFAULT_MEMBERS(VExprBase); - - virtual Uptr copy() const = 0; - - virtual void vexec(SizeT mlast, DPos last) = 0; - virtual void vexec(SizeT mlast) = 0; - - virtual DPos vrootSteps(PtrId ptrId) const = 0; - virtual DPos vextension() const = 0; - }; - - template - class VExpr : public VExprBase, public Xpr - { - public: - typedef ExprInterface EI; - DEFAULT_MEMBERS(VExpr); - VExpr(const ExprInterface& a) : Xpr(a.THIS()) {} - - virtual Uptr copy() const override final { return std::make_unique(*this); } - - virtual void vexec(SizeT mlast, DPos last) override final { EI::THIS()(mlast,last); } - virtual void vexec(SizeT mlast) override final { EI::THIS()(mlast); } - - virtual DPos vrootSteps(PtrId ptrId) const override final { return EI::THIS().rootSteps(ptrId); } - virtual DPos vextension() const override final { return EI::THIS().extension(); } - }; - - class DExpr : public ObjHandle, - public ExprInterface - { - public: - DEFAULT_MEMBERS(DExpr); - - inline void operator()(SizeT mlast, DPos last) { mC->vexec(mlast, last); } - inline void operator()(SizeT mlast) { mC->vexec(mlast); } - - inline DPos rootSteps(PtrId ptrId) const { return mC->vrootSteps(ptrId); } - inline DPos extension() const { return mC->vextension(); } - }; /* template struct PosForward diff --git a/src/include/ranges/xpr/xpr_base.cc.h b/src/include/ranges/xpr/xpr_base.cc.h new file mode 100644 index 0000000..bd3b938 --- /dev/null +++ b/src/include/ranges/xpr/xpr_base.cc.h @@ -0,0 +1,76 @@ + +#ifndef __cxz_xpr_base_cc_h__ +#define __cxz_xpr_base_cc_h__ + +#include "xpr_base.h" + +namespace CNORXZ +{ + + /************ + * VXpr * + ************/ + + template + VXpr::VXpr(const XprInterface& a) : + Xpr(a.THIS()) + {} + + template + Uptr VXpr::copy() const + { + return std::make_unique>(*this); + } + + template + SizeT VXpr::vexec(SizeT mlast, const DPos& last) const + { + return (*this)(mlast, last); + } + + template + SizeT VXpr::vexec(SizeT mlast) const + { + return (*this)(mlast); + } + + template + DPos VXpr::vrootSteps(PtrId ptrId) const + { + return DPos(this->rootSteps(ptrId)); + } + + /************ + * DXpr * + ************/ + + template + explicit DXpr::DXpr(const Xpr& a) : + ObjHandle(VXpr(a)) + {} + + template + inline SizeT DXpr::operator()(SizeT mlast, const PosT& last) const + { + DPosRef dlast(&last); + return mC->vexec(mlast, dlast); + } + + inline SizeT DXpr::operator()(SizeT mlast) const + { + return mC->vexec(mlast); + } + + inline DPos DXpr::rootSteps(PtrId ptrId) const + { + return mC->rootSteps(ptrId); + } + + template + inline DPos DXpr::staticRootSteps(PtrId ptrId) const + { + return this->rootSteps(ptrId); + } +} + +#endif diff --git a/src/include/ranges/xpr/xpr_base.h b/src/include/ranges/xpr/xpr_base.h new file mode 100644 index 0000000..6bdb8bf --- /dev/null +++ b/src/include/ranges/xpr/xpr_base.h @@ -0,0 +1,78 @@ + +#ifndef __cxz_xpr_base_h__ +#define __cxz_xpr_base_h__ + +#include "base/base.h" + +namespace CNORXZ +{ + + template + class XprInterface + { + public: + DEFAULT_MEMBERS(XprInterface); + + Xpr& THIS() { return static_cast(*this); } + const Xpr& THIS() const { return static_cast(*this); } + + template + SizeT operator()(SizeT mlast, const PosT& last) const { return THIS()(mlast,last); } + + SizeT operator()(SizeT mlast = 0) const { return THIS()(mlast); } + + auto rootSteps(PtrId ptrId) const { return THIS().rootSteps(ptrId); } + + template + constexpr auto staticRootSteps(PtrId ptrId) const { return THIS().staticRootSteps(ptrId); } + }; + + class VXprBase + { + public: + DEFAULT_MEMBERS(VXprBase); + + virtual Uptr copy() const = 0; + + virtual SizeT vexec(SizeT mlast, const DPos& last) const = 0; + virtual SizeT vexec(SizeT mlast) const = 0; + + virtual DPos vrootSteps(PtrId ptrId) const = 0; + }; + + template + class VXpr : public VXprBase, public Xpr + { + public: + DEFAULT_MEMBERS(VXpr); + VXpr(const XprInterface& a); + + virtual Uptr copy() const override final; + + virtual SizeT vexec(SizeT mlast, const DPos& last) const override final; + virtual SizeT vexec(SizeT mlast) const override final; + + virtual DPos vrootSteps(PtrId ptrId) const override final; + }; + + class DXpr : public ObjHandle, + public XprInterface + { + public: + DEFAULT_MEMBERS(DXpr); + + template + explicit DXpr(const Xpr& a); + + template + inline SizeT operator()(SizeT mlast, const PosT& last) const; + inline SizeT operator()(SizeT mlast) const; + + inline DPos rootSteps(PtrId ptrId) const; + + template + inline DPos staticRootSteps(PtrId ptrId) const; // fallback to rootSteps + }; +} + +#endif