2017-07-27 14:48:41 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __container_range_h__
|
|
|
|
#define __container_range_h__
|
|
|
|
|
|
|
|
#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"
|
2017-07-27 14:48:41 +02:00
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
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...>,
|
2018-02-15 20:06:14 +01:00
|
|
|
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...>,
|
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-12-25 17:48:52 +01:00
|
|
|
size_t mCPos;
|
2018-08-20 17:50:04 +02:00
|
|
|
//const MultiArrayBase<T,typename Indices::RangeType...>* mMa = nullptr;
|
2018-03-05 00:04:50 +01:00
|
|
|
std::intptr_t mObjPtrNum;
|
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 17:29:13 +02:00
|
|
|
ConstContainerIndex(const ConstContainerIndex& in, bool copy) :
|
2018-12-25 17:48:52 +01:00
|
|
|
IB(in),
|
|
|
|
mNonTrivialBlocks(in.mNonTrivialBlocks),
|
|
|
|
mExternControl(false),
|
|
|
|
mBlockSizes(in.mBlockSizes),
|
|
|
|
mData(in.mData),
|
|
|
|
mCPos(in.mCPos),
|
|
|
|
mObjPtrNum(in.mObjPtrNum)
|
|
|
|
{
|
2021-05-12 17:56:35 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i)
|
|
|
|
{
|
|
|
|
typedef typename std::remove_reference<decltype(*std::get<i>(mIPack))>::type
|
|
|
|
SubType;
|
|
|
|
std::get<i>(mIPack) = std::make_shared<SubType>( in.template get<i>() ) ;
|
|
|
|
return true;
|
|
|
|
});
|
2018-12-25 17:48:52 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex& copy(const ConstContainerIndex& in)
|
2018-12-25 17:48:52 +01:00
|
|
|
{
|
|
|
|
IB::operator=(in);
|
|
|
|
mNonTrivialBlocks = in.mNonTrivialBlocks;
|
|
|
|
mExternControl = false;
|
|
|
|
mBlockSizes = in.mBlockSizes;
|
|
|
|
mData = in.mData;
|
|
|
|
mCPos = in.mCPos;
|
|
|
|
mObjPtrNum = in.mObjPtrNum;
|
2021-05-12 17:56:35 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i)
|
|
|
|
{
|
|
|
|
typedef typename std::remove_reference<decltype(*std::get<i>(mIPack))>::type
|
|
|
|
SubType;
|
|
|
|
std::get<i>(mIPack) = std::make_shared<SubType>( in.template get<i>() ) ;
|
|
|
|
return true;
|
|
|
|
});
|
2018-12-25 17:48:52 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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-11 18:49:43 +01:00
|
|
|
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
|
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>
|
2017-12-17 14:16:37 +01:00
|
|
|
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
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
|
|
|
|
2017-07-27 14:48:41 +02:00
|
|
|
} // end namespace MultiArrayTools
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace MultiArrayHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
2021-05-28 17:29:13 +02:00
|
|
|
* ConstContainerIndex *
|
2017-11-20 21:35:25 +01:00
|
|
|
**********************/
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2017-11-20 21:35:25 +01:00
|
|
|
template <class MRange>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>::ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
2018-03-05 00:04:50 +01:00
|
|
|
std::intptr_t objPtrNum) :
|
2021-05-28 17:29:13 +02:00
|
|
|
IndexInterface<ConstContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
2018-03-05 00:04:50 +01:00
|
|
|
mObjPtrNum(objPtrNum)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_mn<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto r = range->template getPtr<i>();
|
|
|
|
std::get<i>(mIPack) = r->beginPtr();
|
|
|
|
*std::get<i>(mIPack) = 0;
|
|
|
|
|
|
|
|
std::get<i>(mBlockSizes) = sfor_p<i,sizeof...(Indices)>
|
|
|
|
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
|
|
|
[&](auto a, auto b) { return a * b; });
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2021-05-27 23:29:04 +02:00
|
|
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
template <typename T, class... Indices>
|
|
|
|
template <class MRange>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>::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) :
|
2021-05-28 17:29:13 +02:00
|
|
|
IndexInterface<ConstContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
2018-03-05 00:04:50 +01:00
|
|
|
mObjPtrNum(objPtrNum)
|
2018-02-16 18:17:22 +01:00
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_mn<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto r = range->template getPtr<i>();
|
|
|
|
std::get<i>(mIPack) = r->beginPtr();
|
|
|
|
*std::get<i>(mIPack) = 0;
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2021-05-27 23:29:04 +02:00
|
|
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2018-02-16 18:17:22 +01:00
|
|
|
mNonTrivialBlocks = true;
|
|
|
|
}
|
2018-10-06 13:14:24 +02:00
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
|
|
|
template <typename X>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>&
|
|
|
|
ConstContainerIndex<T,Indices...>::operator=(const ConstContainerIndex<X,Indices...>& in)
|
2018-10-06 13:14:24 +02:00
|
|
|
{
|
|
|
|
mIPack = in.mIPack;
|
|
|
|
return (*this)();
|
|
|
|
}
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::sync()
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
if(mExternControl){
|
2021-05-07 17:35:59 +02:00
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2021-05-27 23:29:04 +02:00
|
|
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2017-11-20 21:35:25 +01:00
|
|
|
template <size_t N>
|
2021-05-28 17:29:13 +02:00
|
|
|
auto ConstContainerIndex<T,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return *std::get<N>( mIPack );
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2017-12-12 11:15:39 +01:00
|
|
|
template <size_t N>
|
2021-05-28 17:29:13 +02:00
|
|
|
auto ConstContainerIndex<T,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
2017-12-12 11:15:39 +01:00
|
|
|
{
|
|
|
|
return std::get<N>( mIPack );
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
return (*this)(std::make_tuple(inds...));
|
2017-11-20 21:35:25 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
|
2018-11-29 19:37:32 +01:00
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(inds); return 0; } );
|
2018-11-29 19:37:32 +01:00
|
|
|
mExternControl = true;
|
|
|
|
return sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator()()
|
2017-11-20 21:35:25 +01:00
|
|
|
{
|
|
|
|
return sync();
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
IndexType ConstContainerIndex<T,Indices...>::type() const { return IndexType::CONT; }
|
2017-12-17 14:16:37 +01:00
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator++()
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
if(mExternControl){
|
2021-05-07 17:35:59 +02:00
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2017-12-17 14:16:37 +01:00
|
|
|
}
|
2021-05-06 19:04:26 +02:00
|
|
|
sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto& si = *std::get<i>( mIPack );
|
|
|
|
if(si.last() and i != 0) { si = 0; return true; }
|
|
|
|
else { ++si; return false; }
|
|
|
|
return false;
|
|
|
|
} );
|
2021-05-27 23:29:04 +02:00
|
|
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2017-12-17 14:16:37 +01:00
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator--()
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
if(mExternControl){
|
2021-05-07 17:35:59 +02:00
|
|
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) { return std::get<i>(mIPack); },
|
|
|
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
2017-12-17 14:16:37 +01:00
|
|
|
}
|
2021-05-06 19:04:26 +02:00
|
|
|
sfor_m<sizeof...(Indices),0>
|
|
|
|
( [&](auto i) {
|
|
|
|
auto& si = *std::get<i>( mIPack );
|
|
|
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
|
|
|
else { --si; return false; }
|
|
|
|
return false;
|
|
|
|
} );
|
2021-05-27 23:29:04 +02:00
|
|
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2017-12-17 14:16:37 +01:00
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator=(size_t pos)
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
2021-05-12 17:56:35 +02:00
|
|
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
|
2021-05-27 23:29:04 +02:00
|
|
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2017-12-17 14:16:37 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
int ConstContainerIndex<T,Indices...>::pp(std::intptr_t idxPtrNum)
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
2021-05-27 23:29:04 +02:00
|
|
|
const int tmp = RangeHelper::ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
2017-12-17 14:16:37 +01:00
|
|
|
IB::mPos += tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
int ConstContainerIndex<T,Indices...>::mm(std::intptr_t idxPtrNum)
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
2021-05-27 23:29:04 +02:00
|
|
|
const int tmp = RangeHelper::mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
2017-12-17 14:16:37 +01:00
|
|
|
IB::mPos -= tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2018-07-22 16:16:24 +02:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
std::string ConstContainerIndex<T,Indices...>::stringMeta() const
|
2018-07-22 16:16:24 +02:00
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
typename ConstContainerIndex<T,Indices...>::MetaType ConstContainerIndex<T,Indices...>::meta() const
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
MetaType metaTuple;
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { std::get<i>(metaTuple) = std::get<i>(mIPack)->meta(); return 0; } );
|
2017-12-17 14:16:37 +01:00
|
|
|
return metaTuple;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::at(const MetaType& metaPos)
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
2021-05-07 17:35:59 +02:00
|
|
|
sfor_pn<0,sizeof...(Indices)>
|
|
|
|
( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); return 0; } );
|
2021-05-27 23:29:04 +02:00
|
|
|
IB::mPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
2017-12-17 14:16:37 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
size_t ConstContainerIndex<T,Indices...>::dim() const
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
return sizeof...(Indices);
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::first() const
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
return IB::pos() == 0;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::last() const
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
return IB::pos() == IB::mMax - 1;
|
|
|
|
}
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::sliceMode() const
|
2018-02-16 18:17:22 +01:00
|
|
|
{
|
|
|
|
return mNonTrivialBlocks;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
std::shared_ptr<typename ConstContainerIndex<T,Indices...>::RangeType>
|
|
|
|
ConstContainerIndex<T,Indices...>::range()
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2017-12-17 14:16:37 +01:00
|
|
|
template <size_t N>
|
2021-05-28 17:29:13 +02:00
|
|
|
auto ConstContainerIndex<T,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
return std::get<N>( mIPack );
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
size_t ConstContainerIndex<T,Indices...>::getStepSize(size_t n)
|
2017-12-17 14:16:37 +01:00
|
|
|
{
|
|
|
|
if(n >= sizeof...(Indices)){
|
|
|
|
assert(0);
|
|
|
|
// throw !!
|
|
|
|
}
|
|
|
|
return mBlockSizes[n+1];
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2018-01-13 18:07:52 +01:00
|
|
|
template <class Exprs>
|
2021-05-28 17:29:13 +02:00
|
|
|
auto ConstContainerIndex<T,Indices...>::ifor(size_t step, Exprs exs) const
|
2018-01-07 22:33:34 +01:00
|
|
|
{
|
2021-05-27 12:15:44 +02:00
|
|
|
return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs);
|
2018-01-07 22:33:34 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2018-01-15 14:56:22 +01:00
|
|
|
template <class Exprs>
|
2021-05-28 17:29:13 +02:00
|
|
|
auto ConstContainerIndex<T,Indices...>::iforh(size_t step, Exprs exs) const
|
2018-01-15 14:56:22 +01:00
|
|
|
{
|
2021-05-27 12:15:44 +02:00
|
|
|
return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs);
|
2018-01-15 14:56:22 +01:00
|
|
|
}
|
2018-03-05 00:04:50 +01:00
|
|
|
|
2019-01-15 17:41:43 +01:00
|
|
|
template <typename T, class... Indices>
|
|
|
|
template <class Exprs>
|
2021-05-28 17:29:13 +02:00
|
|
|
auto ConstContainerIndex<T,Indices...>::pifor(size_t step, Exprs exs) const
|
2019-01-15 17:41:43 +01:00
|
|
|
{
|
2021-05-27 12:15:44 +02:00
|
|
|
return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs);
|
2019-01-15 17:41:43 +01:00
|
|
|
}
|
|
|
|
|
2018-03-05 00:04:50 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
std::intptr_t ConstContainerIndex<T,Indices...>::container() const
|
2018-03-05 00:04:50 +01:00
|
|
|
{
|
|
|
|
return mObjPtrNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::
|
2018-03-05 00:04:50 +01:00
|
|
|
format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
|
|
|
{
|
|
|
|
mBlockSizes = blocks;
|
2019-03-22 19:07:29 +01:00
|
|
|
mNonTrivialBlocks = true;
|
2018-03-05 00:04:50 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2017-12-17 14:16:37 +01:00
|
|
|
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::setData(const T* data)
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
mData = data;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
const T& ConstContainerIndex<T,Indices...>::operator*() const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
2018-08-20 17:50:04 +02:00
|
|
|
//return mMa[*this];
|
2018-12-25 17:48:52 +01:00
|
|
|
return mData[mCPos];
|
|
|
|
//return mData[IB::mPos];
|
2018-02-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
const T* ConstContainerIndex<T,Indices...>::operator->() const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
2018-08-20 17:50:04 +02:00
|
|
|
//return &mMa[*this];
|
2018-12-25 17:48:52 +01:00
|
|
|
return &mData[mCPos];
|
2018-02-15 20:06:14 +01:00
|
|
|
}
|
2018-09-08 18:46:04 +02:00
|
|
|
/*
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
T& ConstContainerIndex<T,Indices...>::operator*()
|
2018-09-08 18:46:04 +02:00
|
|
|
{
|
|
|
|
//return mMa[*this];
|
|
|
|
return mData[IB::mPos];
|
|
|
|
}
|
2018-02-15 20:06:14 +01:00
|
|
|
|
2018-09-08 18:46:04 +02:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
T* ConstContainerIndex<T,Indices...>::operator->()
|
2018-09-08 18:46:04 +02:00
|
|
|
{
|
|
|
|
//return &mMa[*this];
|
|
|
|
return &mData[IB::mPos];
|
|
|
|
}
|
|
|
|
*/
|
2018-02-15 20:06:14 +01:00
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator++(int)
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
auto tmp = *this;
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator--(int)
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
auto tmp = *this;
|
|
|
|
--(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator+=(int diff)
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
if(diff < 0){
|
|
|
|
for(int i = 0; i != diff; ++i){
|
|
|
|
(*this)--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(int i = 0; i != diff; ++i){
|
|
|
|
(*this)++;
|
|
|
|
}
|
|
|
|
}
|
2018-05-20 20:03:44 +02:00
|
|
|
return *this;
|
2018-02-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator-=(int diff)
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
if(diff < 0){
|
|
|
|
for(int i = 0; i != diff; ++i){
|
|
|
|
(*this)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(int i = 0; i != diff; ++i){
|
|
|
|
(*this)--;
|
|
|
|
}
|
|
|
|
}
|
2018-05-20 20:03:44 +02:00
|
|
|
return *this;
|
2018-02-15 20:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator+(int num) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
auto tmp = *this;
|
|
|
|
return tmp += num;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator-(int num) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
auto tmp = *this;
|
|
|
|
return tmp -= num;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
int ConstContainerIndex<T,Indices...>::operator-(const ConstContainerIndex<T,Indices...>& it) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
return static_cast<int>( IB::mPos ) - static_cast<int>( it.pos() );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
const T& ConstContainerIndex<T,Indices...>::operator[](int num) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
return mData[IB::mPos + num];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::operator<(const ConstContainerIndex<T,Indices...>& it) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
return IB::mPos < it.pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::operator>(const ConstContainerIndex<T,Indices...>& it) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
return IB::mPos > it.pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::operator<=(const ConstContainerIndex<T,Indices...>& it) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
return IB::mPos <= it.pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... Indices>
|
2021-05-28 17:29:13 +02:00
|
|
|
bool ConstContainerIndex<T,Indices...>::operator>=(const ConstContainerIndex<T,Indices...>& it) const
|
2018-02-15 20:06:14 +01:00
|
|
|
{
|
|
|
|
return IB::mPos >= it.pos();
|
|
|
|
}
|
|
|
|
|
2017-11-20 21:35:25 +01:00
|
|
|
} // end namespace MultiArrayTools
|
|
|
|
|
2017-07-27 14:48:41 +02:00
|
|
|
|
|
|
|
#endif
|