// -*- C++ -*- #ifndef __cxz_array_h__ #define __cxz_array_h__ #include #include "cxz_array_base.h" #include "ranges/anonymous_range.h" namespace CNORXZ { template struct ArrayCatter; template struct ArrayCatter { template static auto cat(const Array& ma) -> Array { return ma; } }; template class Array : public MutableArrayBase { public: typedef ContainerRange CRange; typedef ArrayBase MAB; typedef ConstContainerIndex IndexType; using ArrayBase::operator[]; using MutableArrayBase::operator[]; DEFAULT_MEMBERS(Array); Array(const std::shared_ptr&... ranges); Array(const std::shared_ptr&... ranges, const T& val); Array(const std::shared_ptr&... ranges, const vector& vec); Array(const std::shared_ptr&... ranges, vector&& vec); template Array(const std::shared_ptr&... ranges, Array&& in); // same effect as format Array(const typename CRange::Space& space); Array(const typename CRange::Space& space, const vector& vec); Array(Array&& ama, SIZET... sizes); // Only if ALL ranges have default extensions: //Array(const vector& vec); //Array(vector&& vec); // template // Array(const Array,Range3> in); // implement contstructor using FunctionalArray as Input !!! //template //Array& operator=(const Array,Range3> in); virtual T& operator[](const IndexType& i) final; virtual const T& operator[](const IndexType& i) const final; virtual T& at(const typename IndexType::MetaType& meta) override; virtual const T& at(const typename IndexType::MetaType& meta) const override; virtual bool isConst() const override; virtual bool isSlice() const override; template Array format(const std::shared_ptr&... nrs); // reformat array using 'nr' which in // total must have the same size as mRange template Array format(const std::tuple...>& nrs); template Slice slformat(const std::shared_ptr&... nrs); template ConstSlice slformat(const std::shared_ptr&... nrs) const; virtual const T* data() const override; virtual T* data() override; virtual vector& vdata() { return mCont; } virtual const vector& vdata() const { return mCont; } vector&& vmove() { MAB::mInit = false; return std::move(mCont); } virtual std::shared_ptr > anonymous(bool slice = false) const override; //virtual std::shared_ptr > anonymousMove() override; auto cat() const -> decltype(ArrayCatter::cat(*this)); operator T() const; Array& operator=(const T& in); Array& operator+=(const Array& in); Array& operator-=(const Array& in); Array& operator*=(const T& in); Array& operator/=(const T& in); template friend class Array; private: vector mCont; }; template using Scalar = Array; template Scalar scalar(const T& in); template struct ArrayCatter > { template static auto cat(const Array,Ranges...>& ma) -> Array { auto sma = *ma.begin(); const size_t smas = sma.size(); const size_t mas = ma.size(); auto cr = ma.range()->cat(sma.range()); vector ov; ov.reserve(mas * smas); for(auto& x: ma){ assert(x.size() == smas); ov.insert(ov.end(), x.vdata().begin(), x.vdata().end()); } return Array(cr->space(), std::move(ov)); } }; } /* ========================= * * --- TEMPLATE CODE --- * * ========================= */ #endif