#ifndef __multi_array_base_h__ #define __multi_array_base_h__ #include #include #include #include #include #include "base_def.h" #include "mbase_def.h" #include "ranges/rheader.h" namespace MultiArrayTools { template using IPTR = std::shared_ptr; template inline auto operator|(const IPTR& i1, const IPTR& i2) -> decltype(std::make_tuple(i1->THIS(),i2->THIS())) { return std::make_tuple(i1->THIS(),i2->THIS()); } template inline auto operator|(const IPTR& i1, const std::tuple...>& i2) -> decltype(std::tuple_cat(std::make_tuple(i1),i2)) { return std::tuple_cat(std::make_tuple(i1),i2); } template inline auto operator|(const std::tuple...>& i1, const IPTR& i2) -> decltype(std::tuple_cat(i1,std::make_tuple(i2))) { return std::tuple_cat(i1,std::make_tuple(i2)); } template inline auto operator~(const IPTR& i) -> decltype(std::make_tuple(i)) { return std::make_tuple(i); } // Explicitely specify subranges in template argument !!! template class MultiArrayBase { public: typedef T value_type; typedef ContainerRange CRange; typedef ContainerIndex IndexType; protected: bool mInit = false; std::shared_ptr mRange; std::shared_ptr mProtoI; public: DEFAULT_MEMBERS(MultiArrayBase); MultiArrayBase(const std::shared_ptr&... ranges); MultiArrayBase(const typename CRange::Space& space); virtual ~MultiArrayBase() = default; template const T& operator[](const ContainerIndex& i); const T& operator[](const std::tuple...>& is) const; 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& range() const; virtual bool isConst() const; virtual std::shared_ptr > anonymous(bool slice = false) const = 0; virtual ConstOperationRoot op(const std::shared_ptr& ind) const; virtual ConstOperationRoot operator()(const std::shared_ptr&... inds) const; template ConstOperationRoot m(const std::shared_ptr&... inds) const; virtual bool isInit() const; template auto getRangePtr() const -> decltype(mRange->template getPtr()); }; template class MutableMultiArrayBase : public MultiArrayBase { public: typedef ContainerRange CRange; typedef MultiArrayBase MAB; typedef ContainerIndex IndexType; using MultiArrayBase::operator[]; using MultiArrayBase::at; using MultiArrayBase::data; using MultiArrayBase::begin; using MultiArrayBase::end; DEFAULT_MEMBERS(MutableMultiArrayBase); MutableMultiArrayBase(const std::shared_ptr&... ranges); MutableMultiArrayBase(const typename CRange::Space& space); template T& operator[](const ContainerIndex& i); T& operator[](const std::tuple...>& is); 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; virtual std::shared_ptr > anonymousMove() = 0; virtual ConstOperationRoot op(const std::shared_ptr& ind) const override; virtual ConstOperationRoot operator()(const std::shared_ptr&... inds) const override; virtual OperationRoot op(const std::shared_ptr& ind); virtual OperationRoot operator()(const std::shared_ptr&... inds); template OperationRoot m(const std::shared_ptr&... inds); template ConstOperationRoot m(const std::shared_ptr&... inds) const; }; } // end namespace MultiArrayTools /* ========================= * * --- TEMPLATE CODE --- * * ========================= */ #endif