minor changes + some extensions

This commit is contained in:
Christian Zimmermann 2017-03-09 19:59:11 +01:00
parent 63eb7d0505
commit d3dbdbb865
4 changed files with 36 additions and 5 deletions

View file

@ -41,6 +41,24 @@ namespace MultiArrayTools
{ {
return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...)); return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
} }
template <typename T, class Range>
template <class NameType>
MultiArrayOperationRoot<T,Range> MultiArrayBase<T,Range>::operator()(const NameType& name, bool master)
{
if(master){
return MultiArrayOperationRoot<T,Range>(*this, name);
}
else {
return operator()(name);
}
}
template <typename T, class Range>
bool MultiArrayBase<T,Range>::isInit() const
{
return mInit;
}
/******************* /*******************
* MultiArray * * MultiArray *
@ -49,13 +67,17 @@ namespace MultiArrayTools
template <typename T, class Range> template <typename T, class Range>
MultiArray<T,Range>::MultiArray(const Range& range) : MultiArray<T,Range>::MultiArray(const Range& range) :
MultiArrayBase<T,Range>(range), MultiArrayBase<T,Range>(range),
mCont(MAB::mRange->size()) {} mCont(MAB::mRange->size())
{
MAB::mInit = true;
}
template <typename T, class Range> template <typename T, class Range>
MultiArray<T,Range>::MultiArray(const Range& range, const std::vector<T>& vec) : MultiArray<T,Range>::MultiArray(const Range& range, const std::vector<T>& vec) :
MultiArrayBase<T,Range>(range), MultiArrayBase<T,Range>(range),
mCont(vec) mCont(vec)
{ {
MAB::mInit = true;
if(mCont.size() > MAB::mRange->size()){ if(mCont.size() > MAB::mRange->size()){
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end()); mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
} }
@ -66,6 +88,7 @@ namespace MultiArrayTools
MultiArrayBase<T,Range>(range), MultiArrayBase<T,Range>(range),
mCont(vec) mCont(vec)
{ {
MAB::mInit = true;
if(mCont.size() > MAB::mRange->size()){ if(mCont.size() > MAB::mRange->size()){
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end()); mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
} }
@ -77,6 +100,7 @@ namespace MultiArrayTools
MultiArrayBase<T,Range>(merge(in.range(), in[ in.begin() ].range())) MultiArrayBase<T,Range>(merge(in.range(), in[ in.begin() ].range()))
// assert that Range2 has always same extension // assert that Range2 has always same extension
{ {
MAB::mInit = true;
mCont.clear(); mCont.clear();
for(auto i = in.begin(); i != in.end(); ++i){ for(auto i = in.begin(); i != in.end(); ++i){
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end()); mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());
@ -114,7 +138,7 @@ namespace MultiArrayTools
{ {
return false; return false;
} }
/* /*
template <typename T, class Range> template <typename T, class Range>
void MultiArray<T,Range>::manipulate(ManipulatorBase<T>& mb, void MultiArray<T,Range>::manipulate(ManipulatorBase<T>& mb,

View file

@ -39,7 +39,13 @@ namespace MultiArrayTools
template <class... NameTypes> template <class... NameTypes>
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str); MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);
template <class NameType>
MultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master);
virtual bool isInit() const;
protected: protected:
bool mInit = false;
std::shared_ptr<Range> mRange; std::shared_ptr<Range> mRange;
}; };

View file

@ -74,7 +74,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range>& in) MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range>& in)
{ {
maketurnSlice(in); maketurnSlice(in);
if(mArrayRef.isSlice()){ if(mArrayRef.isSlice() and not mArrayRef.isInit()){
return makeSlice(in); return makeSlice(in);
} }
performAssignment(in); performAssignment(in);
@ -86,7 +86,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range2>& in) MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range2>& in)
{ {
if(mArrayRef.isSlice()){ if(mArrayRef.isSlice() and not mArrayRef.isInit()){
return makeSlice(in); return makeSlice(in);
} }
performAssignment(in); performAssignment(in);
@ -98,7 +98,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in) MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in)
{ {
if(mArrayRef.isSlice()){ if(mArrayRef.isSlice() and not mArrayRef.isInit()){
// NO SLICE CREATION !!! (total array not initialized!!) // NO SLICE CREATION !!! (total array not initialized!!)
// throw ! // throw !
assert(0); assert(0);

View file

@ -22,6 +22,7 @@ namespace MultiArrayTools
const typename MARange::IndexType& MAIdx, // for desired slice position const typename MARange::IndexType& MAIdx, // for desired slice position
const Name& MANm) // for correct linkage) const Name& MANm) // for correct linkage)
{ {
MAB::mInit = true;
mMultiArrayPtr = &multiArrayRef; mMultiArrayPtr = &multiArrayRef;
mMAIdx = MAIdx; mMAIdx = MAIdx;
mOwnIdx = MAB::mRange->begin(); mOwnIdx = MAB::mRange->begin();