2018-10-30 15:06:29 +01:00
|
|
|
|
2021-07-28 19:55:37 +02:00
|
|
|
#include "cxz_array_base.h"
|
2018-10-30 15:06:29 +01:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
/**********************
|
2021-07-28 20:59:31 +02:00
|
|
|
* ArrayBase *
|
2018-10-30 15:06:29 +01:00
|
|
|
**********************/
|
|
|
|
|
2018-12-24 18:55:11 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::ArrayBase(const ArrayBase& in) :
|
2018-12-24 18:55:11 +01:00
|
|
|
mInit(in.mInit),
|
|
|
|
mRange(in.mRange)
|
|
|
|
{
|
2018-12-25 18:57:51 +01:00
|
|
|
if(mRange){
|
|
|
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
|
|
|
}
|
2018-12-24 18:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::ArrayBase(ArrayBase&& in) :
|
2018-12-24 18:55:11 +01:00
|
|
|
mInit(in.mInit),
|
|
|
|
mRange(in.mRange)
|
|
|
|
{
|
2018-12-25 18:57:51 +01:00
|
|
|
if(mRange){
|
|
|
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
|
|
|
}
|
2018-12-24 18:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>& ArrayBase<T,SRanges...>::operator=(const ArrayBase& in)
|
2018-12-24 18:55:11 +01:00
|
|
|
{
|
|
|
|
mInit = in.mInit;
|
|
|
|
mRange = in.mRange;
|
2018-12-25 18:57:51 +01:00
|
|
|
if(mRange){
|
|
|
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
|
|
|
}
|
2018-12-24 18:55:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>& ArrayBase<T,SRanges...>::operator=(ArrayBase&& in)
|
2018-12-24 18:55:11 +01:00
|
|
|
{
|
|
|
|
mInit = in.mInit;
|
|
|
|
mRange = in.mRange;
|
2018-12-25 18:57:51 +01:00
|
|
|
if(mRange){
|
|
|
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
|
|
|
}
|
2018-12-24 18:55:11 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::ArrayBase(const std::shared_ptr<SRanges>&... ranges)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-05-28 19:48:27 +02:00
|
|
|
ContainerRangeFactory<SRanges...> crf(ranges...);
|
|
|
|
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
2018-10-30 15:06:29 +01:00
|
|
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::ArrayBase(const typename CRange::Space& space)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-05-28 19:48:27 +02:00
|
|
|
ContainerRangeFactory<SRanges...> crf(space);
|
|
|
|
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
2018-10-30 15:06:29 +01:00
|
|
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
template <typename X>
|
2021-07-28 20:59:31 +02:00
|
|
|
const T& ArrayBase<T,SRanges...>::operator[](const ConstContainerIndex<X,typename SRanges::IndexType...>& i)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
IndexType ii(*mProtoI);
|
|
|
|
ii = i;
|
|
|
|
return (*this)[ii];
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:37:32 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
const T& ArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const
|
2018-11-29 19:37:32 +01:00
|
|
|
{
|
|
|
|
IndexType ii(*mProtoI);
|
|
|
|
ii(is);
|
|
|
|
return (*this)[ii];
|
|
|
|
}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
size_t ArrayBase<T,SRanges...>::size() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mRange->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::begin() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-05-29 00:03:48 +02:00
|
|
|
return cbegin();
|
2018-10-30 15:06:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::end() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-05-29 00:03:48 +02:00
|
|
|
return end();
|
2018-10-30 15:06:29 +01:00
|
|
|
}
|
2021-05-29 00:03:48 +02:00
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::cbegin() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-05-29 00:03:48 +02:00
|
|
|
CIndexType i(*mProtoI,true);
|
2018-10-30 15:06:29 +01:00
|
|
|
i = 0;
|
|
|
|
return i.setData(data());
|
|
|
|
}
|
2021-05-29 00:03:48 +02:00
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::cend() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-05-29 00:03:48 +02:00
|
|
|
CIndexType i(*mProtoI,true);
|
2018-10-30 15:06:29 +01:00
|
|
|
i = i.max();
|
|
|
|
return i.setData(data());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
const std::shared_ptr<typename ArrayBase<T,SRanges...>::CRange>&
|
|
|
|
ArrayBase<T,SRanges...>::range() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
bool ArrayBase<T,SRanges...>::isConst() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
ConstOperationRoot<T,SRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
ConstOperationRoot<T,SRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::op(const std::shared_ptr<CIndexType>& ind) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return ConstOperationRoot<T,SRanges...>(data(), *ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
template <class... MappedRanges>
|
|
|
|
ConstOperationRoot<T,MappedRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
|
|
|
"number of mapped ranges must be equal to number of original ranges");
|
|
|
|
return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
bool ArrayBase<T,SRanges...>::isInit() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return mInit;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
template <size_t N>
|
2021-07-28 20:59:31 +02:00
|
|
|
auto ArrayBase<T,SRanges...>::getRangePtr() const
|
2018-10-30 15:06:29 +01:00
|
|
|
-> decltype(mRange->template getPtr<N>())
|
|
|
|
{
|
|
|
|
return mRange->template getPtr<N>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************
|
2021-07-28 20:59:31 +02:00
|
|
|
* MutableArrayBase *
|
2018-10-30 15:06:29 +01:00
|
|
|
******************************/
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::MutableArrayBase(const std::shared_ptr<SRanges>&... ranges) :
|
|
|
|
ArrayBase<T,SRanges...>(ranges...) {}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::MutableArrayBase(const typename CRange::Space& space) :
|
|
|
|
ArrayBase<T,SRanges...>(space) {}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
template <typename X>
|
2021-07-28 20:59:31 +02:00
|
|
|
T& MutableArrayBase<T,SRanges...>::operator[](const ConstContainerIndex<X,typename SRanges::IndexType...>& i)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
IndexType ii(*MAB::mProtoI);
|
|
|
|
ii = i;
|
|
|
|
return (*this)[ii];
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:37:32 +01:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
T& MutableArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is)
|
2018-11-29 19:37:32 +01:00
|
|
|
{
|
2021-05-29 00:03:48 +02:00
|
|
|
IndexType ii(*MAB::mProtoI,this->data());
|
2018-11-29 19:37:32 +01:00
|
|
|
ii(is);
|
|
|
|
return (*this)[ii];
|
|
|
|
}
|
|
|
|
|
2021-05-29 00:03:48 +02:00
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
typename MutableArrayBase<T,SRanges...>::IndexType MutableArrayBase<T,SRanges...>::begin()
|
2021-05-29 00:03:48 +02:00
|
|
|
{
|
|
|
|
IndexType i(*MAB::mProtoI,this->data(),true);
|
|
|
|
i = 0;
|
|
|
|
return i.setData(data());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
typename MutableArrayBase<T,SRanges...>::IndexType MutableArrayBase<T,SRanges...>::end()
|
2021-05-29 00:03:48 +02:00
|
|
|
{
|
|
|
|
IndexType i(*MAB::mProtoI,this->data(),true);
|
|
|
|
i = i.max();
|
|
|
|
return i.setData(data());
|
|
|
|
}
|
|
|
|
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
bool MutableArrayBase<T,SRanges...>::isConst() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
OperationRoot<T,SRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return OperationRoot<T,SRanges...>(*this, inds...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
OperationRoot<T,SRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::op(const std::shared_ptr<CIndexType>& ind)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return OperationRoot<T,SRanges...>(data(), *ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
ConstOperationRoot<T,SRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
ConstOperationRoot<T,SRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::op(const std::shared_ptr<CIndexType>& ind) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return ConstOperationRoot<T,SRanges...>(data(), *ind);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
template <class... MappedRanges>
|
|
|
|
OperationRoot<T,MappedRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds)
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
|
|
|
"number of mapped ranges must be equal to number of original ranges");
|
|
|
|
return OperationRoot<T,MappedRanges...>(*this, inds...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class... SRanges>
|
|
|
|
template <class... MappedRanges>
|
|
|
|
ConstOperationRoot<T,MappedRanges...>
|
2021-07-28 20:59:31 +02:00
|
|
|
MutableArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
|
|
|
"number of mapped ranges must be equal to number of original ranges");
|
|
|
|
return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
|
|
|
|
}
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // end namespace CNORXZ
|
2018-10-30 15:06:29 +01:00
|
|
|
|