cnorxz/src/include/ranges/mrange.h

130 lines
2.9 KiB
C
Raw Normal View History

2017-02-16 11:20:40 +01:00
// -*- C++ -*-
#ifndef __cxz_mrange_h__
#define __cxz_mrange_h__
2017-02-16 11:20:40 +01:00
2022-09-11 02:48:30 +02:00
#include "base/base.h"
#include "range_base.h"
#include "index_base.h"
2022-10-16 23:05:48 +02:00
#include "xpr/xpr.h"
2017-02-16 11:20:40 +01:00
2021-07-28 20:29:56 +02:00
namespace CNORXZ
2017-02-16 11:20:40 +01:00
{
template <class... Indices>
class MIndex : public IndexInterface<MIndex<Indices...>,
Tuple<typename Indices::MetaType...> >
2017-02-16 11:20:40 +01:00
{
public:
typedef IndexInterface<MIndex<Indices...>,
2022-09-11 02:48:30 +02:00
Tuple<typename Indices::MetaType...> > IB;
typedef Tuple<Sptr<Indices>...> IndexPack;
typedef Tuple<typename Indices::MetaType...> MetaType;
typedef MRange<typename Indices::RangeType...> RangeType;
2018-07-28 15:27:11 +02:00
2017-02-28 19:29:52 +01:00
// NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly )
MIndex(const MIndex& i);
MIndex(MIndex&& i);
MIndex& operator=(const MIndex& i);
MIndex& operator=(MIndex&& i);
2017-05-24 19:01:02 +02:00
MIndex(const RangePtr& range, SizeT pos = 0);
// replace sub-index instances; only use if you know what you are doing!
MIndex& operator()(Sptr<Indices>&... indices);
MIndex& operator()(const MIndex& indices);
const IndexPack& pack() const { return mIPack; }
const auto& getBlockSizes() const { return mBlockSizes; }
MIndex& operator=(SizeT pos);
MIndex& operator++();
MIndex& operator--();
MIndex operator+(Int n) const;
MIndex operator-(Int n) const;
MIndex& operator+=(Int n);
MIndex& operator-=(Int n);
2022-10-16 23:05:48 +02:00
SizeT max() const;
decltype(auto) id() const;
SizeT operator*() const;
SizeT operator->() const;
2022-09-11 02:48:30 +02:00
int pp(PtrId idxPtrNum);
int mm(PtrId idxPtrNum);
2022-09-11 02:48:30 +02:00
SizeT dim();
Sptr<RangeType> range();
2022-10-16 23:05:48 +02:00
template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const;
String stringMeta() const;
MetaType meta() const;
MIndex& at(const MetaType& metaPos);
2022-10-16 23:05:48 +02:00
template <class PosT, class Xpr>
auto ifor(const PosT& step, const Xpr& xpr) const;
private:
MIndex() = default;
IndexPack mIPack;
Arr<SizeT,sizeof...(Indices)+1> mBlockSizes;
Sptr<RangeType> mRange;
2019-01-15 17:41:43 +01:00
2017-02-16 11:20:40 +01:00
};
// NOT THREAD SAVE
template <class... Ranges>
class MRangeFactory : public RangeFactoryBase
{
public:
MRangeFactory() = delete;
MRangeFactory(const Sptr<Ranges>&... rs);
MRangeFactory(const Tuple<Sptr<Ranges>...>& rs);
2017-07-28 11:33:31 +02:00
private:
virtual void make() override final;
Tuple<Sptr<Ranges>...> mRs;
};
2017-02-21 17:41:48 +01:00
2017-02-16 11:20:40 +01:00
template <class... Ranges>
class MRange : public RangeInterface<MIndex<typename Ranges::IndexType...> >
2017-02-16 11:20:40 +01:00
{
public:
2017-08-04 11:27:47 +02:00
typedef RangeBase RB;
typedef MIndex<typename Ranges::IndexType...> IndexType;
2022-09-11 02:48:30 +02:00
typedef Tuple<typename Ranges::IndexType::MetaType...> MetaType;
const Space& space() const;
2017-08-04 14:57:19 +02:00
2022-09-11 02:48:30 +02:00
SizeT getMeta(const MetaType& metaPos) const;
2021-01-11 11:16:29 +01:00
2022-09-11 02:48:30 +02:00
virtual Sptr<RangeBase> sub(SizeT num) const override;
2018-11-30 00:16:28 +01:00
2022-09-11 02:48:30 +02:00
virtual SizeT dim() const final;
virtual SizeT size() const final;
virtual String stringMeta(SizeT pos) const final;
2017-02-28 19:29:52 +01:00
friend MRangeFactory<Ranges...>;
2017-05-24 19:01:02 +02:00
protected:
MRange() = delete;
MRange(const MRange& in) = delete;
MRange& operator=(const MRange& in) = delete;
Tuple<Sptr<Ranges>...> mRs;
2017-02-16 11:20:40 +01:00
};
}
#endif