fixing compile errors... not finished

This commit is contained in:
Christian Zimmermann 2017-08-04 11:27:47 +02:00
parent e8ad0f1b03
commit 225ecc0abc
11 changed files with 151 additions and 123 deletions

View file

@ -49,10 +49,10 @@ namespace MultiArrayTools
enum class RangeType; enum class RangeType;
// range_base.h // range_base.h
class RangeBase; class RangeFactoryBase;
// range_base.h // range_base.h
class RangeFactoryBase; class RangeBase;
// range_base.h // range_base.h
template <class Index> template <class Index>
@ -74,7 +74,7 @@ namespace MultiArrayTools
class SingleRangeFactory; class SingleRangeFactory;
// single_range.h // single_range.h
template <typename U> template <typename U, RangeType TYPE>
class SingleIndex; class SingleIndex;
// multi_range.h // multi_range.h

View file

@ -21,7 +21,8 @@ namespace MultiArrayTools
} }
template <class... Ranges> template <class... Ranges>
ContainerRangeFactory<Ranges...>::ContainerRangeFactory(const ContainerRange<Ranges...>::SpaceType& space) ContainerRangeFactory<Ranges...>::
ContainerRangeFactory(const typename ContainerRange<Ranges...>::SpaceType& space)
{ {
mProd = std::make_shared<ContainerRange<Ranges...> >( space ); mProd = std::make_shared<ContainerRange<Ranges...> >( space );
} }
@ -57,18 +58,18 @@ namespace MultiArrayTools
} }
template <class... Ranges> template <class... Ranges>
typename IndexType ContainerRange<Ranges...>::begin() const typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
{ {
ContainerIndex<typename Ranges::IndexType...> ContainerIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( mThis ) ); i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
return i = 0; return i = 0;
} }
template <class... Ranges> template <class... Ranges>
typename IndexType ContainerRange<Ranges...>::end() const typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::end() const
{ {
ContainerIndex<typename Ranges::IndexType...> ContainerIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( mThis ) ); i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
return i = size(); return i = size();
} }
@ -76,7 +77,7 @@ namespace MultiArrayTools
std::shared_ptr<IndexBase> ContainerRange<Ranges...>::index() const std::shared_ptr<IndexBase> ContainerRange<Ranges...>::index() const
{ {
return std::make_shared<ContainerIndex<typename Ranges::IndexType...> > return std::make_shared<ContainerIndex<typename Ranges::IndexType...> >
( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( mThis ) ); ( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
} }
@ -89,7 +90,7 @@ namespace MultiArrayTools
IndexInterface<std::tuple<decltype(Indices().meta())...> >(in) IndexInterface<std::tuple<decltype(Indices().meta())...> >(in)
{ {
PackNum<sizeof...(Indices)-1>::copy(mIPack, in); PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
} }
template <class... Indices> template <class... Indices>
@ -97,7 +98,7 @@ namespace MultiArrayTools
{ {
IndexI::operator=(in); IndexI::operator=(in);
PackNum<sizeof...(Indices)-1>::copy(mIPack, in); PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this; return *this;
} }
@ -106,14 +107,14 @@ namespace MultiArrayTools
ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range) ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range)
{ {
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range); PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
} }
template <class... Indices> template <class... Indices>
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator++() ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator++()
{ {
PackNum<sizeof...(Indices)-1>::pp( mIPack ); PackNum<sizeof...(Indices)-1>::pp( mIPack );
++mPos; ++IB::mPos;
return *this; return *this;
} }
@ -121,7 +122,7 @@ namespace MultiArrayTools
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator--() ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator--()
{ {
PackNum<sizeof...(Indices)-1>::mm( mIPack ); PackNum<sizeof...(Indices)-1>::mm( mIPack );
--mPos; --IB::mPos;
return *this; return *this;
} }
@ -129,7 +130,7 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator=(size_t pos) ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator=(size_t pos)
{ {
mPos = pos; IB::mPos = pos;
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos); PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this; return *this;
} }
@ -159,9 +160,9 @@ namespace MultiArrayTools
size_t ContainerIndex<Indices...>::pos() const size_t ContainerIndex<Indices...>::pos() const
{ {
if(mExternControl){ if(mExternControl){
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
} }
return mPos; return IB::mPos;
} }
template <class... Indices> template <class... Indices>

View file

@ -23,7 +23,7 @@ namespace MultiArrayTools
ContainerRangeFactory() = delete; ContainerRangeFactory() = delete;
ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs); ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs);
ContainerRangeFactory(const ContainerRange<Ranges...>::SpaceType& space); ContainerRangeFactory(const typename ContainerRange<Ranges...>::SpaceType& space);
virtual std::shared_ptr<RangeBase> create() override; virtual std::shared_ptr<RangeBase> create() override;
@ -36,16 +36,17 @@ namespace MultiArrayTools
{ {
public: public:
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType; typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
typedef typename RangeInterface<ContainerIndex<typename Ranges::IndexType...> >::IndexType IndexType; typedef typename RangeInterface<ContainerIndex<typename Ranges::IndexType...> >::IndexType IndexType;
static const size_t dim = sizeof...(Ranges); static const size_t sdim = sizeof...(Ranges);
virtual size_t dim() const override; virtual size_t dim() const override;
virtual size_t size() const override; virtual size_t size() const override;
virtual typename IndexType begin() const override; virtual IndexType begin() const override;
virtual typename IndexType end() const override; virtual IndexType end() const override;
virtual std::shared_ptr<IndexBase> index() const override; virtual std::shared_ptr<IndexBase> index() const override;
@ -67,8 +68,10 @@ namespace MultiArrayTools
{ {
public: public:
typedef IndexBase IB;
typedef std::tuple<decltype(Indices().meta())...> MetaType; typedef std::tuple<decltype(Indices().meta())...> MetaType;
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack; typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef IndexInterface<std::tuple<decltype(Indices().meta())...> > IndexI;
ContainerIndex() = default; ContainerIndex() = default;

View file

@ -31,7 +31,7 @@ namespace MultiArrayTools
return mRangePtr->size(); return mRangePtr->size();
} }
operator IndexBase::size_t() const IndexBase::operator size_t() const
{ {
return pos(); return pos();
} }
@ -41,7 +41,7 @@ namespace MultiArrayTools
**********************/ **********************/
template <typename MetaType> template <typename MetaType>
IndexInterface::IndexInterface(const RangeBase& range, size_t pos) : IndexInterface<MetaType>::IndexInterface(const RangeBase& range, size_t pos) :
IndexBase(range, pos) {} IndexBase(range, pos) {}
} }

View file

@ -19,7 +19,7 @@ namespace MultiArrayTools
IndexInterface<std::tuple<decltype(Indices().meta())...> >(in) IndexInterface<std::tuple<decltype(Indices().meta())...> >(in)
{ {
PackNum<sizeof...(Indices)-1>::copy(mIPack, in); PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
} }
template <class... Indices> template <class... Indices>
@ -27,7 +27,7 @@ namespace MultiArrayTools
{ {
IndexI::operator=(in); IndexI::operator=(in);
PackNum<sizeof...(Indices)-1>::copy(mIPack, in); PackNum<sizeof...(Indices)-1>::copy(mIPack, in);
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this; return *this;
} }
@ -37,14 +37,14 @@ namespace MultiArrayTools
IndexInterface<std::tuple<decltype(Indices().meta())...> >(range, 0) IndexInterface<std::tuple<decltype(Indices().meta())...> >(range, 0)
{ {
PackNum<sizeof...(Indices)-1>::construct(mIPack, *range); PackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
} }
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++() MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
{ {
PackNum<sizeof...(Indices)-1>::pp( mIPack ); PackNum<sizeof...(Indices)-1>::pp( mIPack );
++mPos; ++IB::mPos;
return *this; return *this;
} }
@ -52,14 +52,14 @@ namespace MultiArrayTools
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--() MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
{ {
PackNum<sizeof...(Indices)-1>::mm( mIPack ); PackNum<sizeof...(Indices)-1>::mm( mIPack );
--mPos; --IB::mPos;
return *this; return *this;
} }
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos) MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
{ {
mPos = pos; IB::mPos = pos;
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos); PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
return *this; return *this;
} }
@ -69,7 +69,7 @@ namespace MultiArrayTools
MultiIndex<Indices...>& MultiIndex<Indices...>::up() MultiIndex<Indices...>& MultiIndex<Indices...>::up()
{ {
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices"); static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
mPos += PackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack ); IB::mPos += PackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
PackNum<DIR>::pp( mIPack ); PackNum<DIR>::pp( mIPack );
return *this; return *this;
} }
@ -79,7 +79,7 @@ namespace MultiArrayTools
MultiIndex<Indices...>& MultiIndex<Indices...>::down() MultiIndex<Indices...>& MultiIndex<Indices...>::down()
{ {
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices"); static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
mPos -= PackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack ); IB::mPos -= PackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
PackNum<DIR>::mm( mIPack ); PackNum<DIR>::mm( mIPack );
return *this; return *this;
} }
@ -92,7 +92,7 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
template <size_t N> template <size_t N>
auto MultiIndex<Indices...>::get() const -> const decltype(*std::get<N>(mIPack))& auto MultiIndex<Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
{ {
return *std::get<N>(mIPack); return *std::get<N>(mIPack);
} }
@ -105,7 +105,7 @@ namespace MultiArrayTools
// throw !! // throw !!
} }
MultiIndex<Indices...> const* t = this; MultiIndex<Indices...> const* t = this;
return IndexGetter<sizeof...(Indices)-1>::getIndex(*t, n); return PackNum<sizeof...(Indices)-1>::getIndex(*t, n);
} }
template <class... Indices> template <class... Indices>
@ -134,7 +134,7 @@ namespace MultiArrayTools
} }
template <class... Ranges> template <class... Ranges>
MultiRangeFactory<Ranges...>::MultiRangeFactory(const MultiRange<Ranges...>::SpaceType& st) MultiRangeFactory<Ranges...>::MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& st)
{ {
mProd = std::make_shared< MultiRange<Ranges...> >( st ); mProd = std::make_shared< MultiRange<Ranges...> >( st );
} }
@ -154,11 +154,11 @@ namespace MultiArrayTools
MultiRange<Ranges...>::MultiRange(const std::shared_ptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {} MultiRange<Ranges...>::MultiRange(const std::shared_ptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {}
template <class... Ranges> template <class... Ranges>
MultiRange<Ranges...>::MultiRange(const SpaceType& space) : mSpace(space) {} MultiRange<Ranges...>::MultiRange(const SpaceType& space) : mSpace( space ) {}
template <class... Ranges> template <class... Ranges>
template <size_t N> template <size_t N>
auto getRange() const -> const decltype(*std::get<N>(mSpace))& auto MultiRange<Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
//typename std::tuple_element<N, std::tuple<Ranges...> >::type const& MultiRange<Ranges...>::getRange() const //typename std::tuple_element<N, std::tuple<Ranges...> >::type const& MultiRange<Ranges...>::getRange() const
{ {
return *std::get<N>(mSpace); return *std::get<N>(mSpace);
@ -177,16 +177,18 @@ namespace MultiArrayTools
} }
template <class... Ranges> template <class... Ranges>
MultiIndex<typename Ranges::IndexType...> MultiRange<Ranges...>::begin() const typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::begin() const
{ {
MultiIndex<typename Ranges::IndexType...> i( std::dynamic_pointer_cast<MultiRange<Ranges...> >( mThis ) ); MultiIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
return i = 0; return i = 0;
} }
template <class... Ranges> template <class... Ranges>
MultiIndex<typename Ranges::IndexType...> MultiRange<Ranges...>::end() const typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::end() const
{ {
MultiIndex<typename Ranges::IndexType...> i( std::dynamic_pointer_cast<MultiRange<Ranges...> >( mThis ) ); MultiIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
return i = size(); return i = size();
} }
@ -194,6 +196,6 @@ namespace MultiArrayTools
std::shared_ptr<IndexBase> MultiRange<Ranges...>::index() const std::shared_ptr<IndexBase> MultiRange<Ranges...>::index() const
{ {
return std::make_shared<MultiIndex<typename Ranges::IndexType...> > return std::make_shared<MultiIndex<typename Ranges::IndexType...> >
( std::dynamic_pointer_cast<MultiRange<Ranges...> >( mThis ) ); ( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
} }
} }

View file

@ -19,12 +19,15 @@ namespace MultiArrayTools
{ {
public: public:
typedef IndexBase IB;
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack; typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef std::tuple<decltype(Indices().meta())...> MetaType; typedef std::tuple<decltype(Indices().meta())...> MetaType;
typedef IndexInterface<MetaType> IndexI; typedef IndexInterface<MetaType> IndexI;
public: protected:
IndexPack mIPack;
public:
MultiIndex() = default; MultiIndex() = default;
// NO DEFAULT HERE !!! // NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly ) // ( have to assign sub-indices (ptr!) correctly )
@ -45,7 +48,7 @@ namespace MultiArrayTools
MultiIndex& down(); MultiIndex& down();
template <size_t N> template <size_t N>
auto get() const -> decltype(*std::get<N>(mIPack))&; auto get() const -> decltype( *std::get<N>( mIPack ) )&;
const IndexBase& get(size_t n) const; const IndexBase& get(size_t n) const;
@ -53,11 +56,6 @@ namespace MultiArrayTools
virtual MultiIndex& at(const MetaType& metaPos) override; virtual MultiIndex& at(const MetaType& metaPos) override;
virtual size_t dim() const override; virtual size_t dim() const override;
protected:
IndexPack mIPack;
}; };
/************************* /*************************
@ -72,7 +70,7 @@ namespace MultiArrayTools
MultiRangeFactory() = delete; MultiRangeFactory() = delete;
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs); MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
MultiRangeFactory(const MultiRange<Ranges...>::SpaceType& space); MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& space);
virtual std::shared_ptr<RangeBase> create() override; virtual std::shared_ptr<RangeBase> create() override;
}; };
@ -85,30 +83,11 @@ namespace MultiArrayTools
class MultiRange : public RangeInterface<MultiIndex<typename Ranges::IndexType...> > class MultiRange : public RangeInterface<MultiIndex<typename Ranges::IndexType...> >
{ {
public: public:
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType; typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType; typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
static const size_t dim = sizeof...(Ranges);
template <size_t N> // !!!
auto get() const ->;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Ranges>...> >::type const& getRange() const;
virtual size_t dim() const override;
virtual size_t size() const override;
const SpaceType& space() const;
virtual typename IndexType begin() const override;
virtual typename IndexType end() const override;
virtual std::shared_ptr<IndexBase> index() const override;
friend MultiRangeFactory<Ranges...>;
protected: protected:
MultiRange() = delete; MultiRange() = delete;
MultiRange(const MultiRange& in) = delete; MultiRange(const MultiRange& in) = delete;
MultiRange& operator=(const MultiRange& in) = delete; MultiRange& operator=(const MultiRange& in) = delete;
@ -117,6 +96,27 @@ namespace MultiArrayTools
MultiRange(const SpaceType& space); MultiRange(const SpaceType& space);
SpaceType mSpace; SpaceType mSpace;
public:
static const size_t sdim = sizeof...(Ranges);
template <size_t N>
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Ranges>...> >::type const& getRange() const;
virtual size_t dim() const override;
virtual size_t size() const override;
const SpaceType& space() const;
virtual IndexType begin() const override;
virtual IndexType end() const override;
virtual std::shared_ptr<IndexBase> index() const override;
friend MultiRangeFactory<Ranges...>;
}; };
} }

View file

@ -1,12 +1,18 @@
// -*- C++ -*- // -*- C++ -*-
#ifndef __pack_num_h__
#define __pack_num_h__
#include <cstdlib> #include <cstdlib>
#include <type_traits> #include <type_traits>
#include <tuple> #include <tuple>
#include <memory> #include <memory>
#include "base_def.h"
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
using namespace MultiArrayTools;
template <size_t N> template <size_t N>
struct PackNum struct PackNum
@ -65,7 +71,7 @@ namespace MultiArrayHelper
return std::get<N>(rt).size() * PackNum<N-1>::getSize(rt); return std::get<N>(rt).size() * PackNum<N-1>::getSize(rt);
} }
template <template <class...> IndexType, class... Indices> template <template <class...> class IndexType, class... Indices>
static void getMetaPos(std::tuple<decltype(Indices().meta())...>& target, static void getMetaPos(std::tuple<decltype(Indices().meta())...>& target,
const typename IndexType<Indices...>::IndexPack& source) const typename IndexType<Indices...>::IndexPack& source)
{ {
@ -73,7 +79,7 @@ namespace MultiArrayHelper
PackNum<N-1>::getMetaPos(target, source); PackNum<N-1>::getMetaPos(target, source);
} }
template <class IndexPack> template <class IndexPack, typename MetaType>
static void setMeta(IndexPack& target, const MetaType& source) static void setMeta(IndexPack& target, const MetaType& source)
{ {
std::get<N>(target).atMeta( std::get<N>(source) ); std::get<N>(target).atMeta( std::get<N>(source) );
@ -105,7 +111,7 @@ namespace MultiArrayHelper
PackNum<N-1>::construct(ip, range); PackNum<N-1>::construct(ip, range);
} }
template <template<class...> IndexType, class... Indices> template <template<class...> class IndexType, class... Indices>
static void copy(std::tuple<std::shared_ptr<Indices>...>& ip, static void copy(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType<Indices...>& ind) const IndexType<Indices...>& ind)
{ {
@ -141,13 +147,13 @@ namespace MultiArrayHelper
struct PackNum<0> struct PackNum<0>
{ {
template <class MultiIndex> template <class MultiIndex>
static IndefinitIndexBase& getIndex(MultiIndex& in, size_t n) static IndexBase& getIndex(MultiIndex& in, size_t n)
{ {
return in.getIndex<0>(); return in.getIndex<0>();
} }
template <class MultiIndex> template <class MultiIndex>
static const IndefinitIndexBase& getIndex(const MultiIndex& in, size_t n) static const IndexBase& getIndex(const MultiIndex& in, size_t n)
{ {
return in.getIndex<0>(); return in.getIndex<0>();
} }
@ -172,17 +178,17 @@ namespace MultiArrayHelper
return std::get<0>(rt).size(); return std::get<0>(rt).size();
} }
template <template <class...> IndexType, class... Indices> template <template <class...> class IndexType, class... Indices>
static void getMetaPos(std::tuple<decltype(Indices().meta())...>& target, static void getMetaPos(std::tuple<decltype(Indices().meta())...>& target,
const typename IndexType<Indices...>::IndexPack& source) const typename IndexType<Indices...>::IndexPack& source)
{ {
std::get<0>(target) = std::get<0>(source)->meta(); std::get<0>(target) = std::get<0>(source)->meta();
} }
template <class IndexPack> template <class IndexPack, typename MetaType>
static void setMeta(IndexPack& target, const MetaType& source) static void setMeta(IndexPack& target, const MetaType& source)
{ {
std::get<0>(target).atMeta( std::get<0>(source) ); std::get<0>(target).atMeta( std::get<0>( source ) );
} }
template <class IndexPack> template <class IndexPack>
@ -206,7 +212,7 @@ namespace MultiArrayHelper
std::get<0>(ip).swap( std::make_shared<SubIndexType>( range.template get<0>() ) ); std::get<0>(ip).swap( std::make_shared<SubIndexType>( range.template get<0>() ) );
} }
template <template<class...> IndexType, class... Indices> template <template<class...> class IndexType, class... Indices>
static void copy(std::tuple<std::shared_ptr<Indices>...>& ip, static void copy(std::tuple<std::shared_ptr<Indices>...>& ip,
const IndexType<Indices...>& ind) const IndexType<Indices...>& ind)
{ {
@ -235,3 +241,5 @@ namespace MultiArrayHelper
}; };
} // end namespace MultiArrayHelper } // end namespace MultiArrayHelper
#endif

View file

@ -3,6 +3,16 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
/*************************
* RangeFactoryBase *
*************************/
void RangeFactoryBase::setSelf()
{
mProd->mThis = mProd;
}
/****************** /******************
* RangeBase * * RangeBase *
******************/ ******************/

View file

@ -37,9 +37,10 @@ namespace MultiArrayTools
protected: protected:
// call this function before returning product !!
void setSelf() { mProd->mThis = mProd; }
std::shared_ptr<RangeBase> mProd; std::shared_ptr<RangeBase> mProd;
// call this function before returning product !!
void setSelf();
}; };
class RangeBase class RangeBase

View file

@ -7,61 +7,60 @@ namespace MultiArrayTools
* SingleIndex * * SingleIndex *
******************/ ******************/
template <typename U> template <typename U, RangeType TYPE>
template<RangeType TYPE> SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
SingleIndex<U>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
IndexInterface<U>(range, 0) {} IndexInterface<U>(range, 0) {}
template <typename U> template <typename U, RangeType TYPE>
SingleIndex<U>& SingleIndex<U>::operator=(size_t pos) SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
{ {
mPos = pos; IB::mPos = pos;
return *this; return *this;
} }
template <typename U> template <typename U, RangeType TYPE>
SingleIndex<U>& SingleIndex<U>::operator++() SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
{ {
++mPos; ++IB::mPos;
return *this; return *this;
} }
template <typename U> template <typename U, RangeType TYPE>
SingleIndex<U>& SingleIndex<U>::operator--() SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
{ {
--mPos; --IB::mPos;
return *this; return *this;
} }
template <typename U> template <typename U, RangeType TYPE>
U SingleIndex<U>::meta() const U SingleIndex<U,TYPE>::meta() const
{ {
return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->get(IIB::pos()); return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRangePtr )->get( IB::pos() );
} }
template <typename U> template <typename U, RangeType TYPE>
SingleIndex<U>& SingleIndex<U>::at(const U& metaPos) SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
{ {
operator=( dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->getMeta(metaPos) ); operator=( dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRangePtr )->getMeta( metaPos ) );
return *this; return *this;
} }
template <typename U> template <typename U, RangeType TYPE>
size_t SingleIndex<U>::dim() const size_t SingleIndex<U,TYPE>::dim() const
{ {
return 1; return 1;
} }
template <typename U> template <typename U, RangeType TYPE>
bool SingleIndex<U>::last() const bool SingleIndex<U,TYPE>::last() const
{ {
return mPos == mRangePtr->size() - 1; return IB::mPos == IB::mRangePtr->size() - 1;
} }
template <typename U> template <typename U, RangeType TYPE>
bool SingleIndex<U>::first() const bool SingleIndex<U,TYPE>::first() const
{ {
return mPos == 0; return IB::mPos == 0;
} }
/******************** /********************
@ -86,7 +85,7 @@ namespace MultiArrayTools
********************/ ********************/
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) : RangeBase<SingleIndex<U> >(), SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) : RangeInterface<SingleIndex<U,TYPE> >(),
mSpace(space) {} mSpace(space) {}
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
@ -121,16 +120,16 @@ namespace MultiArrayTools
} }
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
SingleIndex<U> SingleRange<U,TYPE>::begin() const SingleIndex<U,TYPE> SingleRange<U,TYPE>::begin() const
{ {
SingleIndex<U> i(mThis); SingleIndex<U,TYPE> i( RB::mThis );
return i = 0; return i = 0;
} }
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
SingleIndex<U> SingleRange<U,TYPE>::end() const SingleIndex<U,TYPE> SingleRange<U,TYPE>::end() const
{ {
SingleIndex<U> i(mThis); SingleIndex<U,TYPE> i( RB::mThis );
return i = size(); return i = size();
} }
@ -138,8 +137,8 @@ namespace MultiArrayTools
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const
{ {
return std::make_shared<SingleIndex<U> > return std::make_shared<SingleIndex<U,TYPE> >
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( mThis ) ); ( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
} }
/* /*

View file

@ -14,13 +14,15 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
template <typename U> template <typename U, RangeType TYPE>
class SingleIndex : public IndexInterface<U> class SingleIndex : public IndexInterface<U>
{ {
public: public:
typedef IndexBase IB;
DEFAULT_MEMBERS(SingleIndex); DEFAULT_MEMBERS(SingleIndex);
template <RangeType TYPE>
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range); SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
virtual SingleIndex& operator=(size_t pos) override; virtual SingleIndex& operator=(size_t pos) override;
@ -49,18 +51,20 @@ namespace MultiArrayTools
}; };
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
class SingleRange : public RangeInterface<SingleIndex<U> > class SingleRange : public RangeInterface<SingleIndex<U,TYPE> >
{ {
public: public:
typedef typename RangeBase<SingleIndex<U> >::IndexType IndexType; typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
virtual size_t size() const override; virtual size_t size() const override;
virtual size_t dim() const override;
const U& get(size_t pos) const; const U& get(size_t pos) const;
size_t getMeta(const U& metaPos) const; size_t getMeta(const U& metaPos) const;
virtual SingleIndex<U> begin() const override; virtual SingleIndex<U,TYPE> begin() const override;
virtual SingleIndex<U> end() const override; virtual SingleIndex<U,TYPE> end() const override;
virtual std::shared_ptr<IndexBase> index() const override; virtual std::shared_ptr<IndexBase> index() const override;
friend SingleRangeFactory<U,TYPE>; friend SingleRangeFactory<U,TYPE>;