cnorxz/orig/include/cxz_array.h

152 lines
4.3 KiB
C
Raw Normal View History

2017-02-16 11:20:40 +01:00
// -*- C++ -*-
2021-07-28 19:55:37 +02:00
#ifndef __cxz_array_h__
#define __cxz_array_h__
2017-02-16 11:20:40 +01:00
#include <algorithm>
2021-07-28 19:55:37 +02:00
#include "cxz_array_base.h"
#include "ranges/anonymous_range.h"
2017-02-16 11:20:40 +01:00
2021-07-28 20:29:56 +02:00
namespace CNORXZ
2017-02-16 11:20:40 +01:00
{
template <typename T>
struct ArrayCatter;
template <typename T>
struct ArrayCatter
{
template <class... Ranges>
static auto cat(const Array<T,Ranges...>& ma)
-> Array<T,Ranges...>
{
return ma;
}
};
2017-02-26 18:14:58 +01:00
template <typename T, class... SRanges>
class Array : public MutableArrayBase<T,SRanges...>
2017-02-16 11:20:40 +01:00
{
public:
typedef ContainerRange<SRanges...> CRange;
typedef ArrayBase<T,SRanges...> MAB;
2021-05-28 17:29:13 +02:00
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IndexType;
using ArrayBase<T,SRanges...>::operator[];
using MutableArrayBase<T,SRanges...>::operator[];
2018-12-23 19:33:01 +01:00
DEFAULT_MEMBERS(Array);
Array(const std::shared_ptr<SRanges>&... ranges);
Array(const std::shared_ptr<SRanges>&... ranges, const T& val);
Array(const std::shared_ptr<SRanges>&... ranges, const vector<T>& vec);
Array(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec);
2019-11-14 19:39:03 +01:00
template <class... Ranges>
Array(const std::shared_ptr<SRanges>&... ranges, Array<T,Ranges...>&& in); // same effect as format
2019-11-14 19:39:03 +01:00
Array(const typename CRange::Space& space);
Array(const typename CRange::Space& space, const vector<T>& vec);
Array(Array<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes);
// Only if ALL ranges have default extensions:
//Array(const vector<T>& vec);
//Array(vector<T>&& vec);
// template <class Range2, class Range3>
// Array(const Array<Array<T,Range2>,Range3> in);
2017-03-08 20:10:11 +01:00
// implement contstructor using FunctionalArray as Input !!!
//template <class Range2, class Range3>
//Array& operator=(const Array<Array<T,Range2>,Range3> in);
2017-02-16 11:20:40 +01:00
virtual T& operator[](const IndexType& i) final;
virtual const T& operator[](const IndexType& i) const final;
virtual T& at(const typename IndexType::MetaType& meta) override;
virtual const T& at(const typename IndexType::MetaType& meta) const override;
2017-08-09 16:58:38 +02:00
virtual bool isConst() const override;
2017-02-26 18:14:58 +01:00
virtual bool isSlice() const override;
2017-03-07 23:14:57 +01:00
template <class... SRanges2>
Array<T,SRanges2...> format(const std::shared_ptr<SRanges2>&... nrs); // reformat array using 'nr' which in
2017-08-09 11:29:41 +02:00
// total must have the same size as mRange
template <class... SRanges2>
Array<T,SRanges2...> format(const std::tuple<std::shared_ptr<SRanges2>...>& nrs);
template <class... SRanges2>
Slice<T,SRanges2...> slformat(const std::shared_ptr<SRanges2>&... nrs);
template <class... SRanges2>
ConstSlice<T,SRanges2...> slformat(const std::shared_ptr<SRanges2>&... nrs) const;
2017-09-09 19:59:09 +02:00
virtual const T* data() const override;
virtual T* data() override;
2019-02-13 21:59:13 +01:00
virtual vector<T>& vdata() { return mCont; }
virtual const vector<T>& vdata() const { return mCont; }
2019-03-14 19:10:06 +01:00
vector<T>&& vmove() { MAB::mInit = false; return std::move(mCont); }
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
//virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymousMove() override;
auto cat() const
-> decltype(ArrayCatter<T>::cat(*this));
2018-04-29 17:41:28 +02:00
operator T() const;
Array& operator=(const T& in);
2018-09-22 20:19:08 +02:00
Array& operator+=(const Array& in);
Array& operator-=(const Array& in);
Array& operator*=(const T& in);
Array& operator/=(const T& in);
2017-03-07 23:14:57 +01:00
template <typename U, class... SRanges2>
friend class Array;
2017-02-16 11:20:40 +01:00
private:
2019-02-13 21:59:13 +01:00
vector<T> mCont;
2017-02-16 11:20:40 +01:00
};
2018-04-29 17:41:28 +02:00
template <typename T>
using Scalar = Array<T,NullRange>;
template <typename T>
Scalar<T> scalar(const T& in);
template <typename T, class... ERanges>
struct ArrayCatter<Array<T,ERanges...> >
{
template <class... Ranges>
static auto cat(const Array<Array<T,ERanges...>,Ranges...>& ma)
-> Array<T,Ranges...,ERanges...>
{
auto sma = *ma.begin();
const size_t smas = sma.size();
const size_t mas = ma.size();
auto cr = ma.range()->cat(sma.range());
2019-02-13 21:59:13 +01:00
vector<T> ov;
ov.reserve(mas * smas);
for(auto& x: ma){
assert(x.size() == smas);
ov.insert(ov.end(), x.vdata().begin(), x.vdata().end());
}
return Array<T,Ranges...,ERanges...>(cr->space(), std::move(ov));
}
};
2017-02-16 11:20:40 +01:00
}
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
2017-02-16 11:20:40 +01:00
#endif