diff --git a/src/base_def.h b/src/base_def.h index 00a77f4..5200fa0 100644 --- a/src/base_def.h +++ b/src/base_def.h @@ -90,7 +90,7 @@ namespace MultiArrayTools class MultiArrayOperation; // slice.h - template + template class Slice; } diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 20353f6..30fc696 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -25,6 +25,28 @@ namespace MultiArrayTools * MultiArrayOperationBase * *********************************/ + template + void MultiArrayOperationRoot::performAssignment(const MultiArrayOperationBase& in) + { + in.linkIndicesTo(MAOB::mIibPtr); + IndexType& iref = dynamic_cast(*MAOB::mIibPtr); + for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){ + // build in vectorization later + get() = in.get(); + } + MAOB::mIibPtr->freeLinked(); + } + + template + template + MultiArrayOperationRoot& + MultiArrayOperationRoot::makeSlice(MultiArrayOperationRoot& in) + { + Slice& sl = dynamic_cast&>( mArrayRef ); + sl.set(in.mArrayRef, name(), &in.index(), in.name()); + return *this; + } + template MultiArrayOperationRoot:: MultiArrayOperationRoot(MultiArrayBase& ma, @@ -43,39 +65,45 @@ namespace MultiArrayTools MultiArrayOperationRoot& MultiArrayOperationRoot::operator=(const MultiArrayOperationRoot& in) { - if(mArrayRef.isSlice()){ - Slice& sl = dynamic_cast&>( mArrayRef ); - - sl.set() - return *this; - } - - in.linkIndicesTo(MAOB::mIibPtr); - IndexType& iref = dynamic_cast(*MAOB::mIibPtr); - - for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){ - // build in vectorization later - get() = in.get(); - } - MAOB::mIibPtr->freeLinked(); + performAssignment(in); return *this; } + template + MultiArrayOperationRoot& + MultiArrayOperationRoot::operator=(MultiArrayOperationRoot& in) + { + maketurnSlice(in); + if(mArrayRef.isSlice()){ + return makeSlice(in); + } + performAssignment(in); + return *this; + } + + template + template + MultiArrayOperationRoot& + MultiArrayOperationRoot::operator=(MultiArrayOperationRoot& in) + { + if(mArrayRef.isSlice()){ + return makeSlice(in); + } + performAssignment(in); + return *this; + } + template template MultiArrayOperationRoot& MultiArrayOperationRoot::operator=(const MultiArrayOperation& in) { - // NO SLICE CREATION !!! (total array not initialized!!) - - in.linkIndicesTo(MAOB::mIibPtr); - IndexType& iref = dynamic_cast(*MAOB::mIibPtr); - - for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){ - // build in vectorization later - get() = in.get(); + if(mArrayRef.isSlice()){ + // NO SLICE CREATION !!! (total array not initialized!!) + // throw ! + assert(0); } - MAOB::mIibPtr->freeLinked(); + performAssignment(in); return *this; } @@ -153,6 +181,12 @@ namespace MultiArrayTools return mArrayRef[*dynamic_cast(MAOB::mIibPtr)]; } + template + const Name& MultiArrayOperationRoot::name() const + { + return mNm; + } + /***************************** * MultiArrayOperation * *****************************/ diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index 11861ad..b1c23ce 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -42,6 +42,11 @@ namespace MultiArrayTools MultiArrayOperationRoot(MultiArrayBase& ma, const Name& nm); MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in); + MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in); + + template + MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in); + template MultiArrayOperationRoot& operator=(const MultiArrayOperation& in); @@ -67,14 +72,24 @@ namespace MultiArrayTools virtual size_t argNum() const override; - //IndexType& index() ; + IndexType& index(); + // set index + MultiArrayOperationRoot& operator[](const IndexType& ind); + virtual void linkIndicesTo(IndefinitIndexBase* target) const override; virtual T& get() override; virtual const T& get() const override; + + const Name& name() const; protected: + + void performAssignment(const MultiArrayOperationBase& in); + + template + MultiArrayOperationRoot& makeSlice(MultiArrayOperationRoot& in); MultiArrayBase& mArrayRef; mutable IndexType mIndex; diff --git a/src/slice.cc b/src/slice.cc index aaeeee6..120f807 100644 --- a/src/slice.cc +++ b/src/slice.cc @@ -7,8 +7,8 @@ namespace MultiArrayTools template Slice:: - Slice() : - MultiArrayBase(ma.range()), + Slice(const Range& range) : + MultiArrayBase(range), mMultiArrayRef(*this) {} template @@ -18,10 +18,16 @@ namespace MultiArrayTools } template - void Slice::set(MultiArrayBase& multiArrayRef, IndefinitIndexBase* MAPtr) + void Slice::set(MultiArrayBase& multiArrayRef, + const Name& ownNm, // for correct linkage + IndefinitIndexBase* MAPtr, // for desired slice position + const Name& MANm) // for correct linkage) { mMultiArrayRef = multiArrayRef; - - mMAPtr.reset(new typename MARange::IndexType(MAPtr)); + mMAPtr.reset(new typename MARange::IndexType(*MAPtr)); + mOwnPtr.reset(new typename Range::IndexType()); + mMAPtr->name(MANm); + mOwnPtr->name(ownNm); + mMAPtr->linkTo(mOwnPtr); } } diff --git a/src/slice.h b/src/slice.h index 49b23f3..2486a61 100644 --- a/src/slice.h +++ b/src/slice.h @@ -21,7 +21,7 @@ namespace MultiArrayTools typedef MultiArrayBase MAB; - Slice(); + Slice(const Range& range); T& operator[](const typename Range::IndexType& i) override; const T& operator[](const typename Range::IndexType& i) const override; @@ -34,13 +34,16 @@ namespace MultiArrayTools virtual bool isSlice() const override; - void set(MultiArrayBase& multiArrayRef, IndefinitIndexBase* MAPtr); + void set(MultiArrayBase& multiArrayRef, + const Name& ownNm, + IndefinitIndexBase* MAPtr, + const Name& MANm); private: MultiArrayBase& mMultiArrayRef; std::shared_ptr mMAPtr; // idx ptr for original MA Range - IndefinitIndexBase* mOwnPtr; // idx ptr for own Range + std::shared_ptr mOwnPtr; // idx ptr for own Range //Index mSlicePos; };