cnorxz/orig/include/slice.h

199 lines
5.5 KiB
C
Raw Normal View History

#ifndef __cxz_slice_h__
#define __cxz_slice_h__
2021-07-28 19:55:37 +02:00
#include "cxz_array_base.h"
#include "cxz_operation.h"
2021-07-28 20:29:56 +02:00
namespace CNORXZ
{
template <typename T, class... SRanges>
class ConstSlice : public ArrayBase<T,SRanges...>
{
public:
typedef ContainerRange<SRanges...> CRange;
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
using ArrayBase<T,SRanges...>::operator();
using ArrayBase<T,SRanges...>::operator[];
DEFAULT_MEMBERS(ConstSlice);
ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
const T* data = nullptr);
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
ConstSlice(const ArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes);
2019-05-17 15:10:33 +02:00
virtual const T& operator[](const IType& i) const final;
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;
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
2018-09-13 13:28:40 +02:00
-> ConstSliceDef<T,SRanges...>;
private:
2018-09-13 13:28:40 +02:00
friend ConstSliceDef<T,SRanges...>;
void format(const std::array<size_t,sizeof...(SRanges)+1>& blocks);
const T* mData;
};
template <typename T, class... SRanges>
class Slice : public MutableArrayBase<T,SRanges...>
{
public:
typedef ContainerRange<SRanges...> CRange;
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
using ArrayBase<T,SRanges...>::operator();
using MutableArrayBase<T,SRanges...>::operator();
using ArrayBase<T,SRanges...>::operator[];
using MutableArrayBase<T,SRanges...>::operator[];
DEFAULT_MEMBERS(Slice);
2019-02-13 21:59:13 +01:00
Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
T* data = nullptr);
Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr);
2019-05-17 15:10:33 +02:00
Slice& operator=(T val);
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;
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
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
//virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymousMove() override;
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
-> SliceDef<T,SRanges...>;
private:
friend SliceDef<T,SRanges...>;
void format(const std::array<size_t,sizeof...(SRanges)+1>& blocks);
T* mData;
};
2018-03-05 21:52:12 +01:00
template <typename T, class... SRanges>
class SliceDef
{
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-05 21:52:12 +01:00
private:
IType mIndex;
2018-09-13 13:28:40 +02:00
Slice<T,SRanges...>& mSl;
2018-03-05 21:52:12 +01:00
SliceDef() = default;
2018-03-05 21:52:12 +01:00
public:
2018-03-05 21:52:12 +01:00
SliceDef(Slice<T,SRanges...>& sl,
const std::shared_ptr<typename SRanges::IndexType>&... inds);
template <class... ORanges>
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
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
#endif