fixing compile errors... not finished
This commit is contained in:
parent
e8ad0f1b03
commit
225ecc0abc
11 changed files with 151 additions and 123 deletions
|
@ -49,10 +49,10 @@ namespace MultiArrayTools
|
|||
enum class RangeType;
|
||||
|
||||
// range_base.h
|
||||
class RangeBase;
|
||||
class RangeFactoryBase;
|
||||
|
||||
// range_base.h
|
||||
class RangeFactoryBase;
|
||||
class RangeBase;
|
||||
|
||||
// range_base.h
|
||||
template <class Index>
|
||||
|
@ -74,7 +74,7 @@ namespace MultiArrayTools
|
|||
class SingleRangeFactory;
|
||||
|
||||
// single_range.h
|
||||
template <typename U>
|
||||
template <typename U, RangeType TYPE>
|
||||
class SingleIndex;
|
||||
|
||||
// multi_range.h
|
||||
|
|
|
@ -21,7 +21,8 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
@ -57,18 +58,18 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename IndexType ContainerRange<Ranges...>::begin() const
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
|
||||
{
|
||||
ContainerIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( mThis ) );
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
|
||||
return i = 0;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename IndexType ContainerRange<Ranges...>::end() const
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::end() const
|
||||
{
|
||||
ContainerIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( mThis ) );
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
|
||||
return i = size();
|
||||
}
|
||||
|
||||
|
@ -76,7 +77,7 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<IndexBase> ContainerRange<Ranges...>::index() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
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>
|
||||
|
@ -97,7 +98,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
IndexI::operator=(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;
|
||||
}
|
||||
|
||||
|
@ -106,14 +107,14 @@ namespace MultiArrayTools
|
|||
ContainerIndex<Indices...>::ContainerIndex(const std::shared_ptr<MRange>& 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>
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator++()
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++mPos;
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -121,7 +122,7 @@ namespace MultiArrayTools
|
|||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator--()
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--mPos;
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator=(size_t pos)
|
||||
{
|
||||
mPos = pos;
|
||||
IB::mPos = pos;
|
||||
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||
return *this;
|
||||
}
|
||||
|
@ -159,9 +160,9 @@ namespace MultiArrayTools
|
|||
size_t ContainerIndex<Indices...>::pos() const
|
||||
{
|
||||
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>
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace MultiArrayTools
|
|||
|
||||
ContainerRangeFactory() = delete;
|
||||
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;
|
||||
|
||||
|
@ -36,16 +36,17 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
typedef RangeBase RB;
|
||||
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
||||
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 size() const override;
|
||||
|
||||
virtual typename IndexType begin() const override;
|
||||
virtual typename IndexType end() const override;
|
||||
virtual IndexType begin() const override;
|
||||
virtual IndexType end() const override;
|
||||
|
||||
virtual std::shared_ptr<IndexBase> index() const override;
|
||||
|
||||
|
@ -67,8 +68,10 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
typedef IndexBase IB;
|
||||
typedef std::tuple<decltype(Indices().meta())...> MetaType;
|
||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||
typedef IndexInterface<std::tuple<decltype(Indices().meta())...> > IndexI;
|
||||
|
||||
ContainerIndex() = default;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace MultiArrayTools
|
|||
return mRangePtr->size();
|
||||
}
|
||||
|
||||
operator IndexBase::size_t() const
|
||||
IndexBase::operator size_t() const
|
||||
{
|
||||
return pos();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace MultiArrayTools
|
|||
**********************/
|
||||
|
||||
template <typename MetaType>
|
||||
IndexInterface::IndexInterface(const RangeBase& range, size_t pos) :
|
||||
IndexInterface<MetaType>::IndexInterface(const RangeBase& range, size_t pos) :
|
||||
IndexBase(range, pos) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace MultiArrayTools
|
|||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(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>
|
||||
|
@ -27,7 +27,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
IndexI::operator=(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;
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,14 @@ namespace MultiArrayTools
|
|||
IndexInterface<std::tuple<decltype(Indices().meta())...> >(range, 0)
|
||||
{
|
||||
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>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++mPos;
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -52,14 +52,14 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--mPos;
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
|
||||
{
|
||||
mPos = pos;
|
||||
IB::mPos = pos;
|
||||
PackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||
return *this;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
||||
{
|
||||
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 );
|
||||
return *this;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
||||
{
|
||||
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 );
|
||||
return *this;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <class... Indices>
|
||||
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);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace MultiArrayTools
|
|||
// throw !!
|
||||
}
|
||||
MultiIndex<Indices...> const* t = this;
|
||||
return IndexGetter<sizeof...(Indices)-1>::getIndex(*t, n);
|
||||
return PackNum<sizeof...(Indices)-1>::getIndex(*t, n);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
|
@ -134,7 +134,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <class... Ranges>
|
||||
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
|
||||
{
|
||||
return *std::get<N>(mSpace);
|
||||
|
@ -177,16 +177,18 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -194,6 +196,6 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<IndexBase> MultiRange<Ranges...>::index() const
|
||||
{
|
||||
return std::make_shared<MultiIndex<typename Ranges::IndexType...> >
|
||||
( std::dynamic_pointer_cast<MultiRange<Ranges...> >( mThis ) );
|
||||
( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,15 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
typedef IndexBase IB;
|
||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||
typedef std::tuple<decltype(Indices().meta())...> MetaType;
|
||||
typedef IndexInterface<MetaType> IndexI;
|
||||
|
||||
public:
|
||||
protected:
|
||||
IndexPack mIPack;
|
||||
|
||||
public:
|
||||
MultiIndex() = default;
|
||||
// NO DEFAULT HERE !!!
|
||||
// ( have to assign sub-indices (ptr!) correctly )
|
||||
|
@ -53,11 +56,6 @@ namespace MultiArrayTools
|
|||
virtual MultiIndex& at(const MetaType& metaPos) override;
|
||||
|
||||
virtual size_t dim() const override;
|
||||
|
||||
protected:
|
||||
|
||||
IndexPack mIPack;
|
||||
|
||||
};
|
||||
|
||||
/*************************
|
||||
|
@ -72,7 +70,7 @@ namespace MultiArrayTools
|
|||
|
||||
MultiRangeFactory() = delete;
|
||||
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;
|
||||
};
|
||||
|
@ -85,30 +83,11 @@ namespace MultiArrayTools
|
|||
class MultiRange : public RangeInterface<MultiIndex<typename Ranges::IndexType...> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef RangeBase RB;
|
||||
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
||||
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:
|
||||
|
||||
MultiRange() = delete;
|
||||
MultiRange(const MultiRange& in) = delete;
|
||||
MultiRange& operator=(const MultiRange& in) = delete;
|
||||
|
@ -117,6 +96,27 @@ namespace MultiArrayTools
|
|||
MultiRange(const SpaceType& space);
|
||||
|
||||
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...>;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __pack_num_h__
|
||||
#define __pack_num_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
|
||||
#include "base_def.h"
|
||||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
using namespace MultiArrayTools;
|
||||
|
||||
template <size_t N>
|
||||
struct PackNum
|
||||
|
@ -65,7 +71,7 @@ namespace MultiArrayHelper
|
|||
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,
|
||||
const typename IndexType<Indices...>::IndexPack& source)
|
||||
{
|
||||
|
@ -73,7 +79,7 @@ namespace MultiArrayHelper
|
|||
PackNum<N-1>::getMetaPos(target, source);
|
||||
}
|
||||
|
||||
template <class IndexPack>
|
||||
template <class IndexPack, typename MetaType>
|
||||
static void setMeta(IndexPack& target, const MetaType& source)
|
||||
{
|
||||
std::get<N>(target).atMeta( std::get<N>(source) );
|
||||
|
@ -105,7 +111,7 @@ namespace MultiArrayHelper
|
|||
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,
|
||||
const IndexType<Indices...>& ind)
|
||||
{
|
||||
|
@ -141,13 +147,13 @@ namespace MultiArrayHelper
|
|||
struct PackNum<0>
|
||||
{
|
||||
template <class MultiIndex>
|
||||
static IndefinitIndexBase& getIndex(MultiIndex& in, size_t n)
|
||||
static IndexBase& getIndex(MultiIndex& in, size_t n)
|
||||
{
|
||||
return in.getIndex<0>();
|
||||
}
|
||||
|
||||
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>();
|
||||
}
|
||||
|
@ -172,14 +178,14 @@ namespace MultiArrayHelper
|
|||
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,
|
||||
const typename IndexType<Indices...>::IndexPack& source)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::get<0>(target).atMeta( std::get<0>( source ) );
|
||||
|
@ -206,7 +212,7 @@ namespace MultiArrayHelper
|
|||
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,
|
||||
const IndexType<Indices...>& ind)
|
||||
{
|
||||
|
@ -235,3 +241,5 @@ namespace MultiArrayHelper
|
|||
};
|
||||
|
||||
} // end namespace MultiArrayHelper
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,16 @@
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
/*************************
|
||||
* RangeFactoryBase *
|
||||
*************************/
|
||||
|
||||
void RangeFactoryBase::setSelf()
|
||||
{
|
||||
mProd->mThis = mProd;
|
||||
}
|
||||
|
||||
/******************
|
||||
* RangeBase *
|
||||
******************/
|
||||
|
|
|
@ -37,9 +37,10 @@ namespace MultiArrayTools
|
|||
|
||||
protected:
|
||||
|
||||
// call this function before returning product !!
|
||||
void setSelf() { mProd->mThis = mProd; }
|
||||
std::shared_ptr<RangeBase> mProd;
|
||||
|
||||
// call this function before returning product !!
|
||||
void setSelf();
|
||||
};
|
||||
|
||||
class RangeBase
|
||||
|
|
|
@ -7,61 +7,60 @@ namespace MultiArrayTools
|
|||
* SingleIndex *
|
||||
******************/
|
||||
|
||||
template <typename U>
|
||||
template<RangeType TYPE>
|
||||
SingleIndex<U>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
|
||||
IndexInterface<U>(range, 0) {}
|
||||
|
||||
template <typename U>
|
||||
SingleIndex<U>& SingleIndex<U>::operator=(size_t pos)
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
|
||||
{
|
||||
mPos = pos;
|
||||
IB::mPos = pos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
SingleIndex<U>& SingleIndex<U>::operator++()
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
|
||||
{
|
||||
++mPos;
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
SingleIndex<U>& SingleIndex<U>::operator--()
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
|
||||
{
|
||||
--mPos;
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
U SingleIndex<U>::meta() const
|
||||
template <typename U, RangeType TYPE>
|
||||
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>
|
||||
SingleIndex<U>& SingleIndex<U>::at(const U& metaPos)
|
||||
template <typename U, RangeType TYPE>
|
||||
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;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
size_t SingleIndex<U>::dim() const
|
||||
template <typename U, RangeType TYPE>
|
||||
size_t SingleIndex<U,TYPE>::dim() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
bool SingleIndex<U>::last() const
|
||||
template <typename U, RangeType TYPE>
|
||||
bool SingleIndex<U,TYPE>::last() const
|
||||
{
|
||||
return mPos == mRangePtr->size() - 1;
|
||||
return IB::mPos == IB::mRangePtr->size() - 1;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
bool SingleIndex<U>::first() const
|
||||
template <typename U, RangeType TYPE>
|
||||
bool SingleIndex<U,TYPE>::first() const
|
||||
{
|
||||
return mPos == 0;
|
||||
return IB::mPos == 0;
|
||||
}
|
||||
|
||||
/********************
|
||||
|
@ -86,7 +85,7 @@ namespace MultiArrayTools
|
|||
********************/
|
||||
|
||||
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) {}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
|
@ -121,16 +120,16 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -138,8 +137,8 @@ namespace MultiArrayTools
|
|||
template <typename U, RangeType TYPE>
|
||||
std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const
|
||||
{
|
||||
return std::make_shared<SingleIndex<U> >
|
||||
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( mThis ) );
|
||||
return std::make_shared<SingleIndex<U,TYPE> >
|
||||
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -14,13 +14,15 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <typename U>
|
||||
template <typename U, RangeType TYPE>
|
||||
class SingleIndex : public IndexInterface<U>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef IndexBase IB;
|
||||
|
||||
DEFAULT_MEMBERS(SingleIndex);
|
||||
|
||||
template <RangeType TYPE>
|
||||
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
|
||||
|
||||
virtual SingleIndex& operator=(size_t pos) override;
|
||||
|
@ -49,18 +51,20 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
class SingleRange : public RangeInterface<SingleIndex<U> >
|
||||
class SingleRange : public RangeInterface<SingleIndex<U,TYPE> >
|
||||
{
|
||||
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 dim() const override;
|
||||
|
||||
const U& get(size_t pos) const;
|
||||
size_t getMeta(const U& metaPos) const;
|
||||
|
||||
virtual SingleIndex<U> begin() const override;
|
||||
virtual SingleIndex<U> end() const override;
|
||||
virtual SingleIndex<U,TYPE> begin() const override;
|
||||
virtual SingleIndex<U,TYPE> end() const override;
|
||||
virtual std::shared_ptr<IndexBase> index() const override;
|
||||
|
||||
friend SingleRangeFactory<U,TYPE>;
|
||||
|
|
Loading…
Reference in a new issue