xpr_base
This commit is contained in:
parent
85059f8024
commit
e2baceada7
3 changed files with 154 additions and 60 deletions
|
@ -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 Xpr, class PosT>
|
||||
class ExprInterface
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(ExprInterface);
|
||||
|
||||
Xpr& THIS() { return static_cast<Xpr&>(*this); }
|
||||
const Xpr& THIS() const { return static_cast<const Xpr&>(*this); }
|
||||
|
||||
//Sptr<Expr> 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<VExprBase> 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 Xpr, class PosT>
|
||||
class VExpr : public VExprBase, public Xpr
|
||||
{
|
||||
public:
|
||||
typedef ExprInterface<Xpr,PosT> EI;
|
||||
DEFAULT_MEMBERS(VExpr);
|
||||
VExpr(const ExprInterface<Xpr,PosT>& a) : Xpr(a.THIS()) {}
|
||||
|
||||
virtual Uptr<VExprBase> copy() const override final { return std::make_unique<VExpr>(*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<VExprBase>,
|
||||
public ExprInterface<DExpr,DPos>
|
||||
{
|
||||
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 <ForType FT = ForType::DEFAULT>
|
||||
struct PosForward
|
||||
|
|
76
src/include/ranges/xpr/xpr_base.cc.h
Normal file
76
src/include/ranges/xpr/xpr_base.cc.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
|
||||
#ifndef __cxz_xpr_base_cc_h__
|
||||
#define __cxz_xpr_base_cc_h__
|
||||
|
||||
#include "xpr_base.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
/************
|
||||
* VXpr *
|
||||
************/
|
||||
|
||||
template <class Xpr>
|
||||
VXpr<Xpr>::VXpr(const XprInterface<Xpr>& a) :
|
||||
Xpr(a.THIS())
|
||||
{}
|
||||
|
||||
template <class Xpr>
|
||||
Uptr<VXprBase> VXpr<Xpr>::copy() const
|
||||
{
|
||||
return std::make_unique<VXpr<Xpr>>(*this);
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
SizeT VXpr<Xpr>::vexec(SizeT mlast, const DPos& last) const
|
||||
{
|
||||
return (*this)(mlast, last);
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
SizeT VXpr<Xpr>::vexec(SizeT mlast) const
|
||||
{
|
||||
return (*this)(mlast);
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
DPos VXpr<Xpr>::vrootSteps(PtrId ptrId) const
|
||||
{
|
||||
return DPos(this->rootSteps(ptrId));
|
||||
}
|
||||
|
||||
/************
|
||||
* DXpr *
|
||||
************/
|
||||
|
||||
template <class Xpr>
|
||||
explicit DXpr::DXpr(const Xpr& a) :
|
||||
ObjHandle<VXprBase>(VXpr<Xpr>(a))
|
||||
{}
|
||||
|
||||
template <class PosT>
|
||||
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 <SizeT N>
|
||||
inline DPos DXpr::staticRootSteps(PtrId ptrId) const
|
||||
{
|
||||
return this->rootSteps(ptrId);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
78
src/include/ranges/xpr/xpr_base.h
Normal file
78
src/include/ranges/xpr/xpr_base.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
|
||||
#ifndef __cxz_xpr_base_h__
|
||||
#define __cxz_xpr_base_h__
|
||||
|
||||
#include "base/base.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <class Xpr>
|
||||
class XprInterface
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(XprInterface);
|
||||
|
||||
Xpr& THIS() { return static_cast<Xpr&>(*this); }
|
||||
const Xpr& THIS() const { return static_cast<const Xpr&>(*this); }
|
||||
|
||||
template <class PosT>
|
||||
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 <SizeT N>
|
||||
constexpr auto staticRootSteps(PtrId ptrId) const { return THIS().staticRootSteps<N>(ptrId); }
|
||||
};
|
||||
|
||||
class VXprBase
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(VXprBase);
|
||||
|
||||
virtual Uptr<VXprBase> 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 Xpr>
|
||||
class VXpr : public VXprBase, public Xpr
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(VXpr);
|
||||
VXpr(const XprInterface<Xpr>& a);
|
||||
|
||||
virtual Uptr<VXprBase> 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<VXprBase>,
|
||||
public XprInterface<DXpr>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(DXpr);
|
||||
|
||||
template <class Xpr>
|
||||
explicit DXpr(const Xpr& a);
|
||||
|
||||
template <class PosT>
|
||||
inline SizeT operator()(SizeT mlast, const PosT& last) const;
|
||||
inline SizeT operator()(SizeT mlast) const;
|
||||
|
||||
inline DPos rootSteps(PtrId ptrId) const;
|
||||
|
||||
template <SizeT N>
|
||||
inline DPos staticRootSteps(PtrId ptrId) const; // fallback to rootSteps
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue