diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index 02daf86..f35b7a5 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -31,13 +31,13 @@ namespace CNORXZ template const T& CArrayBase::operator[](const IndexInterface& i) const { - /* - TODO: check if container format is trivial: - if yes, just return data[i.lex()], in case of at() check extensions - if not, do what is done now - */ - auto ai = itLex(i); - return *ai; + if(formatIsTrivial()){ + return data()[i.lex()]; + } + else { + auto ai = itLex(i); + return *ai; + } } template @@ -52,8 +52,13 @@ namespace CNORXZ template const T& CArrayBase::operator[](const SPack& pack) const { - auto ai = itLex(pack); - return *ai; + if(formatIsTrivial()){ + return data()[pack.lex()]; + } + else { + auto ai = itLex(pack); + return *ai; + } } template @@ -116,32 +121,39 @@ namespace CNORXZ template COpRoot CArrayBase::operator()(const Sptr& i) const { - /* - TODO: check if container format is trivial - if yes, assert that index format is trivial and has correct extensions - if not, check if index format is trivial - - if yes: try to apply container format - - if not: check if format is compatible - */ - this->checkFormatCompatibility(*i); - return coproot(*this, i); + if(formatIsTrivial()){ + // assert that index format is trivial and has correct extensions + CXZ_ASSERT(i->formatIsTrivial(), + "got non-trivial index for container with trivial format"); + this->checkFormatCompatibility(*i); + return coproot(*this, i); + } + else { + if(i->formatIsTrivial()){ + // try to apply container format + auto aformat = begin().deepFormat(); + CXZ_ERROR("IMPLEMENT " << toString(aformat)); + return coproot(*this, i); + } + else { + // check if format is compatible + this->checkFormatCompatibility(*i); + return coproot(*this, i); + } + } } template template inline decltype(auto) CArrayBase::operator()(const SPack& pack) const { - auto i = mindexPtr(pack); - this->checkFormatCompatibility(*i); - return coproot(*this, i); + return operator()(mindexPtr(pack)); } template inline decltype(auto) CArrayBase::operator()(const DPack& pack) const { - auto i = yindexPtr(pack); - this->checkFormatCompatibility(*i); - return coproot(*this, i); + return operator()(yindexPtr(pack)); } /*=================================================================+ @@ -210,8 +222,13 @@ namespace CNORXZ template T& ArrayBase::operator[](const IndexInterface& i) { - auto ai = itLex(i); - return *ai; + if(this->formatIsTrivial()){ + return data()[i.lex()]; + } + else { + auto ai = itLex(i); + return *ai; + } } template @@ -226,8 +243,13 @@ namespace CNORXZ template T& ArrayBase::operator[](const SPack& pack) { - auto ai = itLex(pack); - return *ai; + if(this->formatIsTrivial()){ + return data()[pack.lex()]; + } + else { + auto ai = itLex(pack); + return *ai; + } } template @@ -278,25 +300,39 @@ namespace CNORXZ template OpRoot ArrayBase::operator()(const Sptr& i) { - this->checkFormatCompatibility(*i); - return oproot(*this, i); + if(this->formatIsTrivial()){ + // assert that index format is trivial and has correct extensions + CXZ_ASSERT(i->formatIsTrivial(), + "got non-trivial index for container with trivial format"); + this->checkFormatCompatibility(*i); + return oproot(*this, i); + } + else { + if(i->formatIsTrivial()){ + // try to apply container format + auto aformat = begin().deepFormat(); + CXZ_ERROR("IMPLEMENT " << toString(aformat)); + return oproot(*this, i); + } + else { + // check if format is compatible + this->checkFormatCompatibility(*i); + return oproot(*this, i); + } + } } template template inline decltype(auto) ArrayBase::operator()(const SPack& pack) { - auto i = mindexPtr(pack); - this->checkFormatCompatibility(*i); - return oproot(*this, i); + return operator()(mindexPtr(pack)); } template inline decltype(auto) ArrayBase::operator()(const DPack& pack) { - auto i = yindexPtr(pack); - this->checkFormatCompatibility(*i); - return oproot(*this, i); + return operator()(yindexPtr(pack)); } /*================================================================+ diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index 155325a..f74f83b 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -174,7 +174,7 @@ namespace CNORXZ void checkFormatCompatibility(const Acc& acc) const; /** check if format is trivial - @return true is container is data owning array, else return + @return true if container is data owning array, else return result of the corresponding container index */ virtual bool formatIsTrivial() const = 0; diff --git a/src/include/array/marray.h b/src/include/array/marray.h index 8195e16..9445ec7 100644 --- a/src/include/array/marray.h +++ b/src/include/array/marray.h @@ -18,6 +18,10 @@ namespace CNORXZ { + /** *** + Generic multi-dimensional array class + This class owns the data that can be accessed through it + **/ template class MArray : public ArrayBase {