diff --git a/src/include/dynamic_operation.cc.h b/src/include/dynamic_operation.cc.h index 39aa818..cdd1332 100644 --- a/src/include/dynamic_operation.cc.h +++ b/src/include/dynamic_operation.cc.h @@ -6,8 +6,18 @@ namespace MultiArrayTools template const T& DynamicOperation::get(const DExtT& pos) const { - VCHECK(pos.expl().val()); - return mOp.get(pos.expl()); + if(pos.isInit()){ + VCHECK(pos.stype()); + ET xx; + VCHECK(xx.stype()); + VCHECK(mOp.rootSteps(0).stype()); + VCHECK(pos.expl().val()); + return mOp.get(pos.expl()); + } + else { + ET xx; + return mOp.get(xx); + } } template diff --git a/src/include/xfor/exttype.h b/src/include/xfor/exttype.h index ebb84e1..e14ee82 100644 --- a/src/include/xfor/exttype.h +++ b/src/include/xfor/exttype.h @@ -92,6 +92,10 @@ namespace MultiArrayHelper auto extend(const Y& y) const -> MExt { return MExt(mExt, mNext.extend(y)); } + std::string stype() const { return std::string("E[") + mNext.stype() + "]"; } + + const MExt& lowest() const { return *this; } + MExt& lowest() { return *this; } }; struct None @@ -117,6 +121,11 @@ namespace MultiArrayHelper template Y extend(const Y& y) const { return y; } + + std::string stype() const { return "N"; } + + const None& lowest() const { return *this; } + None& lowest() { return *this; } }; template <> @@ -170,6 +179,10 @@ namespace MultiArrayHelper auto extend(const Y& y) const -> MExt { return MExt(mExt,y); } + std::string stype() const { return "E[N]"; } + + const MExt& lowest() const { return *this; } + MExt& lowest() { return *this; } }; diff --git a/src/include/xfor/xfor.h b/src/include/xfor/xfor.h index 9beb278..d32d26e 100644 --- a/src/include/xfor/xfor.h +++ b/src/include/xfor/xfor.h @@ -44,6 +44,8 @@ namespace MultiArrayHelper template const ExtType& expl() const; + virtual std::string stype() const = 0; + }; typedef std::shared_ptr DExt; @@ -63,7 +65,7 @@ namespace MultiArrayHelper ExtT& operator=(const ExtT& in) = default; ExtT& operator=(ExtT&& in) = default; - ExtT(const ExtType& in) : mExt(in) {} + ExtT(const ExtType& in) : mExt(in) { assert(in.stype()[0] != 'T'); } virtual std::shared_ptr deepCopy() const override final { return std::make_shared>(mExt); } @@ -78,31 +80,70 @@ namespace MultiArrayHelper { return std::make_shared( mExt + dynamic_cast(in).mExt ); } virtual DExt operator*(size_t in) const override final { return std::make_shared( mExt * in ); } + + virtual std::string stype() const override final { return std::string("T[")+mExt.stype()+"]"; } + const ExtType& lowest() const { return mExt; } + ExtType& lowest() { return mExt; } }; //class DExtT; + template + class DExtTX; + template + struct SptrExtT + { + typedef typename std::remove_reference().lowest())>::type YX; + + static DExt mk(const Y& y) + { + return std::make_shared>(y.lowest()); + } + }; + + template + struct SptrExtT> + { + static DExt mk(const DExtTX& y) + { + return y.lowest(); + } + }; + /* + template + struct SptrExtT> + { + static DExt mk(const ExtT& y) + { + return std::make_shared>(y); + } + }; + */ template class DExtTX { private: mutable DExt mDExt = nullptr; X mNext; + + static DExt getDeepCopy(const DExtTX& in) { if(in.mDExt) return in.mDExt->deepCopy(); else return DExt(); } + public: static constexpr size_t NUM = X::SIZE; static constexpr size_t SIZE = NUM + 1; - DExtTX() { mDExt = std::make_shared>(); } - DExtTX(const DExtTX& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} - DExtTX(DExtTX&& in) : mDExt(in.mDExt->deepCopy()), mNext(in.mNext) {} - DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); } - DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); } + //DExtTX() { VCHECK(mDExt->val()) ;mDExt = std::make_shared>(); } + DExtTX() = default; + DExtTX(const DExtTX& in) : mDExt(getDeepCopy(in)), mNext(in.mNext) {} + DExtTX(DExtTX&& in) : mDExt(getDeepCopy(in)), mNext(in.mNext) {} + DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = getDeepCopy(in); } + DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = getDeepCopy(in); } DExtTX(const DExt& in) : mDExt(in) {} template - DExtTX& operator=(const Y& y) { mDExt = std::make_shared>(y); return *this; } + DExtTX& operator=(const Y& y) { mDExt = SptrExtT::mk(y); return *this; } template - DExtTX(const Y& y) : mDExt(std::make_shared>(y)) {} + DExtTX(const Y& y) : mDExt(SptrExtT::mk(y)) {} DExtTX(const DExt& y, const X& x) : mDExt(y), mNext(x) {} @@ -117,7 +158,8 @@ namespace MultiArrayHelper template inline const ExtType& expl() const - { if(mDExt == nullptr) mDExt = std::make_shared>(); assert(mDExt != nullptr); return mDExt->expl(); } + //{ if(mDExt == nullptr) mDExt = std::make_shared>(); assert(mDExt != nullptr); return mDExt->expl(); } + { return mDExt->expl(); } template inline auto extend(const Y& y) const -> DExtTX @@ -131,6 +173,13 @@ namespace MultiArrayHelper template inline auto nn() const -> decltype(Getter::getX(*this)) { return Getter::getX(*this); } + + inline std::string stype() const { return std::string("S[")+mDExt->stype()+"]"; } + + inline bool isInit() const { return mDExt != nullptr; } + + const DExt& lowest() const { return mDExt; } + DExt& lowest() { return mDExt; } }; typedef DExtTX DExtT; @@ -494,7 +543,13 @@ namespace MultiArrayHelper template const ExtType& ExtBase::expl() const { - return dynamic_cast*>(this)->ext(); + VCHECK(this); + VCHECK(this->stype()); + auto xx = dynamic_cast*>(this); + VCHECK(xx); + ExtT xxx; + VCHECK(xxx.stype()); + return xx->ext(); } /***************** @@ -522,6 +577,9 @@ namespace MultiArrayHelper template inline void For::operator()(size_t mlast, DExt last) { + VCHECK(last->stype()); + ExtType xxx; + VCHECK(xxx.stype()); operator()(mlast, std::dynamic_pointer_cast>(last)->ext()); //operator()(mlast, *reinterpret_cast(last.first)); } @@ -569,7 +627,7 @@ namespace MultiArrayHelper template DExt For::dRootSteps(std::intptr_t iPtrNum) const { - return std::make_shared>(rootSteps(iPtrNum)); + return SptrExtT::mk(rootSteps(iPtrNum)); //mRootSteps = rootSteps(iPtrNum); //return std::make_pair(reinterpret_cast(&mRootSteps), // sizeof(ExtType)/sizeof(size_t)); @@ -578,7 +636,7 @@ namespace MultiArrayHelper template DExt For::dExtension() const { - return std::make_shared>(mExt); + return SptrExtT::mk(mExt); //return std::make_pair(reinterpret_cast(&mExt), // sizeof(ExtType)/sizeof(size_t)); } @@ -681,7 +739,7 @@ namespace MultiArrayHelper template DExt PFor::dRootSteps(std::intptr_t iPtrNum) const { - return std::make_shared>(rootSteps(iPtrNum)); + return SptrExtT::mk(rootSteps(iPtrNum)); //mRootSteps = rootSteps(iPtrNum); //return std::make_pair(reinterpret_cast(&mRootSteps), // sizeof(ExtType)/sizeof(size_t)); @@ -690,7 +748,7 @@ namespace MultiArrayHelper template DExt PFor::dExtension() const { - return std::make_shared>(mExt); + return SptrExtT::mk(mExt); //return std::make_pair(reinterpret_cast(&mExt), // sizeof(ExtType)/sizeof(size_t)); } @@ -768,7 +826,7 @@ namespace MultiArrayHelper template DExt SingleExpression::dRootSteps(std::intptr_t iPtrNum) const { - return std::make_shared>(rootSteps(iPtrNum)); + return SptrExtT::mk(rootSteps(iPtrNum)); //mRootSteps = rootSteps(iPtrNum); //return std::make_pair(reinterpret_cast(&mRootSteps), // sizeof(ExtType)/sizeof(size_t)); @@ -777,7 +835,7 @@ namespace MultiArrayHelper template DExt SingleExpression::dExtension() const { - return std::make_shared>(mExt); + return SptrExtT::mk(mExt); //return std::make_pair(reinterpret_cast(&mExt), // sizeof(ExtType)/sizeof(size_t)); } @@ -855,7 +913,7 @@ namespace MultiArrayHelper template DExt SubExpr::dRootSteps(std::intptr_t iPtrNum) const { - return std::make_shared>(rootSteps(iPtrNum)); + return SptrExtT::mk(rootSteps(iPtrNum)); //mRootSteps = rootSteps(iPtrNum); //return std::make_pair(reinterpret_cast(&mRootSteps), //sizeof(ExtType)/sizeof(size_t)); @@ -864,7 +922,7 @@ namespace MultiArrayHelper template DExt SubExpr::dExtension() const { - return std::make_shared>(mExt); + return SptrExtT::mk(mExt); //return std::make_pair(reinterpret_cast(&mExt), // sizeof(ExtType)/sizeof(size_t)); } @@ -910,7 +968,7 @@ namespace MultiArrayHelper inline void ExpressionHolder::operator()(size_t mlast, ExtType last) { mExpr(mlast, - std::make_shared>(last)); + SptrExtT::mk(last)); } template