cnorxz/src/include/array/array_base.h

126 lines
2.8 KiB
C
Raw Normal View History

2022-08-31 14:58:39 +02:00
#ifndef __cxz_array_base_h__
#define __cxz_array_base_h__
2022-08-31 14:58:39 +02:00
#include <cstdlib>
#include <vector>
#include <memory>
#include <algorithm>
2022-09-15 16:45:45 +02:00
#include "base/base.h"
2022-09-17 22:08:01 +02:00
#include "aindex.h"
2022-09-15 16:45:45 +02:00
//#include "operation/"
2022-08-31 14:58:39 +02:00
namespace CNORXZ
{
template <typename T>
class CArrayBase
2022-08-31 14:58:39 +02:00
{
public:
2022-09-17 22:08:01 +02:00
typedef AIndex<T> const_iterator;
2022-08-31 14:58:39 +02:00
protected:
RangePtr mRange;
public:
CArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(CArrayBase);
2022-08-31 14:58:39 +02:00
virtual ~CArrayBase() = default;
2022-08-31 14:58:39 +02:00
template <typename I, typename M>
const T& operator[](const IndexInterface<I,M>& i) const;
2022-08-31 14:58:39 +02:00
template <typename I, typename M>
const T& at(const IndexInterface<I,M>& i) const;
2022-08-31 14:58:39 +02:00
template <typename I, typename M>
Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& i) const;
2022-08-31 14:58:39 +02:00
virtual const T* data() const = 0;
2022-09-17 22:08:01 +02:00
virtual SizeT size() const;
2022-08-31 14:58:39 +02:00
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;
2022-09-15 16:45:45 +02:00
//template <typename I, typename M>
//ConstOperationRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
2022-08-31 14:58:39 +02:00
};
template <typename T>
class ArrayBase : public CArrayBase<T>
2022-08-31 14:58:39 +02:00
{
public:
typedef CArrayBase<T> CAB;
typedef typename CAB::const_iterator const_iterator;
2022-09-17 22:08:01 +02:00
typedef BIndex<T> iterator;
2022-08-31 14:58:39 +02:00
using CAB::operator[];
using CAB::at;
using CAB::data;
using CAB::begin;
using CAB::end;
using CAB::cbegin;
using CAB::cend;
//using CAB::operator();
2022-08-31 14:58:39 +02:00
ArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(ArrayBase);
2022-08-31 14:58:39 +02:00
template <typename I, typename M>
T& operator[](const IndexInterface<I,M>& i);
2022-08-31 14:58:39 +02:00
template <typename I, typename M>
T& at(const IndexInterface<I,M>& i);
2022-08-31 14:58:39 +02:00
template <typename I, typename M>
Sptr<ArrayBase<T>> sl(const IndexInterface<I,M>& i);
2022-08-31 14:58:39 +02:00
virtual T* data() = 0;
virtual iterator begin();
virtual iterator end();
2022-09-15 16:45:45 +02:00
//template <typename I, typename M>
//OperationRoot<T,I> operator()(const IndexPtr<I,M>& i);
2022-12-12 02:15:42 +01:00
2022-08-31 14:58:39 +02:00
};
2022-12-12 02:15:42 +01:00
// to extra header file !!!:
template <class... Indices>
constexpr decltype(auto) flattenIndexPack(const Tuple<Sptr<Indices>...>& ipack)
{
constexpr SizeT D = sizeof...(Indices);
}
inline Vector<XIndexPtr> flattenIndexPack(const Vector<XIndexPtr>& ipack)
{
}
template <class... Indices>
inline SizeT indexPackDim(Tuple<Sptr<Indices>...> ipack)
{
constexpr SizeT D = sizeof...(Indices);
return iter<0,D>([&](const auto& i) { return std::get<i>(ipack)->dim(); },
[](const auto&... e) { return (e + ...); });
}
inline SizeT indexPackDim(const Vector<XIndexPtr>& ipack)
{
return std::accumulate(ipack.begin(), ipack.end(), ipack[0]->dim(),
[](auto a, auto b) { return a->dim() + b->dim(); });
}
2022-08-31 14:58:39 +02:00
}
#endif