final at [] + assignment between Container Indices of different data type

This commit is contained in:
Christian Zimmermann 2018-10-06 13:14:24 +02:00
parent ca01dcaa10
commit be016abf3a
4 changed files with 51 additions and 6 deletions

View file

@ -56,8 +56,8 @@ namespace MultiArrayTools
//template <class Range2, class Range3> //template <class Range2, class Range3>
//MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in); //MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
virtual T& operator[](const IndexType& i) override; virtual T& operator[](const IndexType& i) final;
virtual const T& operator[](const IndexType& i) const override; virtual const T& operator[](const IndexType& i) const final;
virtual T& at(const typename IndexType::MetaType& meta) override; virtual T& at(const typename IndexType::MetaType& meta) override;
virtual const T& at(const typename IndexType::MetaType& meta) const override; virtual const T& at(const typename IndexType::MetaType& meta) const override;

View file

@ -39,6 +39,9 @@ namespace MultiArrayTools
virtual ~MultiArrayBase() = default; virtual ~MultiArrayBase() = default;
template <typename X>
const T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
virtual const T& operator[](const IndexType& i) const = 0; virtual const T& operator[](const IndexType& i) const = 0;
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0; virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0;
@ -96,6 +99,9 @@ namespace MultiArrayTools
MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges); MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
MutableMultiArrayBase(const typename CRange::Space& space); MutableMultiArrayBase(const typename CRange::Space& space);
template <typename X>
T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
virtual T& operator[](const IndexType& i) = 0; virtual T& operator[](const IndexType& i) = 0;
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0; virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
@ -159,6 +165,16 @@ namespace MultiArrayTools
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) ); mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
} }
template <typename T, class... SRanges>
template <typename X>
const T& MultiArrayBase<T,SRanges...>::operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i)
{
IndexType ii(*mProtoI);
ii = i;
return (*this)[ii];
}
template <typename T, class... SRanges> template <typename T, class... SRanges>
size_t MultiArrayBase<T,SRanges...>::size() const size_t MultiArrayBase<T,SRanges...>::size() const
{ {
@ -279,6 +295,17 @@ namespace MultiArrayTools
return i.setData(data()); return i.setData(data());
} }
*/ */
template <typename T, class... SRanges>
template <typename X>
T& MutableMultiArrayBase<T,SRanges...>::operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i)
{
IndexType ii(*MAB::mProtoI);
ii = i;
return (*this)[ii];
}
template <typename T, class... SRanges> template <typename T, class... SRanges>
bool MutableMultiArrayBase<T,SRanges...>::isConst() const bool MutableMultiArrayBase<T,SRanges...>::isConst() const
{ {

View file

@ -34,6 +34,12 @@ namespace MultiArrayTools
static constexpr SpaceType STYPE = SpaceType::ANY; static constexpr SpaceType STYPE = SpaceType::ANY;
template <typename X>
using CIX = ContainerIndex<X,Indices...>;
template <typename X>
friend class CIX;
private: private:
ContainerIndex() = default; ContainerIndex() = default;
@ -51,6 +57,9 @@ namespace MultiArrayTools
ContainerIndex(const ContainerIndex& in) = default; ContainerIndex(const ContainerIndex& in) = default;
ContainerIndex& operator=(const ContainerIndex& in) = default; ContainerIndex& operator=(const ContainerIndex& in) = default;
template <typename X>
ContainerIndex& operator=(const ContainerIndex<X,Indices...>& in);
template <class MRange> template <class MRange>
ContainerIndex(const std::shared_ptr<MRange>& range, ContainerIndex(const std::shared_ptr<MRange>& range,
std::intptr_t objPtrNum); std::intptr_t objPtrNum);
@ -252,6 +261,15 @@ namespace MultiArrayTools
mNonTrivialBlocks = true; mNonTrivialBlocks = true;
} }
template <typename T, class... Indices>
template <typename X>
ContainerIndex<T,Indices...>&
ContainerIndex<T,Indices...>::operator=(const ContainerIndex<X,Indices...>& in)
{
mIPack = in.mIPack;
return (*this)();
}
template <typename T, class... Indices> template <typename T, class... Indices>
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::sync() ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::sync()

View file

@ -23,7 +23,7 @@ namespace MultiArrayTools
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr); ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes); ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes);
virtual const T& operator[](const IType& i) const override; virtual const T& operator[](const IType& i) const final;
virtual const T& at(const typename IType::MetaType& meta) const override; virtual const T& at(const typename IType::MetaType& meta) const override;
virtual const T* data() const override; virtual const T* data() const override;
@ -63,8 +63,8 @@ namespace MultiArrayTools
Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr); Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr);
virtual const T& operator[](const IType& i) const override; virtual const T& operator[](const IType& i) const final;
virtual T& operator[](const IType& i) override; virtual T& operator[](const IType& i) final;
virtual const T& at(const typename IType::MetaType& meta) const override; virtual const T& at(const typename IType::MetaType& meta) const override;
virtual T& at(const typename IType::MetaType& meta) override; virtual T& at(const typename IType::MetaType& meta) override;