WIP: todos in array operator(), operator[]
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
a7c1aad6fc
commit
fb8a44e88b
3 changed files with 77 additions and 37 deletions
|
@ -31,14 +31,14 @@ namespace CNORXZ
|
|||
template <typename I, typename M>
|
||||
const T& CArrayBase<T>::operator[](const IndexInterface<I,M>& 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
|
||||
*/
|
||||
if(formatIsTrivial()){
|
||||
return data()[i.lex()];
|
||||
}
|
||||
else {
|
||||
auto ai = itLex(i);
|
||||
return *ai;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename I, typename M>
|
||||
|
@ -52,9 +52,14 @@ namespace CNORXZ
|
|||
template <class... Indices>
|
||||
const T& CArrayBase<T>::operator[](const SPack<Indices...>& pack) const
|
||||
{
|
||||
if(formatIsTrivial()){
|
||||
return data()[pack.lex()];
|
||||
}
|
||||
else {
|
||||
auto ai = itLex(pack);
|
||||
return *ai;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class... Indices>
|
||||
|
@ -116,32 +121,39 @@ namespace CNORXZ
|
|||
template <class Index>
|
||||
COpRoot<T,Index> CArrayBase<T>::operator()(const Sptr<Index>& 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
|
||||
*/
|
||||
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 <typename T>
|
||||
template <class... Indices>
|
||||
inline decltype(auto) CArrayBase<T>::operator()(const SPack<Indices...>& pack) const
|
||||
{
|
||||
auto i = mindexPtr(pack);
|
||||
this->checkFormatCompatibility(*i);
|
||||
return coproot(*this, i);
|
||||
return operator()(mindexPtr(pack));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline decltype(auto) CArrayBase<T>::operator()(const DPack& pack) const
|
||||
{
|
||||
auto i = yindexPtr(pack);
|
||||
this->checkFormatCompatibility(*i);
|
||||
return coproot(*this, i);
|
||||
return operator()(yindexPtr(pack));
|
||||
}
|
||||
|
||||
/*=================================================================+
|
||||
|
@ -210,9 +222,14 @@ namespace CNORXZ
|
|||
template <typename I, typename M>
|
||||
T& ArrayBase<T>::operator[](const IndexInterface<I,M>& i)
|
||||
{
|
||||
if(this->formatIsTrivial()){
|
||||
return data()[i.lex()];
|
||||
}
|
||||
else {
|
||||
auto ai = itLex(i);
|
||||
return *ai;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename I, typename M>
|
||||
|
@ -226,9 +243,14 @@ namespace CNORXZ
|
|||
template <class... Indices>
|
||||
T& ArrayBase<T>::operator[](const SPack<Indices...>& pack)
|
||||
{
|
||||
if(this->formatIsTrivial()){
|
||||
return data()[pack.lex()];
|
||||
}
|
||||
else {
|
||||
auto ai = itLex(pack);
|
||||
return *ai;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class... Indices>
|
||||
|
@ -278,25 +300,39 @@ namespace CNORXZ
|
|||
template <class Index>
|
||||
OpRoot<T,Index> ArrayBase<T>::operator()(const Sptr<Index>& 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 <typename T>
|
||||
template <class... Indices>
|
||||
inline decltype(auto) ArrayBase<T>::operator()(const SPack<Indices...>& pack)
|
||||
{
|
||||
auto i = mindexPtr(pack);
|
||||
this->checkFormatCompatibility(*i);
|
||||
return oproot(*this, i);
|
||||
return operator()(mindexPtr(pack));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline decltype(auto) ArrayBase<T>::operator()(const DPack& pack)
|
||||
{
|
||||
auto i = yindexPtr(pack);
|
||||
this->checkFormatCompatibility(*i);
|
||||
return oproot(*this, i);
|
||||
return operator()(yindexPtr(pack));
|
||||
}
|
||||
|
||||
/*================================================================+
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
namespace CNORXZ
|
||||
{
|
||||
|
||||
/** ***
|
||||
Generic multi-dimensional array class
|
||||
This class owns the data that can be accessed through it
|
||||
**/
|
||||
template <typename T>
|
||||
class MArray : public ArrayBase<T>
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue