2018-02-16 18:17:22 +01:00
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
#ifndef __cxz_slice_h__
|
|
|
|
#define __cxz_slice_h__
|
2018-02-16 18:17:22 +01:00
|
|
|
|
2021-07-28 19:55:37 +02:00
|
|
|
#include "cxz_array_base.h"
|
|
|
|
#include "cxz_operation.h"
|
2018-02-16 18:17:22 +01:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-02-16 18:17:22 +01:00
|
|
|
{
|
2018-03-22 11:13:00 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
class ConstSlice : public ArrayBase<T,SRanges...>
|
2018-03-22 11:13:00 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-05-28 19:48:27 +02:00
|
|
|
typedef ContainerRange<SRanges...> CRange;
|
2021-07-28 20:59:31 +02:00
|
|
|
typedef ArrayBase<T,SRanges...> MAB;
|
2021-05-28 17:29:13 +02:00
|
|
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
2018-09-16 18:53:28 +02:00
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
using ArrayBase<T,SRanges...>::operator();
|
|
|
|
using ArrayBase<T,SRanges...>::operator[];
|
2018-03-22 11:13:00 +01:00
|
|
|
|
|
|
|
DEFAULT_MEMBERS(ConstSlice);
|
|
|
|
|
2018-11-03 22:03:35 +01:00
|
|
|
ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
|
|
|
const T* data = nullptr);
|
2018-03-22 11:13:00 +01:00
|
|
|
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
|
2021-07-28 20:59:31 +02:00
|
|
|
ConstSlice(const ArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes);
|
2019-05-17 15:10:33 +02:00
|
|
|
|
2018-10-06 13:14:24 +02:00
|
|
|
virtual const T& operator[](const IType& i) const final;
|
2018-03-22 11:13:00 +01:00
|
|
|
virtual const T& at(const typename IType::MetaType& meta) const override;
|
|
|
|
|
|
|
|
virtual const T* data() const override;
|
|
|
|
|
|
|
|
virtual bool isSlice() const override;
|
|
|
|
|
|
|
|
virtual auto begin() const -> IType override;
|
|
|
|
virtual auto end() const -> IType override;
|
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
2018-07-16 18:52:02 +02:00
|
|
|
|
2018-03-22 11:13:00 +01:00
|
|
|
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
2018-09-13 13:28:40 +02:00
|
|
|
-> ConstSliceDef<T,SRanges...>;
|
2018-03-22 11:13:00 +01:00
|
|
|
|
|
|
|
private:
|
2018-09-13 13:28:40 +02:00
|
|
|
friend ConstSliceDef<T,SRanges...>;
|
2018-03-22 11:13:00 +01:00
|
|
|
|
|
|
|
void format(const std::array<size_t,sizeof...(SRanges)+1>& blocks);
|
|
|
|
|
|
|
|
const T* mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
class Slice : public MutableArrayBase<T,SRanges...>
|
2018-02-16 18:17:22 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-05-28 19:48:27 +02:00
|
|
|
typedef ContainerRange<SRanges...> CRange;
|
2021-07-28 20:59:31 +02:00
|
|
|
typedef ArrayBase<T,SRanges...> MAB;
|
2021-05-28 17:29:13 +02:00
|
|
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
2018-09-16 18:53:28 +02:00
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
using ArrayBase<T,SRanges...>::operator();
|
|
|
|
using MutableArrayBase<T,SRanges...>::operator();
|
|
|
|
using ArrayBase<T,SRanges...>::operator[];
|
|
|
|
using MutableArrayBase<T,SRanges...>::operator[];
|
2018-11-29 19:37:32 +01:00
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
DEFAULT_MEMBERS(Slice);
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
|
|
|
T* data = nullptr);
|
2018-03-06 13:58:17 +01:00
|
|
|
Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr);
|
2019-05-17 15:10:33 +02:00
|
|
|
|
|
|
|
Slice& operator=(T val);
|
|
|
|
|
2018-10-06 13:14:24 +02:00
|
|
|
virtual const T& operator[](const IType& i) const final;
|
|
|
|
virtual T& operator[](const IType& i) final;
|
2018-03-05 00:04:50 +01:00
|
|
|
virtual const T& at(const typename IType::MetaType& meta) const override;
|
|
|
|
virtual T& at(const typename IType::MetaType& meta) override;
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
virtual const T* data() const override;
|
|
|
|
virtual T* data() override;
|
|
|
|
|
|
|
|
virtual bool isSlice() const override;
|
|
|
|
|
2018-03-05 00:04:50 +01:00
|
|
|
virtual auto begin() const -> IType override;
|
|
|
|
virtual auto end() const -> IType override;
|
2018-03-05 18:46:29 +01:00
|
|
|
|
2021-07-28 20:59:31 +02:00
|
|
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
|
|
|
//virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymousMove() override;
|
2018-07-16 18:52:02 +02:00
|
|
|
|
2018-03-06 13:58:17 +01:00
|
|
|
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
|
|
|
-> SliceDef<T,SRanges...>;
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
private:
|
2018-03-06 13:58:17 +01:00
|
|
|
friend SliceDef<T,SRanges...>;
|
|
|
|
|
|
|
|
void format(const std::array<size_t,sizeof...(SRanges)+1>& blocks);
|
|
|
|
|
2018-02-16 18:17:22 +01:00
|
|
|
T* mData;
|
|
|
|
};
|
2018-03-05 21:52:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
class SliceDef
|
|
|
|
{
|
2018-03-06 13:58:17 +01:00
|
|
|
public:
|
2021-05-28 17:29:13 +02:00
|
|
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
2018-09-08 18:46:04 +02:00
|
|
|
|
|
|
|
template <class Op>
|
2018-09-13 13:28:40 +02:00
|
|
|
static Slice<T,SRanges...> mkSlice( const typename Slice<T,SRanges...>::IndexType& ind,
|
2021-05-04 18:26:17 +02:00
|
|
|
const Op& op )
|
2018-09-08 18:46:04 +02:00
|
|
|
{
|
2018-09-13 13:28:40 +02:00
|
|
|
Slice<T,SRanges...> out(ind->range()->space(), &*ind);
|
2018-09-08 18:46:04 +02:00
|
|
|
std::array<size_t,sizeof...(SRanges)+1> ff;
|
2021-06-08 16:41:28 +02:00
|
|
|
sfor_pn<0,sizeof...(SRanges)>
|
|
|
|
( [&](auto i) {
|
|
|
|
std::get<i+1>(ff) =
|
|
|
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
|
|
|
( ind.template getPtr<i>().get())).val();
|
|
|
|
return 0; } );
|
2018-09-08 18:46:04 +02:00
|
|
|
out.format(ff);
|
|
|
|
return out;
|
|
|
|
}
|
2018-03-06 13:58:17 +01:00
|
|
|
|
2018-03-05 21:52:12 +01:00
|
|
|
private:
|
2018-03-06 13:58:17 +01:00
|
|
|
IType mIndex;
|
2018-09-13 13:28:40 +02:00
|
|
|
Slice<T,SRanges...>& mSl;
|
2018-03-05 21:52:12 +01:00
|
|
|
|
2018-03-06 13:58:17 +01:00
|
|
|
SliceDef() = default;
|
2018-03-05 21:52:12 +01:00
|
|
|
public:
|
2018-03-22 11:13:00 +01:00
|
|
|
|
2018-03-05 21:52:12 +01:00
|
|
|
SliceDef(Slice<T,SRanges...>& sl,
|
|
|
|
const std::shared_ptr<typename SRanges::IndexType>&... inds);
|
|
|
|
|
|
|
|
template <class... ORanges>
|
2018-03-06 13:58:17 +01:00
|
|
|
SliceDef& operator=(const OperationRoot<T,ORanges...>& op);
|
2018-03-05 21:52:12 +01:00
|
|
|
};
|
2018-09-13 13:28:40 +02:00
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
class ConstSliceDef
|
|
|
|
{
|
|
|
|
public:
|
2021-05-28 17:29:13 +02:00
|
|
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
2018-09-13 13:28:40 +02:00
|
|
|
|
|
|
|
template <class Op>
|
|
|
|
static ConstSlice<T,SRanges...> mkSlice( const typename ConstSlice<T,SRanges...>::IndexType& ind,
|
|
|
|
const Op& op )
|
|
|
|
{
|
|
|
|
ConstSlice<T,SRanges...> out(ind->range()->space(), &*ind);
|
|
|
|
std::array<size_t,sizeof...(SRanges)+1> ff;
|
2021-06-08 16:41:28 +02:00
|
|
|
sfor_pn<0,sizeof...(SRanges)>
|
|
|
|
( [&](auto i) {
|
|
|
|
std::get<i+1>(ff) =
|
|
|
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
|
|
|
( ind.template getPtr<i>().get())).val();
|
|
|
|
return 0; } );
|
2018-09-13 13:28:40 +02:00
|
|
|
out.format(ff);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
IType mIndex;
|
|
|
|
ConstSlice<T,SRanges...>& mSl;
|
|
|
|
|
|
|
|
ConstSliceDef() = default;
|
|
|
|
public:
|
|
|
|
ConstSliceDef(ConstSlice<T,SRanges...>& csl,
|
|
|
|
const std::shared_ptr<typename SRanges::IndexType>&... inds);
|
|
|
|
|
|
|
|
template <class... ORanges>
|
|
|
|
ConstSliceDef& operator=(const ConstOperationRoot<T,ORanges...>& op);
|
|
|
|
|
|
|
|
template <class... ORanges>
|
|
|
|
ConstSliceDef& operator=(const OperationRoot<T,ORanges...>& op);
|
|
|
|
};
|
2018-09-08 18:46:04 +02:00
|
|
|
|
|
|
|
template <typename T, class Op, class... Ranges>
|
|
|
|
ConstSlice<T,Ranges...> mkSlice( const typename ConstSlice<T,Ranges...>::IndexType& ind,
|
|
|
|
const Op& op )
|
2018-09-13 13:28:40 +02:00
|
|
|
{
|
|
|
|
return ConstSliceDef<T,Ranges...>::mkSlice(ind, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Op, class... Ranges>
|
|
|
|
Slice<T,Ranges...> mkSlice( const typename Slice<T,Ranges...>::IndexType& ind,
|
|
|
|
const Op& op )
|
2018-09-08 18:46:04 +02:00
|
|
|
{
|
|
|
|
return SliceDef<T,Ranges...>::mkSlice(ind, op);
|
|
|
|
}
|
2018-09-13 13:28:40 +02:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // end namespace CNORXZ
|
2018-02-16 18:17:22 +01:00
|
|
|
|
|
|
|
/* ========================= *
|
|
|
|
* --- TEMPLATE CODE --- *
|
|
|
|
* ========================= */
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|