DArray (future Array)

This commit is contained in:
Christian Zimmermann 2022-08-31 14:58:39 +02:00
parent 21bd120032
commit 3dd688bbed
4 changed files with 216 additions and 1 deletions

View file

@ -0,0 +1,108 @@
#include "cxz_darray_base.h"
namespace CNORXZ
{
/****************
* DArrayBase *
***************/
template <typename T>
DArrayBase<T>::DArrayBase(const RangePtr& range) : mRange(range), mInit(true)
{
mIt = this->begin();
}
template <typename T>
template <typename I>
const value_type& DArrayBase<T>::operator[](const IndexInterface<I>& i) const
{
return *mIt(i);
}
template <typename T>
template <typename I>
const value_type& DArrayBase<T>::at(const IndexInterface<I>& i) const
{
return *mIt.at(i);
}
template <typename T>
size_t DArrayBase<T>::size() const
{
return mRange->size();
}
template <typename T>
RangePtr DArrayBase<T>::range() const
{
return mRange;
}
template <typename T>
DArrayBase<T>::const_iterator DArrayBase<T>::begin() const
{
return this->cbegin();
}
template <typename T>
DArrayBase<T>::const_iterator DArrayBase<T>::end() const
{
return this->cend();
}
template <typename T>
virtual bool DArrayBase<T>::isInit() const
{
return mInit;
}
template <typename T>
template <typename I>
ConstOperationRoot<T,I> DArrayBase<T>::operator()(const IndexPtr<I>& i) const
{
return ConstOperationRoot<T,I>(/**/);
}
/*****************
* MDArrayBase *
****************/
template <typename T>
MDArrayBase<T>::MDArrayBase(const RangePtr& range) : DArrayBase(range) {}
template <typename T>
template <typename I>
value_type& MDArrayBase<T>::operator[](const IndexInterface<I>& i)
{
return *mIt(i);
}
template <typename T>
template <typename I>
value_type& MDArrayBase<T>::at(const IndexInterface<I>& i)
{
return *mIt.at(i);
}
template <typename T>
MDArrayBase<T>::iterator MDArrayBase<T>::begin()
{
return iterator(this->data(), this->cbegin());
}
template <typename T>
MDArrayBase<T>::iterator MDArrayBase<T>::end()
{
return iterator(this->data(), this->cend());
}
template <typename T>
template <typename I>
OperationRoot<T,I> MDArrayBase<T>::operator()(const IndexPtr<I>& i)
{
return OperationRoot<T,I>(/**/);
}
}

View file

@ -0,0 +1,101 @@
#ifndef __cxz_darray_base_h__
#define __cxz_darray_base_h__
#include <cstdlib>
#include <vector>
#include <memory>
#include <algorithm>
#include "base_def.h"
#include "mbase_def.h"
#include "ranges/rheader.h"
namespace CNORXZ
{
template <typename T>
class DArrayBase
{
public:
typedef T value_type;
typedef ConstContainerIndex const_iterator;
protected:
RangePtr mRange;
const_iterator mIt;
bool mInit = false;
public:
DArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(DArrayBase);
virtual ~DArrayBase() = default;
template <typename I>
const value_type& operator[](const IndexInterface<I>& i) const;
template <typename I>
const value_type& at(const IndexInterface<I>& i) const;
template <typename I>
DArrayBase sl(const IndexInterface<I>& i) const;
virtual const T* data() const = 0;
virtual size_t size() const;
virtual RangePtr range() const;
virtual const_iterator begin() const;
virtual const_iterator end() const;
virtual const_iterator cbegin() const = 0;
virtual const_iterator cend() const = 0;
virtual bool isView() const = 0;
virtual bool isInit() const;
template <typename I>
ConstOperationRoot<T,I> operator()(const IndexPtr<I>& i) const;
};
template <typename T>
class MDArrayBase : public DArrayBase<T>
{
public:
typedef DArrayBase<T> DAB;
typedef DAB::value_type value_type;
typedef DAB::const_iterator const_iterator;
typedef DContainerIndex iterator;
using DAB::operator[];
using DAB::at;
using DAB::data;
using DAB::begin;
using DAB::end;
using DAB::cbegin;
using DAB::cend;
using DAB::operator();
MDArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(MDArrayBase);
template <typename I>
value_type& operator[](const IndexInterface<I>& i);
template <typename I>
value_type& at(const IndexInterface<I>& i);
template <typename I>
DArrayBase sl(const IndexInterface<I>& i);
virtual T* data() = 0;
virtual iterator begin();
virtual iterator end();
template <typename I>
OperationRoot<T,I> operator()(const IndexPtr<I>& i);
};
}
#endif

View file

@ -100,6 +100,9 @@ namespace CNORXZ
return iptr; return iptr;
} }
template <class Index>
using IndexPtr = std::shared_ptr<IndexInterface<Index>>
} }
/* ========================= * /* ========================= *

View file

@ -127,6 +127,9 @@ namespace CNORXZ
RangeInterface() = default; RangeInterface() = default;
}; };
typedef std::shared_ptr<RangeBase> RangePtr;
RangePtr operator*(const RangePtr& a, const RangePtr& b); // -> Ptr to MultiRange
} }
#endif #endif