fixing some of the compile errors

This commit is contained in:
Christian Zimmermann 2017-12-12 11:15:39 +01:00
parent 888c7f6a07
commit f691c9ea66
4 changed files with 93 additions and 44 deletions

View file

@ -42,9 +42,14 @@ namespace MultiArrayTools
template <class MRange>
ContainerIndex(const std::shared_ptr<MRange>& range);
ContainerIndex& operator=(size_t pos) { IB::operator=(pos) ; return *this; }
template <size_t N>
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
ContainerIndex& operator()(); // -> sync; just to shorten the code
@ -56,7 +61,7 @@ namespace MultiArrayTools
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
static IndexType S_type(ContainerIndex* i) { return IndexType::CONT; }
static IndexType S_type(ContainerIndex const* i) { return IndexType::CONT; }
static ContainerIndex& S_pp_op(ContainerIndex* i)
{
@ -100,7 +105,7 @@ namespace MultiArrayTools
return tmp;
}
static MetaType S_meta(ContainerIndex* i)
static MetaType S_meta(ContainerIndex const* i)
{
MetaType metaTuple;
PackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, i->mIPack);
@ -114,28 +119,33 @@ namespace MultiArrayTools
return *i;
}
static size_t S_dim(ContainerIndex* i)
static size_t S_dim(ContainerIndex const* i)
{
return sizeof...(Indices);
}
static bool S_first(ContainerIndex* i)
static bool S_first(ContainerIndex const* i)
{
return i->pos() == 0;
}
static bool S_last(ContainerIndex* i)
static bool S_last(ContainerIndex const* i)
{
return i->pos() == i->mMax - 1;
}
static std::shared_ptr<RangeType> S_range(ContainerIndex const* i)
{
return std::dynamic_pointer_cast<RangeType>( i->mRangePtr );
}
template <size_t N>
static auto S_getPtr(ContainerIndex* i) -> decltype( std::get<N>( mIPack ) )&
static auto S_getPtr(ContainerIndex const* i) -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>( i->mIPack );
}
static std::shared_ptr<VIWB> S_getVPtr(ContainerIndex* i, size_t n)
static std::shared_ptr<VIWB> S_getVPtr(ContainerIndex const* i, size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
@ -145,7 +155,7 @@ namespace MultiArrayTools
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
}
static size_t S_getStepSize(ContainerIndex* i, size_t n)
static size_t S_getStepSize(ContainerIndex const* i, size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
@ -154,7 +164,7 @@ namespace MultiArrayTools
return i->mBlockSizes[n+1];
}
static std::string S_id(ContainerIndex* i) { return std::string("con") + std::to_string(IB::mId); }
static std::string S_id(ContainerIndex const* i) { return std::string("con") + std::to_string(i->mId); }
};
@ -182,7 +192,8 @@ namespace MultiArrayTools
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
typedef typename RangeInterface<ContainerIndex<typename Ranges::IndexType...> >::IndexType IndexType;
typedef ContainerIndex<typename Ranges::IndexType...> IndexType;
//typedef typename RangeInterface<ContainerIndex<typename Ranges::IndexType...> >::IndexType IndexType;
protected:
ContainerRange() = default;
@ -264,6 +275,13 @@ namespace MultiArrayTools
return *std::get<N>( mIPack );
}
template <class... Indices>
template <size_t N>
auto ContainerIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>( mIPack );
}
template <class... Indices>
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
{
@ -368,8 +386,9 @@ namespace MultiArrayTools
template <class... Ranges>
std::shared_ptr<VIWB> ContainerRange<Ranges...>::index() const
{
return std::make_shared<VIWB>
( std::make_shared<ContainerIndex<typename Ranges::IndexType...> >
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
( std::make_shared<IndexType>
( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}

View file

@ -53,20 +53,20 @@ namespace MultiArrayTools
}
template <class I>
class IndexWrapper
class IndexWrapper : public VirtualIndexWrapperBase
{
public:
DEFAULT_MEMBERS(IndexWrapper);
IndexWrapper(std::shared_ptr<I>& idxPtr);
IndexWrapper(std::shared_ptr<I> idxPtr);
virtual IndexType type() const override { return mIdxPtr->type(); }
virtual size_t dim() const override { return mIdxPtr->dim(); }
virtual size_t pos() const override { return mIdxPtr->pos(); }
virtual size_t max() const override { return mIdxPtr->max(); }
virtual std::shared_ptr<RangeBase> rangePtr() const override { return mIdxPtr->rangePtr(); }
virtual std::shared_ptr<VirtualIndexWrapperBase> getPtr(size_t n) const override { return mIdxPtr->getv(n); }
virtual std::shared_ptr<RangeBase> rangePtr() const override { return mIdxPtr->vrange(); }
virtual std::shared_ptr<VirtualIndexWrapperBase> getPtr(size_t n) const override { return mIdxPtr->getVPtr(n); }
virtual intptr_t getPtrNum() const override { return static_cast<intptr_t>( mIdxPtr.get() ); }
virtual size_t getStepSize(size_t n) const override { return mIdxPtr->getStepSize(n); }
@ -78,7 +78,7 @@ namespace MultiArrayTools
class IndexInterface
{
public:
typedef typename I::RangeType RangeType;
//typedef typename I::RangeType RangeType;
//DEFAULT_MEMBERS(IndexInterface);
@ -106,12 +106,14 @@ namespace MultiArrayTools
bool last() const { return I::S_last(THIS()); }
bool first() const { return I::S_first(THIS()); }
std::shared_ptr<RangeBase> vrange() const { return mRangePtr; }
std::shared_ptr<RangeType> range() const { return std::dynamic_pointer_cast<RangeType>(mRangePtr); }
/*auto range() const -> decltype( I::S_range(THIS()) ) { return I::S_range(THIS()); }
template <size_t N>
auto getPtr() const -> decltype(I::S_get<N>(THIS())) { return I::S_get<N>(THIS()); }
auto getPtr() const -> decltype(I::template S_get<N>(THIS()))
{ return I::template S_get<N>(THIS()); }
*/
std::shared_ptr<VIWB> getVPtr(size_t n) const { return I::S_getVPtr(THIS(),n); }
size_t getStepSize(size_t n) const { return I::S_getStepSize(THIS(),n); }

View file

@ -40,6 +40,8 @@ namespace MultiArrayTools
public:
MultiIndex() = delete;
MultiIndex& operator=(size_t pos) { IB::operator=(pos) ; return *this; }
// NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly )
@ -59,6 +61,9 @@ namespace MultiArrayTools
template <size_t N>
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
// raplace instances (in contrast to its analogon in ContainerIndex
// MultiIndices CANNOT be influences be its subindices, so there is
// NO foreign/external controll)
@ -70,7 +75,7 @@ namespace MultiArrayTools
friend IB;
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
static IndexType S_type(MultiIndex* i) { return IndexType::MULTI; }
static IndexType S_type(MultiIndex const* i) { return IndexType::MULTI; }
static MultiIndex& S_ass_op(MultiIndex* i, size_t pos)
{
@ -107,7 +112,7 @@ namespace MultiArrayTools
return tmp;
}
static MetaType S_meta(MultiIndex* i)
static MetaType S_meta(MultiIndex const* i)
{
MetaType metaTuple;
PackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, i->mIPack);
@ -121,29 +126,34 @@ namespace MultiArrayTools
return *i;
}
static size_t S_dim(MultiIndex* i)
static size_t S_dim(MultiIndex const* i)
{
return sizeof...(Indices);
}
static bool S_first(MultiIndex* i)
static bool S_first(MultiIndex const* i)
{
return i->mPos == 0;
}
static bool S_last(MultiIndex* i)
static bool S_last(MultiIndex const* i)
{
return i->mPos == i->mMax - 1;
}
static std::shared_ptr<RangeType> S_range(MultiIndex const* i)
{
return std::dynamic_pointer_cast<RangeType>( i->mRangePtr );
}
template <size_t N>
static auto S_getPtr(MultiIndex* i) -> decltype( std::get<N>( mIPack ) )&
static auto S_getPtr(MultiIndex const* i) -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(i->mIPack);
}
//const IndexBase& get(size_t n);
static std::shared_ptr<VIWB> S_getVPtr(MultiIndex* i, size_t n)
static std::shared_ptr<VIWB> S_getVPtr(MultiIndex const* i, size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
@ -153,7 +163,7 @@ namespace MultiArrayTools
return PackNum<sizeof...(Indices)-1>::getIndexPtr(*t, n);
}
static size_t S_getStepSize(MultiIndex* i, size_t n)
static size_t S_getStepSize(MultiIndex const* i, size_t n)
{
if(n >= sizeof...(Indices)){
assert(0);
@ -162,7 +172,7 @@ namespace MultiArrayTools
return i->mBlockSizes[n+1];
}
static std::string S_id(MultiIndex* i) { return std::string("mul") + std::to_string(IB::mId); }
static std::string S_id(MultiIndex const* i) { return std::string("mul") + std::to_string(i->mId); }
};
/*************************
@ -193,7 +203,8 @@ namespace MultiArrayTools
public:
typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
typedef MultiIndex<typename Ranges::IndexType...> IndexType;
//typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
protected:
MultiRange() = delete;
@ -311,6 +322,13 @@ namespace MultiArrayTools
return *std::get<N>(mIPack);
}
template <class... Indices>
template <size_t N>
auto MultiIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
{
return std::get<N>(mIPack);
}
template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
{
@ -413,8 +431,9 @@ namespace MultiArrayTools
template <class... Ranges>
std::shared_ptr<VIWB> MultiRange<Ranges...>::index() const
{
return std::make_shared<VIWB>
( std::make_shared<MultiIndex<typename Ranges::IndexType...> >
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
( std::make_shared<IndexType>
( std::dynamic_pointer_cast<MultiRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}

View file

@ -27,13 +27,15 @@ namespace MultiArrayTools
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
SingleIndex& operator=(size_t pos) { IB::operator=(pos); return *this; }
private:
friend IB;
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
static IndexType S_type(SingleIndex* i)
static IndexType S_type(SingleIndex const* i)
{
return IndexType::SINGLE;
}
@ -68,46 +70,51 @@ namespace MultiArrayTools
return 1;
}
static U S_meta(SingleIndex* i)
static U S_meta(SingleIndex const* i)
{
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( i->mRangePtr )->get( i->pos() );
}
static SingleIndex& S_at(SingleIndex* i, const U& metaPos)
{
operator=( std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( i->mRangePtr )->getMeta( metaPos ) );
(*i) = std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( i->mRangePtr )->getMeta( metaPos );
return *i;
}
static size_t S_dim(SingleIndex* i) // = 1
static size_t S_dim(SingleIndex const* i) // = 1
{
return 1;
}
static bool S_last(SingleIndex* i)
static bool S_last(SingleIndex const* i)
{
return i->mPos == i->mMax - 1;
}
static bool S_first(SingleIndex* i)
static bool S_first(SingleIndex const* i)
{
return i->mPos == 0;
}
static std::shared_ptr<RangeType> S_range(SingleIndex const* i)
{
return std::dynamic_pointer_cast<RangeType>( i->mRangePtr );
}
template <size_t N>
static void S_getPtr(SingleIndex* i) {}
static std::shared_ptr<VIWB> S_getVPtr(SingleIndex* i, size_t n)
static std::shared_ptr<VIWB> S_getVPtr(SingleIndex const* i, size_t n)
{
return std::shared_ptr<VIWB>();
}
static size_t S_getStepSize(SingleIndex* i, size_t n)
static size_t S_getStepSize(SingleIndex const* i, size_t n)
{
return 1;
}
static std::string S_id(SingleIndex* i) { return std::string("sin") + std::to_string(IB::mId); }
static std::string S_id(SingleIndex const* i) { return std::string("sin") + std::to_string(i->mId); }
};
template <typename U, RangeType TYPE>
@ -128,7 +135,8 @@ namespace MultiArrayTools
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
typedef SingleIndex<U,TYPE> IndexType;
//typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
virtual size_t size() const override;
virtual size_t dim() const override;
@ -246,8 +254,9 @@ namespace MultiArrayTools
template <typename U, RangeType TYPE>
std::shared_ptr<VIWB> SingleRange<U,TYPE>::index() const
{
return std::make_shared<VIWB>
( std::make_shared<SingleIndex<U,TYPE> >
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
( std::make_shared<IndexType>
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}