#ifndef __dynamic_range_h__ #define __dynamic_range_h__ #include #include #include "ranges/rbase_def.h" #include "ranges/range_base.h" #include "ranges/index_base.h" #include "xfor/xfor.h" #include "ranges/x_to_string.h" #include "ranges/type_map.h" #include "ranges/dynamic_meta.h" #include "index_wrapper.h" namespace CNORXZ { namespace { using namespace CNORXZInternal; } class DynamicIndex : public IndexInterface> { private: typedef vector,size_t>> IVecT; typedef std::map> IMapT; static IMapT sIMap; IVecT mIVec; bool mIvecInit = false; public: typedef IndexInterface> IB; typedef vector MetaType; typedef DynamicRange RangeType; typedef DynamicIndex IType; DynamicIndex(const std::shared_ptr& range); static void clearIMap() { sIMap.clear(); } template static std::shared_ptr getIndexFromMap(const std::string& name) { auto tmp = std::dynamic_pointer_cast>(sIMap.at(name)); assert(tmp); return tmp->getIndex(); } static const std::shared_ptr& getIndexWFromMap(const std::string& name) { return sIMap.at(name); } static bool checkIndexMap(const std::string& name) { return sIMap.count(name) != 0; } static constexpr IndexType sType() { return IndexType::SINGLE; } static constexpr size_t totalDim() { return 1; } static constexpr size_t sDim() { return 1; } static constexpr SpaceType STYPE = SpaceType::DYN; IndexType type() const; DynamicIndex& operator=(size_t pos); DynamicIndex& operator++(); DynamicIndex& operator--(); DynamicIndex& operator()(const IVecT& ivec); DynamicIndex& operator()(const vector>& ivec); DynamicIndex& operator()(const vector& inames); template DynamicIndex& operator()(const std::shared_ptr&... is); DynamicIndex& sync(); int pp(std::intptr_t idxPtrNum); int mm(std::intptr_t idxPtrNum); std::string stringMeta() const; MetaType meta() const; const MetaType* metaPtr() const; DynamicIndex& at(const MetaType& metaPos); size_t posAt(const MetaType& metaPos) const; //bool isMeta(const MetaType& metaPos) const; size_t dim() const; bool last() const; bool first() const; const IndexW& get(size_t n) const; const std::shared_ptr& getP(size_t n) const; std::shared_ptr range(); template void getPtr(); size_t getStepSize(size_t n) const; template DynamicExpression ifor(size_t step, Expr ex) const; template DynamicExpression iforh(size_t step, Expr ex) const; template DynamicExpression pifor(size_t step, Expr ex) const; }; // NOT THREAD SAVE!! class DynamicRangeFactory : public RangeFactoryBase { public: typedef DynamicRange oType; DynamicRangeFactory(); template DynamicRangeFactory(const std::tuple...>& origs); template DynamicRangeFactory(std::shared_ptr... origs); DynamicRangeFactory(const vector>& origs); template void append(std::shared_ptr r); std::shared_ptr create(); private: std::shared_ptr checkIfCreated(const vector >& pvec); static std::map,vector > mAleadyCreated; bool mProductCreated = false; }; class DynamicRange : public RangeInterface { public: static constexpr bool defaultable = true; static constexpr size_t ISSTATIC = 0; static constexpr size_t SIZE = -1; static constexpr bool HASMETACONT = false; typedef RangeBase RB; typedef DynamicIndex IndexType; typedef DynamicRange RangeType; typedef vector MetaType; typedef DynamicRangeFactory FType; private: DynamicRange() = default; DynamicRange(const DynamicRange& in) = default; template DynamicRange(const std::tuple...>& origs); template DynamicRange(std::shared_ptr... origs); DynamicRange(const vector>& origs); size_t mSize = 1; bool mEmpty = true; vector > mOrig; public: virtual size_t size() const final; virtual size_t dim() const final; MetaType get(size_t pos) const; size_t getMeta(const MetaType& metaPos) const; virtual IndexType begin() const final; virtual IndexType end() 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; std::shared_ptr sub(size_t num) const; template std::shared_ptr fullsub(size_t num) const; template std::shared_ptr > scast(SIZET... sizes) const; // save cast const vector >& orig() const; void sreplace(const std::shared_ptr in, size_t num); bool isEmpty() const; friend DynamicRangeFactory; static DynamicRangeFactory factory() { return DynamicRangeFactory(); } }; } // namespace CNORXZ namespace CNORXZ { namespace RangeHelper { template <> inline void resolveSetRange(std::shared_ptr& rp, const vector >& orig, size_t origpos, size_t size); template <> inline void setRangeToVec(vector >& v, std::shared_ptr r); template <> inline size_t getStepSize(const DynamicIndex& ii, std::intptr_t j); } } //#include "dynamic_range.cc.h" #endif