diff --git a/src/multi_array.cc b/src/multi_array.cc index ee8e0c0..69179c1 100644 --- a/src/multi_array.cc +++ b/src/multi_array.cc @@ -41,6 +41,24 @@ namespace MultiArrayTools { return MultiArrayOperationRoot(*this, Name("master", str...)); } + + template + template + MultiArrayOperationRoot MultiArrayBase::operator()(const NameType& name, bool master) + { + if(master){ + return MultiArrayOperationRoot(*this, name); + } + else { + return operator()(name); + } + } + + template + bool MultiArrayBase::isInit() const + { + return mInit; + } /******************* * MultiArray * @@ -49,13 +67,17 @@ namespace MultiArrayTools template MultiArray::MultiArray(const Range& range) : MultiArrayBase(range), - mCont(MAB::mRange->size()) {} + mCont(MAB::mRange->size()) + { + MAB::mInit = true; + } template MultiArray::MultiArray(const Range& range, const std::vector& vec) : MultiArrayBase(range), mCont(vec) { + MAB::mInit = true; if(mCont.size() > MAB::mRange->size()){ mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end()); } @@ -66,6 +88,7 @@ namespace MultiArrayTools MultiArrayBase(range), mCont(vec) { + MAB::mInit = true; if(mCont.size() > MAB::mRange->size()){ mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end()); } @@ -77,6 +100,7 @@ namespace MultiArrayTools MultiArrayBase(merge(in.range(), in[ in.begin() ].range())) // assert that Range2 has always same extension { + MAB::mInit = true; mCont.clear(); for(auto i = in.begin(); i != in.end(); ++i){ mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end()); @@ -114,7 +138,7 @@ namespace MultiArrayTools { return false; } - + /* template void MultiArray::manipulate(ManipulatorBase& mb, diff --git a/src/multi_array.h b/src/multi_array.h index 3b32434..81dac14 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -39,7 +39,13 @@ namespace MultiArrayTools template MultiArrayOperationRoot operator()(const NameTypes&... str); + template + MultiArrayOperationRoot operator()(const NameType& name, bool master); + + virtual bool isInit() const; + protected: + bool mInit = false; std::shared_ptr mRange; }; diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 51031ac..17aadc4 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -74,7 +74,7 @@ namespace MultiArrayTools MultiArrayOperationRoot::operator=(MultiArrayOperationRoot& in) { maketurnSlice(in); - if(mArrayRef.isSlice()){ + if(mArrayRef.isSlice() and not mArrayRef.isInit()){ return makeSlice(in); } performAssignment(in); @@ -86,7 +86,7 @@ namespace MultiArrayTools MultiArrayOperationRoot& MultiArrayOperationRoot::operator=(MultiArrayOperationRoot& in) { - if(mArrayRef.isSlice()){ + if(mArrayRef.isSlice() and not mArrayRef.isInit()){ return makeSlice(in); } performAssignment(in); @@ -98,7 +98,7 @@ namespace MultiArrayTools MultiArrayOperationRoot& MultiArrayOperationRoot::operator=(const MultiArrayOperation& in) { - if(mArrayRef.isSlice()){ + if(mArrayRef.isSlice() and not mArrayRef.isInit()){ // NO SLICE CREATION !!! (total array not initialized!!) // throw ! assert(0); diff --git a/src/slice.cc b/src/slice.cc index ee2b139..437822a 100644 --- a/src/slice.cc +++ b/src/slice.cc @@ -22,6 +22,7 @@ namespace MultiArrayTools const typename MARange::IndexType& MAIdx, // for desired slice position const Name& MANm) // for correct linkage) { + MAB::mInit = true; mMultiArrayPtr = &multiArrayRef; mMAIdx = MAIdx; mOwnIdx = MAB::mRange->begin();