... compiles now
This commit is contained in:
parent
225ecc0abc
commit
d2a1286d17
9 changed files with 111 additions and 63 deletions
|
@ -41,7 +41,7 @@ namespace MultiArrayTools
|
|||
**********************/
|
||||
|
||||
template <typename MetaType>
|
||||
IndexInterface<MetaType>::IndexInterface(const RangeBase& range, size_t pos) :
|
||||
IndexBase(range, pos) {}
|
||||
IndexInterface<MetaType>::IndexInterface(const std::shared_ptr<RangeBase>& rangePtr, size_t pos) :
|
||||
IndexBase(rangePtr, pos) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,10 +48,11 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
IndexInterface(const RangeBase& range, size_t pos);
|
||||
DEFAULT_MEMBERS(IndexInterface);
|
||||
|
||||
MetaType& meta() = 0;
|
||||
const MetaType& meta() const = 0;
|
||||
IndexInterface(const std::shared_ptr<RangeBase>& rangePtr, size_t pos);
|
||||
virtual MetaType meta() const = 0;
|
||||
virtual IndexInterface& at(const MetaType& meta) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,21 @@ namespace {
|
|||
|
||||
using namespace MAT;
|
||||
|
||||
template <class Factory, typename T>
|
||||
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
|
||||
{
|
||||
std::vector<T> tmp = ilist;
|
||||
auto nptr = std::make_shared<Factory>( tmp );
|
||||
fptr = nptr;
|
||||
}
|
||||
|
||||
template <class Factory, class... Rs>
|
||||
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
|
||||
{
|
||||
auto nptr = std::make_shared<Factory>( rs... );
|
||||
fptr = nptr;
|
||||
}
|
||||
|
||||
class IndexTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -30,21 +45,21 @@ namespace {
|
|||
|
||||
IndexTest()
|
||||
{
|
||||
rfbptr.swap( std::make_shared<SRF>( { 'e', 'b', 'n' } ) );
|
||||
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
||||
swapFactory<SRF>(rfbptr, { 'e', 'b', 'n' } );
|
||||
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
rfbptr.swap( std::make_shared<SRF>( { 'x', 'y', 'l', 'f' } ) );
|
||||
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
||||
swapFactory<SRF>(rfbptr, { 'x', 'y', 'l', 'f' } );
|
||||
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
rfbptr.swap( std::make_shared<SRF>( { 'a', 'b' } ) );
|
||||
std::shared_ptr<SRange> temp1 = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
||||
rfbptr.swap( std::make_shared<SRF>( { '1' } ) );
|
||||
std::shared_ptr<SRange> temp2 = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
||||
rfbptr.swap( std::make_shared<SRF>( { '0', '7' } ) );
|
||||
std::shared_ptr<SRange> temp3 = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
||||
swapFactory<SRF>(rfbptr, { 'a', 'b' } );
|
||||
std::shared_ptr<SRange> temp1 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
swapFactory<SRF>(rfbptr, { '1' } );
|
||||
std::shared_ptr<SRange> temp2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
swapFactory<SRF>(rfbptr, { '0', '7' } );
|
||||
std::shared_ptr<SRange> temp3 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
rfbptr.swap( std::make_shared<M3RF>( temp1, temp2, temp3 ) );
|
||||
m3rptr = std::dynamic_pointer_cast<M3Range>( rfbptr.create() );
|
||||
swapMFactory<M3RF>(rfbptr, temp1, temp2, temp3 );
|
||||
m3rptr = std::dynamic_pointer_cast<M3Range>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
|
|
|
@ -10,9 +10,9 @@ namespace MultiArrayTools
|
|||
using namespace MultiArrayHelper;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MultiIndexBase *
|
||||
**********************/
|
||||
/******************
|
||||
* MultiIndex *
|
||||
******************/
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
|
||||
|
@ -123,6 +123,18 @@ namespace MultiArrayTools
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
bool MultiIndex<Indices...>::first() const
|
||||
{
|
||||
return IB::mPos == 0;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
bool MultiIndex<Indices...>::last() const
|
||||
{
|
||||
return IB::mPos == IB::mRangePtr->size() - 1;
|
||||
}
|
||||
|
||||
/*************************
|
||||
* MultiRangeFactory *
|
||||
*************************/
|
||||
|
@ -130,13 +142,13 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
MultiRangeFactory<Ranges...>::MultiRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
||||
{
|
||||
mProd = std::make_shared< MultiRange<Ranges...> >( rs... );
|
||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( rs... ) );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRangeFactory<Ranges...>::MultiRangeFactory(const typename MultiRange<Ranges...>::SpaceType& st)
|
||||
{
|
||||
mProd = std::make_shared< MultiRange<Ranges...> >( st );
|
||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
|
@ -159,11 +171,23 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
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);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
auto MultiRange<Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
||||
{
|
||||
return std::get<N>(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::dim() const
|
||||
{
|
||||
return sdim;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::size() const
|
||||
{
|
||||
|
|
|
@ -55,6 +55,9 @@ namespace MultiArrayTools
|
|||
virtual MetaType meta() const override;
|
||||
virtual MultiIndex& at(const MetaType& metaPos) override;
|
||||
|
||||
virtual bool first() const override;
|
||||
virtual bool last() const override;
|
||||
|
||||
virtual size_t dim() const override;
|
||||
};
|
||||
|
||||
|
@ -103,7 +106,9 @@ namespace MultiArrayTools
|
|||
|
||||
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;
|
||||
|
||||
template <size_t N>
|
||||
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
||||
|
||||
virtual size_t dim() const override;
|
||||
virtual size_t size() const override;
|
||||
|
|
|
@ -43,9 +43,9 @@ namespace MultiArrayHelper
|
|||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<N>(ip);
|
||||
if(si.pos() == si.last()){
|
||||
if(si.last()){
|
||||
si = 0;
|
||||
PackNum<N-1>::pp(index);
|
||||
PackNum<N-1>::pp(ip);
|
||||
}
|
||||
else {
|
||||
++si;
|
||||
|
@ -56,9 +56,9 @@ namespace MultiArrayHelper
|
|||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
||||
{
|
||||
auto& si = *std::get<N>(ip);
|
||||
if(si.pos() == si.atEdge()){
|
||||
if(si.first()){
|
||||
si = si.max();
|
||||
PackNum<N-1>::mm(index);
|
||||
PackNum<N-1>::mm(ip);
|
||||
}
|
||||
else {
|
||||
--si;
|
||||
|
@ -68,12 +68,12 @@ namespace MultiArrayHelper
|
|||
template <class RangeTuple>
|
||||
static size_t getSize(const RangeTuple& rt)
|
||||
{
|
||||
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...> class IndexType, class... Indices>
|
||||
static void getMetaPos(std::tuple<decltype(Indices().meta())...>& target,
|
||||
const typename IndexType<Indices...>::IndexPack& source)
|
||||
template <class IndexPack, class MetaType>
|
||||
static void getMetaPos(MetaType& target,
|
||||
const IndexPack& source)
|
||||
{
|
||||
std::get<N>(target) = std::get<N>(source)->meta();
|
||||
PackNum<N-1>::getMetaPos(target, source);
|
||||
|
@ -82,14 +82,14 @@ namespace MultiArrayHelper
|
|||
template <class IndexPack, typename MetaType>
|
||||
static void setMeta(IndexPack& target, const MetaType& source)
|
||||
{
|
||||
std::get<N>(target).atMeta( std::get<N>(source) );
|
||||
std::get<N>(target)->at( std::get<N>(source) );
|
||||
PackNum<N-1>::setMeta(target, source);
|
||||
}
|
||||
|
||||
template <class IndexPack>
|
||||
static void setIndexPack(IndexPack& iPack, size_t pos)
|
||||
{
|
||||
auto i = std::get<N>(iPack);
|
||||
auto i = *std::get<N>(iPack).get();
|
||||
const size_t ownPos = pos % i.max();
|
||||
i = ownPos;
|
||||
if(ownPos == pos){
|
||||
|
@ -101,13 +101,14 @@ namespace MultiArrayHelper
|
|||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const MRange& range)
|
||||
{
|
||||
typedef decltype(range.template get<N>()) SubIndexType;
|
||||
typedef decltype(std::get<N>(ip).get()) TypeFromIndexPack;
|
||||
typedef typename std::remove_reference<decltype(range.template get<N>())>::type SubRangeType;
|
||||
typedef typename SubRangeType::IndexType SubIndexType;
|
||||
typedef typename std::remove_reference<decltype(*std::get<N>(ip).get())>::type TypeFromIndexPack;
|
||||
|
||||
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
||||
"inconsiśtent types");
|
||||
|
||||
std::get<N>(ip).swap( std::make_shared<SubIndexType>( range.template get<N>() ) );
|
||||
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
|
||||
PackNum<N-1>::construct(ip, range);
|
||||
}
|
||||
|
||||
|
@ -115,8 +116,8 @@ namespace MultiArrayHelper
|
|||
static void copy(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const IndexType<Indices...>& ind)
|
||||
{
|
||||
typedef decltype(ind.template get<N>()) SubIndexType;
|
||||
std::get<N>(ip).swap( std::make_shared<SubIndexType>( ind.template get<N>() ) );
|
||||
typedef typename std::remove_reference<decltype(ind.template get<N>())>::type SubIndexType;
|
||||
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( ind.template get<N>() ) );
|
||||
PackNum<N-1>::copy(ip, ind);
|
||||
}
|
||||
|
||||
|
@ -175,12 +176,12 @@ namespace MultiArrayHelper
|
|||
template <class RangeTuple>
|
||||
static size_t getSize(const RangeTuple& rt)
|
||||
{
|
||||
return std::get<0>(rt).size();
|
||||
return std::get<0>(rt)->size();
|
||||
}
|
||||
|
||||
template <template <class...> class IndexType, class... Indices>
|
||||
static void getMetaPos(std::tuple<decltype(Indices().meta())...>& target,
|
||||
const typename IndexType<Indices...>::IndexPack& source)
|
||||
template <class IndexPack, class MetaType>
|
||||
static void getMetaPos(MetaType& target,
|
||||
const IndexPack& source)
|
||||
{
|
||||
std::get<0>(target) = std::get<0>(source)->meta();
|
||||
}
|
||||
|
@ -188,13 +189,13 @@ namespace MultiArrayHelper
|
|||
template <class IndexPack, typename MetaType>
|
||||
static void setMeta(IndexPack& target, const MetaType& source)
|
||||
{
|
||||
std::get<0>(target).atMeta( std::get<0>( source ) );
|
||||
std::get<0>(target)->at( std::get<0>( source ) );
|
||||
}
|
||||
|
||||
template <class IndexPack>
|
||||
static void setIndexPack(IndexPack& iPack, size_t pos)
|
||||
{
|
||||
auto i = std::get<0>(iPack);
|
||||
auto i = *std::get<0>(iPack);
|
||||
const size_t ownPos = pos % i.max();
|
||||
i = ownPos;
|
||||
}
|
||||
|
@ -203,21 +204,22 @@ namespace MultiArrayHelper
|
|||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const MRange& range)
|
||||
{
|
||||
typedef decltype(range.template get<0>()) SubIndexType;
|
||||
typedef decltype(std::get<0>(ip).get()) TypeFromIndexPack;
|
||||
typedef typename std::remove_reference<decltype(range.template get<0>())>::type SubRangeType;
|
||||
typedef typename SubRangeType::IndexType SubIndexType;
|
||||
typedef typename std::remove_reference<decltype(*std::get<0>(ip).get())>::type TypeFromIndexPack;
|
||||
|
||||
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
||||
"inconsiśtent types");
|
||||
|
||||
std::get<0>(ip).swap( std::make_shared<SubIndexType>( range.template get<0>() ) );
|
||||
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
|
||||
}
|
||||
|
||||
template <template<class...> class IndexType, class... Indices>
|
||||
static void copy(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||
const IndexType<Indices...>& ind)
|
||||
{
|
||||
typedef decltype(ind.template get<0>()) SubIndexType;
|
||||
std::get<0>(ip).swap( std::make_shared<SubIndexType>( ind.template get<0>() ) );
|
||||
typedef typename std::remove_reference<decltype(ind.template get<0>())>::type SubIndexType;
|
||||
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( ind.template get<0>() ) );
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
|
|
|
@ -72,8 +72,8 @@ namespace MultiArrayTools
|
|||
|
||||
typedef Index IndexType;
|
||||
|
||||
virtual Index begin() = 0;
|
||||
virtual Index end() = 0;
|
||||
virtual Index begin() const = 0;
|
||||
virtual Index end() const = 0;
|
||||
|
||||
protected:
|
||||
RangeInterface() = default;
|
||||
|
|
|
@ -35,13 +35,13 @@ namespace MultiArrayTools
|
|||
template <typename U, RangeType TYPE>
|
||||
U SingleIndex<U,TYPE>::meta() const
|
||||
{
|
||||
return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRangePtr )->get( IB::pos() );
|
||||
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->get( IB::pos() );
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
|
||||
{
|
||||
operator=( dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRangePtr )->getMeta( metaPos ) );
|
||||
operator=( std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ namespace MultiArrayTools
|
|||
template <typename U, RangeType TYPE>
|
||||
SingleRangeFactory<U,TYPE>::SingleRangeFactory(const std::vector<U>& space)
|
||||
{
|
||||
mProd = std::make_shared<oType>( space );
|
||||
mProd = std::shared_ptr<oType>( new SingleRange<U,TYPE>( space ) );
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
|
@ -120,16 +120,16 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE> SingleRange<U,TYPE>::begin() const
|
||||
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
|
||||
{
|
||||
SingleIndex<U,TYPE> i( RB::mThis );
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
|
||||
return i = 0;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
SingleIndex<U,TYPE> SingleRange<U,TYPE>::end() const
|
||||
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const
|
||||
{
|
||||
SingleIndex<U,TYPE> i( RB::mThis );
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
|
||||
return i = size();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace MultiArrayTools
|
|||
public:
|
||||
|
||||
typedef IndexBase IB;
|
||||
typedef U MetaType;
|
||||
|
||||
DEFAULT_MEMBERS(SingleIndex);
|
||||
|
||||
|
@ -29,8 +30,8 @@ namespace MultiArrayTools
|
|||
virtual SingleIndex& operator++() override;
|
||||
virtual SingleIndex& operator--() override;
|
||||
|
||||
virtual U meta() const;
|
||||
virtual SingleIndex& at(const U& metaPos);
|
||||
virtual U meta() const override;
|
||||
virtual SingleIndex& at(const U& metaPos) override;
|
||||
|
||||
virtual size_t dim() const override; // = 1
|
||||
virtual bool last() const override;
|
||||
|
@ -63,8 +64,8 @@ namespace MultiArrayTools
|
|||
const U& get(size_t pos) const;
|
||||
size_t getMeta(const U& metaPos) const;
|
||||
|
||||
virtual SingleIndex<U,TYPE> begin() const override;
|
||||
virtual SingleIndex<U,TYPE> end() const override;
|
||||
virtual IndexType begin() const override;
|
||||
virtual IndexType end() const override;
|
||||
virtual std::shared_ptr<IndexBase> index() const override;
|
||||
|
||||
friend SingleRangeFactory<U,TYPE>;
|
||||
|
|
Loading…
Reference in a new issue