2017-07-27 14:48:41 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
#ifndef __cxz_container_index_h__
|
|
|
|
#define __cxz_container_index_h__
|
2017-07-27 14:48:41 +02:00
|
|
|
|
|
|
|
#include <cstdlib>
|
2017-07-28 14:02:44 +02:00
|
|
|
#include <tuple>
|
|
|
|
#include <memory>
|
|
|
|
|
2017-12-17 17:40:55 +01:00
|
|
|
#include "ranges/range_base.h"
|
|
|
|
#include "ranges/index_base.h"
|
2021-05-28 20:35:24 +02:00
|
|
|
#include "mbase_def.h"
|
|
|
|
#include "statics/static_for.h"
|
|
|
|
#include "ranges/range_helper.h"
|
2017-07-27 14:48:41 +02:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2017-07-27 14:48:41 +02:00
|
|
|
{
|
2017-08-25 22:03:20 +02:00
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
class ConstContainerIndex : public IndexInterface<ConstContainerIndex<T,Indices...>,
|
2022-08-08 14:55:07 +02:00
|
|
|
std::tuple<typename Indices::MetaType...> >
|
2017-08-04 16:19:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
typedef IndexInterface<ConstContainerIndex<T,Indices...>,
|
2017-12-11 18:49:43 +01:00
|
|
|
std::tuple<typename Indices::MetaType...> > IB;
|
2017-08-11 15:26:10 +02:00
|
|
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
2017-08-04 16:19:50 +02:00
|
|
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
2021-05-28 19:48:27 +02:00
|
|
|
typedef ContainerRange<typename Indices::RangeType...> RangeType;
|
2017-08-04 16:19:50 +02:00
|
|
|
|
2018-03-02 16:37:11 +01:00
|
|
|
static constexpr IndexType sType() { return IndexType::CONT; }
|
|
|
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
2021-05-27 23:29:04 +02:00
|
|
|
static constexpr size_t totalDim() { return (... * Indices::totalDim()); }
|
2018-02-16 18:17:22 +01:00
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
static constexpr SpaceType STYPE = SpaceType::ANY;
|
2019-01-15 17:41:43 +01:00
|
|
|
static constexpr bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
|
|
|
|
2018-10-06 13:14:24 +02:00
|
|
|
template <typename X>
|
2021-05-28 17:29:13 +02:00
|
|
|
using CIX = ConstContainerIndex<X,Indices...>;
|
2018-10-06 13:14:24 +02:00
|
|
|
|
|
|
|
template <typename X>
|
|
|
|
friend class CIX;
|
2018-07-28 15:27:11 +02:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
private:
|
2018-03-02 13:35:50 +01:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex() = default;
|
2018-03-02 13:35:50 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
bool mNonTrivialBlocks = false;
|
2017-08-04 16:19:50 +02:00
|
|
|
bool mExternControl = false;
|
|
|
|
IndexPack mIPack;
|
2017-08-30 19:41:49 +02:00
|
|
|
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
2018-08-20 17:50:04 +02:00
|
|
|
const T* mData = nullptr;
|
2018-03-05 00:04:50 +01:00
|
|
|
std::intptr_t mObjPtrNum;
|
2021-05-29 00:03:48 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t mCPos;
|
2017-08-30 19:41:49 +02:00
|
|
|
|
2017-08-04 16:19:50 +02:00
|
|
|
public:
|
2017-12-17 14:16:37 +01:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex(const ConstContainerIndex& in) = default;
|
|
|
|
ConstContainerIndex& operator=(const ConstContainerIndex& in) = default;
|
2018-10-06 13:14:24 +02:00
|
|
|
|
2021-05-28 21:20:07 +02:00
|
|
|
ConstContainerIndex(const ConstContainerIndex& in, bool copy);
|
2018-12-25 17:48:52 +01:00
|
|
|
|
2021-05-28 21:20:07 +02:00
|
|
|
ConstContainerIndex& copy(const ConstContainerIndex& in);
|
2018-12-25 17:48:52 +01:00
|
|
|
|
2018-10-06 13:14:24 +02:00
|
|
|
template <typename X>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& operator=(const ConstContainerIndex<X,Indices...>& in);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-08-04 16:19:50 +02:00
|
|
|
template <class MRange>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
2018-03-05 00:04:50 +01:00
|
|
|
std::intptr_t objPtrNum);
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
template <class MRange>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
2018-03-05 00:04:50 +01:00
|
|
|
std::intptr_t objPtrNum,
|
2018-02-16 18:17:22 +01:00
|
|
|
const std::array<size_t,sizeof...(Indices)+1>& blockSizes);
|
2018-03-02 13:35:50 +01:00
|
|
|
|
2017-12-12 11:15:39 +01:00
|
|
|
|
2018-09-16 18:53:28 +02:00
|
|
|
template <size_t N>
|
|
|
|
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
|
|
|
|
2018-01-05 13:56:16 +01:00
|
|
|
const IndexPack& pack() const { return mIPack; }
|
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
|
|
|
|
ConstContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
|
|
|
ConstContainerIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& inds);
|
|
|
|
ConstContainerIndex& operator()(); // -> sync; just to shorten the code
|
2017-12-12 16:16:09 +01:00
|
|
|
|
2017-12-11 18:49:43 +01:00
|
|
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
|
|
|
|
2017-12-26 15:13:50 +01:00
|
|
|
IndexType type() const;
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& operator++();
|
|
|
|
ConstContainerIndex& operator--();
|
2017-08-30 17:56:38 +02:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& operator=(size_t pos);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
int pp(std::intptr_t idxPtrNum);
|
|
|
|
int mm(std::intptr_t idxPtrNum);
|
2018-07-22 16:16:24 +02:00
|
|
|
|
|
|
|
std::string stringMeta() const;
|
2018-02-16 18:17:22 +01:00
|
|
|
MetaType meta() const;
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& at(const MetaType& metaPos);
|
2017-12-11 18:49:43 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
size_t dim() const;
|
|
|
|
bool first() const;
|
|
|
|
bool last() const;
|
|
|
|
bool sliceMode() const;
|
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
std::shared_ptr<RangeType> range();
|
2017-08-04 16:19:50 +02:00
|
|
|
|
2017-08-07 17:11:03 +02:00
|
|
|
template <size_t N>
|
2021-05-29 00:03:48 +02:00
|
|
|
auto& get() const;
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() const;
|
2017-08-28 18:28:43 +02:00
|
|
|
|
2017-12-17 14:16:37 +01:00
|
|
|
size_t getStepSize(size_t n);
|
2017-12-24 18:14:07 +01:00
|
|
|
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Exprs>
|
2021-05-06 19:04:26 +02:00
|
|
|
auto ifor(size_t step, Exprs exs) const;
|
2018-01-15 14:56:22 +01:00
|
|
|
|
|
|
|
template <class Exprs>
|
2021-05-06 19:04:26 +02:00
|
|
|
auto iforh(size_t step, Exprs exs) const;
|
2018-01-15 14:56:22 +01:00
|
|
|
|
2019-01-15 17:41:43 +01:00
|
|
|
template <class Exprs>
|
2021-05-06 19:04:26 +02:00
|
|
|
auto pifor(size_t step, Exprs exs) const;
|
2019-01-15 17:41:43 +01:00
|
|
|
|
2018-03-05 00:04:50 +01:00
|
|
|
std::intptr_t container() const;
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks);
|
2018-03-05 00:04:50 +01:00
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
// Iterator Stuff
|
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& setData(const T* data);
|
2018-02-15 20:06:14 +01:00
|
|
|
|
|
|
|
const T& operator*() const;
|
|
|
|
const T* operator->() const;
|
2018-09-08 18:46:04 +02:00
|
|
|
//T& operator*();
|
|
|
|
//T* operator->();
|
2018-02-15 20:06:14 +01:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex operator++(int);
|
|
|
|
ConstContainerIndex operator--(int);
|
|
|
|
ConstContainerIndex& operator+=(int diff);
|
|
|
|
ConstContainerIndex& operator-=(int diff);
|
|
|
|
ConstContainerIndex operator+(int num) const;
|
|
|
|
ConstContainerIndex operator-(int num) const;
|
2018-02-15 20:06:14 +01:00
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
int operator-(const ConstContainerIndex& it) const;
|
2018-02-15 20:06:14 +01:00
|
|
|
const T& operator[](int num) const;
|
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
bool operator<(const ConstContainerIndex& it) const;
|
|
|
|
bool operator>(const ConstContainerIndex& it) const;
|
|
|
|
bool operator<=(const ConstContainerIndex& it) const;
|
|
|
|
bool operator>=(const ConstContainerIndex& it) const;
|
2018-02-15 20:06:14 +01:00
|
|
|
|
2017-08-04 16:19:50 +02:00
|
|
|
};
|
2018-03-01 18:16:12 +01:00
|
|
|
|
2021-05-29 00:03:48 +02:00
|
|
|
template <typename T, class... Indices>
|
|
|
|
class ContainerIndex : public ConstContainerIndex<T,Indices...>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef ConstContainerIndex<T,Indices...> CCI;
|
|
|
|
typedef CCI IB;
|
|
|
|
typedef typename CCI::MetaType MetaType;
|
|
|
|
typedef typename CCI::IndexPack IndexPack;
|
|
|
|
typedef typename CCI::RangeType RangeType;
|
|
|
|
|
|
|
|
static constexpr IndexType sType() { return CCI::sType(); }
|
|
|
|
static constexpr size_t sDim() { return CCI::sDim(); }
|
|
|
|
static constexpr size_t totalDim() { return CCI::totalDim(); }
|
|
|
|
|
|
|
|
static constexpr SpaceType STYPE = CCI::STYPE;
|
|
|
|
static constexpr bool PARALLEL = CCI::PARALLEL;
|
|
|
|
|
|
|
|
template <typename X>
|
|
|
|
using CIX = ContainerIndex<X,Indices...>;
|
|
|
|
|
|
|
|
template <typename X>
|
|
|
|
friend class CIX;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ContainerIndex() = default;
|
|
|
|
|
|
|
|
T* mMData = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ContainerIndex(const ContainerIndex& in) = default;
|
|
|
|
ContainerIndex& operator=(const ContainerIndex& in) = default;
|
|
|
|
|
|
|
|
ContainerIndex(const ContainerIndex& in, bool copy) : CCI(in,copy)
|
|
|
|
{ mMData = in.mMData; }
|
|
|
|
|
|
|
|
ContainerIndex(const ConstContainerIndex<T,Indices...>& in, T* data) : CCI(in)
|
|
|
|
{ mMData = data; }
|
|
|
|
|
|
|
|
ContainerIndex(const ConstContainerIndex<T,Indices...>& in, T* data, bool copy) :
|
|
|
|
CCI(in,copy)
|
|
|
|
{ mMData = data; }
|
|
|
|
|
|
|
|
ContainerIndex& copy(const ContainerIndex& in)
|
|
|
|
{ CCI::copy(in); mMData = in.mMData; }
|
|
|
|
|
|
|
|
template <typename X>
|
|
|
|
ContainerIndex& operator=(const ContainerIndex<X,Indices...>& in)
|
|
|
|
{ CCI::operator=(in); return *this; }
|
|
|
|
|
|
|
|
template <class MRange>
|
|
|
|
ContainerIndex(const std::shared_ptr<MRange>& range,
|
|
|
|
std::intptr_t objPtrNum) : CCI(range, objPtrNum) {}
|
|
|
|
|
|
|
|
template <class MRange>
|
|
|
|
ContainerIndex(const std::shared_ptr<MRange>& range,
|
|
|
|
std::intptr_t objPtrNum,
|
|
|
|
const std::array<size_t,sizeof...(Indices)+1>& blockSizes)
|
|
|
|
: CCI(range, objPtrNum, blockSizes) {}
|
|
|
|
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
size_t getBlockSize() const { return CCI::template getBlockSize<N>(); }
|
|
|
|
|
|
|
|
const IndexPack& pack() const { CCI::pack(); return *this; }
|
|
|
|
|
|
|
|
ContainerIndex& sync() { return CCI::sync(); return *this; }
|
|
|
|
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds)
|
|
|
|
{ CCI::operator()(inds...); return *this; }
|
|
|
|
ContainerIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
|
|
|
|
{ CCI::operator()(inds); return *this; }
|
|
|
|
ContainerIndex& operator()() { CCI::operator()(); return *this; }
|
|
|
|
|
|
|
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
|
|
|
|
|
|
|
IndexType type() const { return CCI::type(); }
|
|
|
|
|
|
|
|
ContainerIndex& operator++() { CCI::operator++(); return *this; }
|
|
|
|
ContainerIndex& operator--() { CCI::operator--(); return *this; }
|
|
|
|
|
|
|
|
ContainerIndex& operator=(size_t pos) { CCI::operator=(pos); return *this; }
|
|
|
|
|
|
|
|
int pp(std::intptr_t idxPtrNum) { return CCI::pp(idxPtrNum); }
|
|
|
|
int mm(std::intptr_t idxPtrNum) { return CCI::mm(idxPtrNum); }
|
|
|
|
|
|
|
|
std::string stringMeta() const { return CCI::stringMeta; }
|
|
|
|
MetaType meta() const { return CCI::meta(); }
|
|
|
|
ContainerIndex& at(const MetaType& metaPos) { CCI::at(metaPos); return *this; }
|
|
|
|
|
|
|
|
size_t dim() const { return CCI::dim(); }
|
|
|
|
bool first() const { return CCI::first(); }
|
|
|
|
bool last() const { return CCI::last(); }
|
|
|
|
bool sliceMode() const { return CCI::sliceMode(); }
|
|
|
|
|
|
|
|
std::shared_ptr<RangeType> range() { return CCI::range(); }
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto& get() const { return CCI::template get<N>(); }
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
auto getPtr() const { return CCI::template getPtr<N>(); }
|
|
|
|
|
|
|
|
size_t getStepSize(size_t n) { return getStepSize(n); }
|
|
|
|
|
|
|
|
template <class Exprs>
|
|
|
|
auto ifor(size_t step, Exprs exs) const { return CCI::ifor(step, exs); }
|
|
|
|
|
|
|
|
template <class Exprs>
|
|
|
|
auto iforh(size_t step, Exprs exs) const { return CCI::iforh(step, exs); }
|
|
|
|
|
|
|
|
template <class Exprs>
|
|
|
|
auto pifor(size_t step, Exprs exs) const { return CCI::pifor(step, exs); }
|
|
|
|
|
|
|
|
std::intptr_t container() const { return CCI::container(); }
|
|
|
|
ContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
|
|
|
{ CCI::format(blocks); return *this; }
|
|
|
|
|
|
|
|
// Iterator Stuff
|
|
|
|
|
|
|
|
ContainerIndex& setData(T* data) { CCI::setData(data); mMData = data; return *this; }
|
|
|
|
|
|
|
|
const T& operator*() const { return CCI::operator*(); }
|
|
|
|
const T* operator->() const { return CCI::operator->(); }
|
|
|
|
T& operator*() { return mMData[CCI::mCPos]; }
|
|
|
|
T* operator->() { return &mMData[CCI::mCPos]; }
|
|
|
|
|
|
|
|
ContainerIndex operator++(int) { auto tmp = *this; ++(*this); return tmp; }
|
|
|
|
ContainerIndex operator--(int) { auto tmp = *this; --(*this); return tmp; }
|
|
|
|
ContainerIndex& operator+=(int diff) { CCI::operator+=(diff); return *this; }
|
|
|
|
ContainerIndex& operator-=(int diff) { CCI::operator-=(diff); return *this; }
|
|
|
|
ContainerIndex operator+(int num) const { CCI::operator+(num); return *this; }
|
|
|
|
ContainerIndex operator-(int num) const { CCI::operator-(num); return *this; }
|
|
|
|
|
|
|
|
int operator-(const ContainerIndex& it) const { return CCI::operator-(it); }
|
|
|
|
const T& operator[](int num) const { return CCI::operator[](num); }
|
|
|
|
|
|
|
|
bool operator<(const ContainerIndex& it) const { return CCI::operator<(it); }
|
|
|
|
bool operator>(const ContainerIndex& it) const { return CCI::operator>(it); }
|
|
|
|
bool operator<=(const ContainerIndex& it) const { return CCI::operator<=(it); }
|
|
|
|
bool operator>=(const ContainerIndex& it) const { return CCI::operator>=(it); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // end namespace CNORXZ
|
2017-07-27 14:48:41 +02:00
|
|
|
|
|
|
|
#endif
|