cnorxz/src/include/container_index.h

163 lines
4.6 KiB
C
Raw Normal View History

// -*- C++ -*-
#ifndef __container_index_h__
#define __container_index_h__
#include <cstdlib>
#include <tuple>
#include <memory>
2017-12-17 17:40:55 +01:00
#include "ranges/range_base.h"
#include "ranges/index_base.h"
#include "mbase_def.h"
#include "statics/static_for.h"
#include "ranges/range_helper.h"
namespace MultiArrayTools
{
template <typename T, class... Indices>
2021-05-28 17:29:13 +02:00
class ConstContainerIndex : public IndexInterface<ConstContainerIndex<T,Indices...>,
std::tuple<typename Indices::MetaType...> >,
public std::iterator<std::random_access_iterator_tag,T>
2017-08-04 16:19:50 +02:00
{
public:
2021-05-28 17:29:13 +02:00
typedef IndexInterface<ConstContainerIndex<T,Indices...>,
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;
typedef ContainerRange<typename Indices::RangeType...> RangeType;
2017-08-04 16:19:50 +02: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-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;
template <typename X>
2021-05-28 17:29:13 +02:00
using CIX = ConstContainerIndex<X,Indices...>;
template <typename X>
friend class CIX;
2018-07-28 15:27:11 +02:00
private:
2021-05-28 17:29:13 +02:00
ConstContainerIndex() = default;
bool mNonTrivialBlocks = false;
2017-08-04 16:19:50 +02:00
bool mExternControl = false;
IndexPack mIPack;
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
const T* mData = nullptr;
2018-12-25 17:48:52 +01:00
size_t mCPos;
2018-03-05 00:04:50 +01:00
std::intptr_t mObjPtrNum;
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;
ConstContainerIndex(const ConstContainerIndex& in, bool copy);
2018-12-25 17:48:52 +01:00
ConstContainerIndex& copy(const ConstContainerIndex& in);
2018-12-25 17:48:52 +01:00
template <typename X>
2021-05-28 17:29:13 +02:00
ConstContainerIndex& operator=(const ConstContainerIndex<X,Indices...>& in);
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);
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,
const std::array<size_t,sizeof...(Indices)+1>& blockSizes);
template <size_t N>
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
2017-12-12 11:15:39 +01:00
template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
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
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() const;
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-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;
MetaType meta() const;
2021-05-28 17:29:13 +02:00
ConstContainerIndex& at(const MetaType& metaPos);
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
template <size_t N>
2017-12-17 14:16:37 +01:00
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
2017-12-17 14:16:37 +01:00
size_t getStepSize(size_t n);
2017-12-24 18:14:07 +01:00
template <class Exprs>
2021-05-06 19:04:26 +02:00
auto ifor(size_t step, Exprs exs) const;
template <class Exprs>
2021-05-06 19:04:26 +02:00
auto iforh(size_t step, Exprs exs) const;
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
// Iterator Stuff
2021-05-28 17:29:13 +02:00
ConstContainerIndex& setData(const T* data);
const T& operator*() const;
const T* operator->() const;
2018-09-08 18:46:04 +02:00
//T& operator*();
//T* operator->();
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;
2021-05-28 17:29:13 +02:00
int operator-(const ConstContainerIndex& it) const;
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;
2017-08-04 16:19:50 +02:00
};
} // end namespace MultiArrayTools
#endif