From f94f758c1659efcb09e96612a10164b786c5537f Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 15 Feb 2017 22:39:36 +0100 Subject: [PATCH] almost finished operation templates --- src/me.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++---- src/me.h | 14 ++++++++++ 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/me.cc b/src/me.cc index 9d5382a..945eb86 100644 --- a/src/me.cc +++ b/src/me.cc @@ -476,13 +476,17 @@ namespace ME /********************************* * MultiArrayOperationBase * *********************************/ - + template template MultiArrayOperationBase& MultiArrayOperationBase::operator=(const MultiArrayOperationBase& in) { - // perform operation (iterate head index) + in.linkIndicesTo(mIibPtr); + for(*mIibPtr = mArrayRef.begin(); *mIibPtr != mArrayRef.end(); ++(*mIibPtr)){ + // build in vectorization later + get() = in.get(); + } } template @@ -490,9 +494,7 @@ namespace ME MultiArrayOperation MultiArrayOperationBase::operator()(Operation& op, MultiArrayOperationBase&... secs) { - // set operation - // set mSecs - // link Indices + return MultiArrayOperationBase(op, secs); } template @@ -501,15 +503,81 @@ namespace ME return 1; } + template + IndefinitIndexBase* MultiArrayOperationBase::index() + { + return mIibPtr; + } + + template + void MultiArrayOperationBase::linkIndicesTo(IndefinitIndexBase* target) + { + mIibPtr->linkTo(target); + } + + template + T& MultiArrayOperationBase::get() + { + return mArrayRef(*mIibPtr); + } + + template + const T& MultiArrayOperationBase::get() const + { + return mArrayRef(*mIibPtr); + } + /***************************** * MultiArrayOperation * *****************************/ + template + void linkTupleIndicesTo(IndexTuple& itp, IndefinitIndexBase* target) + { + std::get(itp).linkTo(target); + linkTupleIndicesTo(itp, target); + } + + template + void linkTupleIndicesTo<0>(IndexTuple& itp, IndefinitIndexBase* target) + { + std::get<0>(itp).linkTo(target); + } + + template + T callOperation(Operation& op, Tuple& tp, MBases&... secs) + { + return callOperation(op, tp, std::get(tp), secs...); + } + + // spezialization for termination !!! + template size_t MultiArrayOperation::argNum() const { return sizeof...(Ranges) + 1; } + + template + void MultiArrayOperation::linkIndicesTo(IndefinitIndexBase* target) + { + mIibPtr->linkTo(target); + linkTupleIndicesTo(mSecs, target); + } + + template + T& MultiArrayOperation::get() + { + mVal = mOp(); + return mVal; + } + + template + const T& MultiArrayOperation::get() const + { + mVal = mOp() + return mVal; + } } // end namespace ME diff --git a/src/me.h b/src/me.h index 1edc2ba..28591c4 100644 --- a/src/me.h +++ b/src/me.h @@ -356,6 +356,13 @@ namespace ME MultiArrayOperation,Range2> operator/(MultiArrayOperationBase& sec); virtual size_t argNum() const; + + IndefinitIndexBase* index(); + + virtual void linkIndicesTo(IndefinitIndexBase* target); + + virtual T& get(); + virtual const T& get() const; protected: @@ -369,10 +376,17 @@ namespace ME { public: + MultiArrayOperation(Operation& op, MultiArrayOperationBase&... secs); virtual size_t argNum() const override; + virtual void linkIndicesTo(IndefinitIndexBase* target) override; + + virtual T& get() override; + virtual const T& get() const override; + protected: + T mVal; Operation mOp; std::tuple... > mSecs; };