// -*- C++ -*- #ifndef __container_range_h__ #define __container_range_h__ #include #include #include #include "base_def.h" #include "range_base.h" #include "index_base.h" namespace MultiArrayTools { template class ContainerIndex : public IndexInterface > { public: typedef IndexBase IB; typedef std::tuple MetaType; typedef std::tuple...> IndexPack; typedef IndexInterface > IndexI; protected: bool mExternControl = false; IndexPack mIPack; public: ContainerIndex() = default; ContainerIndex(const ContainerIndex& in); ContainerIndex& operator=(const ContainerIndex& in); template ContainerIndex(const std::shared_ptr& range); virtual ContainerIndex& operator++() override; virtual ContainerIndex& operator--() override; virtual ContainerIndex& operator=(size_t pos) override; virtual MetaType meta() const override; virtual ContainerIndex& at(const MetaType& metaPos) override; virtual bool first() const override; virtual bool last() const override; virtual size_t dim() const override; ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true template auto get() const -> decltype( *std::get( mIPack ) )&; ContainerIndex& operator()(const std::shared_ptr&... inds); // control via external indices ContainerIndex& operator()(); // -> sync; just to shorten the code }; template class ContainerRangeFactory : public RangeFactoryBase { public: typedef ContainerRange oType; ContainerRangeFactory() = delete; ContainerRangeFactory(const std::shared_ptr&... rs); ContainerRangeFactory(const typename ContainerRange::SpaceType& space); virtual std::shared_ptr create() override; protected: }; template class ContainerRange : public RangeInterface > { public: typedef RangeBase RB; typedef std::tuple...> SpaceType; typedef typename RangeInterface >::IndexType IndexType; protected: ContainerRange() = default; ContainerRange(const ContainerRange& in) = delete; ContainerRange& operator=(const ContainerRange& in) = delete; ContainerRange(const std::shared_ptr&... rs); ContainerRange(const SpaceType& space); SpaceType mSpace; public: static const size_t sdim = sizeof...(Ranges); virtual size_t dim() const override; virtual size_t size() const override; template auto get() const -> decltype( *std::get( mSpace ) )&; template auto getPtr() const -> decltype( std::get( mSpace ) )&; virtual IndexType begin() const override; virtual IndexType end() const override; virtual std::shared_ptr index() const override; friend ContainerRangeFactory; }; } // end namespace MultiArrayTools #include "container_range.cc" #endif