// -*- C++ -*- #ifndef __map_range_h__ #define __map_range_h__ #include #include #include #include #include "mbase_def.h" #include "ranges/range_base.h" #include "ranges/index_base.h" #include "ranges/rpack_num.h" #include "map_range_factory_product_map.h" #include "ranges/x_to_string.h" #include "ranges/type_map.h" #include "xfor/xfor.h" namespace MultiArrayTools { namespace { using namespace MultiArrayHelper; } template auto mkMapOp(const std::shared_ptr& func, const std::shared_ptr&... is) -> decltype(std::make_tuple(FunctionalMultiArray().exec(is...), FunctionalMultiArray())) { typedef FunctionalMultiArray FMA; if(Func::FISSTATIC){ FMA fma(is->range()...); return std::make_tuple(fma.exec(is...),fma); } else { FMA fma(is->range()...,func); return std::make_tuple(fma.exec(is...),fma); } } template //template class OpExpr : public ExpressionBase { public: //typedef typename Index::OIType OIType; //typedef SingleIndex OIType; static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE + Op::SIZE; static constexpr size_t NHLAYER = Expr::NHLAYER + 1; private: OpExpr() = default; const Index* mIndPtr; //const OIType* mIndPtr; size_t mSPos; size_t mMax; size_t mStep; Expr mExpr; Op mOp; typedef decltype(mOp.rootSteps(std::declval()).extend( mExpr.rootSteps(std::declval()) )) ExtType; ExtType mExt; public: OpExpr(const OpExpr& in) = default; OpExpr(OpExpr&& in) = default; OpExpr& operator=(const OpExpr& in) = default; OpExpr& operator=(OpExpr&& in) = default; OpExpr(const Op& mapf, const Index* ind, size_t step, Expr ex); virtual std::shared_ptr deepCopy() const override final; template inline auto vec() const { return *this; } inline void operator()(size_t mlast, DExt last) override final; inline void operator()(size_t mlast, ExtType last); inline void operator()(size_t mlast = 0) override final; auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final; virtual DExt dExtension() const override final; }; template class GenMapIndex : public IndexInterface, typename Op::value_type> //std::tuple > { public: typedef IndexInterface, typename Op::value_type> IB; //std::tuple > IB; typedef std::tuple...> IndexPack; //typedef std::tuple MetaType; typedef typename Op::value_type MetaType; typedef GenMapRange RangeType; typedef GenMapIndex IType; //typedef SingleIndex OIType; static constexpr IndexType sType() { return IndexType::SINGLE; } static constexpr size_t sDim() { return sizeof...(Indices); } static constexpr size_t totalDim() { return mkTotalDim(); } static void check_type() { static_assert( std::is_same::value, "inconsitent value types" ); } static constexpr SpaceType STYPE = XSTYPE; static constexpr bool PARALLEL = false; private: IndexPack mIPack; std::array mBlockSizes; std::shared_ptr mOutIndex; public: const IndexPack& pack() const { return mIPack; } GenMapIndex() = delete; // NO DEFAULT HERE !!! // ( have to assign sub-indices (ptr!) correctly ) //MapIndex(const MapIndex& in); //MapIndex& operator=(const MapIndex& in); template GenMapIndex(const std::shared_ptr& range); template GenMapIndex& up(); template GenMapIndex& down(); template auto get() const -> decltype( *std::get( mIPack ) )&; template auto getPtr() const -> decltype( std::get( mIPack ) )&; template size_t getBlockSize() const { return std::get(mBlockSizes); } std::shared_ptr outIndex() const; // raplace instances (in contrast to its analogon in ContainerIndex // MultiIndices CANNOT be influences be its subindices, so there is // NO foreign/external controll) // Do NOT share index instances between two or more MapIndex instances GenMapIndex& operator()(const std::shared_ptr&... indices); GenMapIndex& operator()(const std::tuple...>& indices); // ==== >>>>> STATIC POLYMORPHISM <<<<< ==== IndexType type() const; GenMapIndex& operator=(size_t pos); GenMapIndex& operator++(); GenMapIndex& operator--(); int pp(std::intptr_t idxPtrNum); int mm(std::intptr_t idxPtrNum); std::string stringMeta() const; MetaType meta() const; GenMapIndex& at(const MetaType& metaPos); size_t posAt(const MetaType& metaPos) const; size_t dim() const; bool first() const; bool last() const; std::shared_ptr range() const; template auto getPtr() -> decltype( std::get( mIPack ) )&; size_t getStepSize(size_t n) const; template auto ifor(size_t step, Exprs exs) const; // first step arg not used! template auto pifor(size_t step, Exprs exs) const; // NO MULTITHREADING template auto iforh(size_t step, Exprs exs) const; }; /************************* * MapRangeFactory * *************************/ // NOT THREAD SAVE template class GenMapRangeFactory : public RangeFactoryBase { public: //typedef SingleRange ORType; typedef GenMapRange oType; GenMapRangeFactory() = delete; template GenMapRangeFactory(const std::shared_ptr& outr, const std::tuple& mapf, const std::shared_ptr&... rs); template GenMapRangeFactory(const std::shared_ptr& outr, const std::tuple& mapf, const typename GenMapRange::Space& st); template GenMapRangeFactory(const std::tuple& mapf, const std::shared_ptr&... rs); template GenMapRangeFactory(const std::tuple& mapf, const typename GenMapRange::Space& space); virtual std::shared_ptr create() override; private: std::shared_ptr checkIfCreated(const std::tuple...>& ptp); }; /****************** * MapRange * ******************/ template class GenMapRange : public RangeInterface > { public: typedef RangeBase RB; typedef std::tuple...> Space; typedef GenMapIndex IndexType; typedef typename Op::value_type MetaType; protected: GenMapRange() = delete; GenMapRange(const GenMapRange& in) = delete; GenMapRange& operator=(const GenMapRange& in) = delete; template GenMapRange(const std::shared_ptr& outr, const std::tuple& mapf, const std::shared_ptr&... rs); template GenMapRange(const std::shared_ptr& outr, const std::tuple& mapf, const Space& space); template GenMapRange(const std::tuple& mapf, const Space& space); template GenMapRange(const std::tuple& mapf, const std::shared_ptr&... rs); Space mSpace; Op mMapf; //Op mMapf; std::shared_ptr mOutRange; MultiArray mMapMult; vector mMapPos; private: template void mkOutRange(const MA& mapf); public: static constexpr size_t sdim = sizeof...(Ranges); template auto get() const -> decltype( *std::get( mSpace ) )&; template auto getPtr() const -> decltype( std::get( mSpace ) )&; std::shared_ptr outRange() const; const Op& map() const; virtual size_t dim() const final; virtual size_t size() const final; virtual SpaceType spaceType() const final; virtual DataHeader dataHeader() const final; virtual vector typeNum() const final; virtual size_t cmeta(char* target, size_t pos) const final; virtual size_t cmetaSize() const final; virtual std::string stringMeta(size_t pos) const final; virtual vector data() const final; const Space& space() const; virtual IndexType begin() const final; virtual IndexType end() const final; const MultiArray& mapMultiplicity() const; ConstSlice explMapMultiplicity() const; vector mapPos() const; /* template auto cat(const std::shared_ptr >& erange) -> std::shared_ptr >; */ friend GenMapRangeFactory; static constexpr bool HASMETACONT = false; static constexpr bool defaultable = false; static constexpr size_t ISSTATIC = SubProp::ISSTATIC; static constexpr size_t SIZE = SubProp::SIZE; }; // for legacy template using MapIndex = GenMapIndex; template using MapRangeFactory = GenMapRangeFactory; template using MapRange = GenMapRange; template auto mapResult/* >*/(const std::shared_ptr >& ind) -> decltype(ind->outIndex()) { return ind->outIndex(); } } #endif