2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
#ifndef __multi_array_base_h__
|
|
|
|
#define __multi_array_base_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "base_def.h"
|
|
|
|
#include "mbase_def.h"
|
|
|
|
|
|
|
|
#include "ranges/rheader.h"
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
|
2018-11-29 19:37:32 +01:00
|
|
|
template <class IndexType>
|
|
|
|
using IPTR = std::shared_ptr<IndexType>;
|
|
|
|
|
|
|
|
template <class IndexType1, class IndexType2>
|
|
|
|
inline auto operator|(const IPTR<IndexType1>& i1, const IPTR<IndexType2>& i2)
|
|
|
|
-> decltype(std::make_tuple(i1->THIS(),i2->THIS()))
|
|
|
|
{
|
|
|
|
return std::make_tuple(i1->THIS(),i2->THIS());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IndexType1, class... IndexTypes2>
|
|
|
|
inline auto operator|(const IPTR<IndexType1>& i1,
|
|
|
|
const std::tuple<IPTR<IndexTypes2>...>& i2)
|
|
|
|
-> decltype(std::tuple_cat(std::make_tuple(i1),i2))
|
|
|
|
{
|
|
|
|
return std::tuple_cat(std::make_tuple(i1),i2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IndexType2, class... IndexTypes1>
|
|
|
|
inline auto operator|(const std::tuple<IPTR<IndexTypes1>...>& i1,
|
|
|
|
const IPTR<IndexType2>& i2)
|
|
|
|
-> decltype(std::tuple_cat(i1,std::make_tuple(i2)))
|
|
|
|
{
|
|
|
|
return std::tuple_cat(i1,std::make_tuple(i2));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IndexType>
|
|
|
|
inline auto operator~(const IPTR<IndexType>& i)
|
|
|
|
-> decltype(std::make_tuple(i))
|
|
|
|
{
|
|
|
|
return std::make_tuple(i);
|
|
|
|
}
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
// Explicitely specify subranges in template argument !!!
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
class MultiArrayBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef T value_type;
|
|
|
|
typedef ContainerRange<T,SRanges...> CRange;
|
2018-03-01 18:16:12 +01:00
|
|
|
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
2018-02-16 18:17:22 +01:00
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
protected:
|
|
|
|
bool mInit = false;
|
|
|
|
std::shared_ptr<CRange> mRange;
|
|
|
|
std::shared_ptr<IndexType> mProtoI;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
DEFAULT_MEMBERS(MultiArrayBase);
|
|
|
|
MultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
2018-07-21 18:05:53 +02:00
|
|
|
MultiArrayBase(const typename CRange::Space& space);
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
virtual ~MultiArrayBase() = default;
|
|
|
|
|
2018-10-06 13:14:24 +02:00
|
|
|
template <typename X>
|
|
|
|
const T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
|
2018-11-29 19:37:32 +01:00
|
|
|
const T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const;
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual const T& operator[](const IndexType& i) const = 0;
|
|
|
|
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0;
|
|
|
|
|
|
|
|
virtual const T* data() const = 0;
|
|
|
|
|
|
|
|
virtual size_t size() const;
|
|
|
|
virtual bool isSlice() const = 0;
|
|
|
|
|
|
|
|
virtual IndexType begin() const;
|
|
|
|
virtual IndexType end() const;
|
|
|
|
|
|
|
|
virtual IndexType beginIndex() const;
|
|
|
|
virtual IndexType endIndex() const;
|
|
|
|
|
|
|
|
virtual const std::shared_ptr<CRange>& range() const;
|
|
|
|
|
|
|
|
virtual bool isConst() const;
|
|
|
|
|
2018-08-06 15:20:06 +02:00
|
|
|
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const = 0;
|
2018-09-08 18:46:04 +02:00
|
|
|
|
|
|
|
virtual ConstOperationRoot<T,SRanges...>
|
|
|
|
op(const std::shared_ptr<IndexType>& ind) const;
|
2018-07-16 18:52:02 +02:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual ConstOperationRoot<T,SRanges...>
|
2018-07-21 18:05:53 +02:00
|
|
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <class... MappedRanges>
|
2018-08-20 17:50:04 +02:00
|
|
|
ConstOperationRoot<T,MappedRanges...>
|
|
|
|
m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual bool isInit() const;
|
2018-05-20 20:03:44 +02:00
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getRangePtr() const
|
|
|
|
-> decltype(mRange->template getPtr<N>());
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
class MutableMultiArrayBase : public MultiArrayBase<T,SRanges...>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef ContainerRange<T,SRanges...> CRange;
|
|
|
|
typedef MultiArrayBase<T,SRanges...> MAB;
|
2018-03-01 18:16:12 +01:00
|
|
|
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
using MultiArrayBase<T,SRanges...>::operator[];
|
|
|
|
using MultiArrayBase<T,SRanges...>::at;
|
|
|
|
using MultiArrayBase<T,SRanges...>::data;
|
|
|
|
using MultiArrayBase<T,SRanges...>::begin;
|
|
|
|
using MultiArrayBase<T,SRanges...>::end;
|
|
|
|
|
|
|
|
DEFAULT_MEMBERS(MutableMultiArrayBase);
|
|
|
|
MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
2018-07-21 18:05:53 +02:00
|
|
|
MutableMultiArrayBase(const typename CRange::Space& space);
|
2018-10-06 13:14:24 +02:00
|
|
|
|
|
|
|
template <typename X>
|
|
|
|
T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
|
2018-11-29 19:37:32 +01:00
|
|
|
T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is);
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual T& operator[](const IndexType& i) = 0;
|
|
|
|
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
|
|
|
|
|
|
|
|
virtual T* data() = 0;
|
|
|
|
|
|
|
|
//virtual IndexType begin();
|
|
|
|
//virtual IndexType end();
|
|
|
|
|
|
|
|
virtual bool isConst() const override;
|
|
|
|
|
2018-07-16 18:52:02 +02:00
|
|
|
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() = 0;
|
|
|
|
|
2018-09-08 18:46:04 +02:00
|
|
|
virtual ConstOperationRoot<T,SRanges...>
|
|
|
|
op(const std::shared_ptr<IndexType>& ind) const override;
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
virtual ConstOperationRoot<T,SRanges...>
|
2018-07-21 18:05:53 +02:00
|
|
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
2018-09-08 18:46:04 +02:00
|
|
|
|
|
|
|
virtual OperationRoot<T,SRanges...>
|
|
|
|
op(const std::shared_ptr<IndexType>& ind);
|
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
virtual OperationRoot<T,SRanges...> operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds);
|
2018-08-07 21:49:21 +02:00
|
|
|
|
|
|
|
template <class... MappedRanges>
|
2018-08-20 17:50:04 +02:00
|
|
|
OperationRoot<T,MappedRanges...>
|
|
|
|
m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds);
|
|
|
|
|
|
|
|
template <class... MappedRanges>
|
|
|
|
ConstOperationRoot<T,MappedRanges...>
|
|
|
|
m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const;
|
2018-08-07 21:49:21 +02:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace MultiArrayTools
|
|
|
|
|
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|