started refactoring index linking -- intermediate commit

This commit is contained in:
Christian Zimmermann 2017-05-22 13:39:37 +02:00
parent 0a5cdd2339
commit 030d26a3bb
8 changed files with 70 additions and 402 deletions

View file

@ -38,54 +38,6 @@ namespace MultiArrayTools
//assert(not virt());
mName = nm.own();
}
bool IndefinitIndexBase::link(IndefinitIndexBase* toLink)
{
//assert(not virt());
if(toLink->rangeType() != rangeType() and toLink->name() == name()){
assert(0);
// throw !!
}
if(toLink->rangeType() == rangeType() and toLink->name() == name()){
if(mLinked == toLink){
return true; // dont link twice the same
}
else if(mLinked == nullptr){
mLinked = toLink;
return true;
}
else {
return mLinked->link(toLink);
}
}
else {
return false;
}
}
void IndefinitIndexBase::freeLinked()
{
if(mLinked != nullptr){
//mLinked->freeLinked();
mLinked = nullptr;
}
if(mSoftLinked != nullptr){
//mSoftLinked->freeLinked();
mSoftLinked = nullptr;
}
}
bool IndefinitIndexBase::linked() const
{
//assert(not virt());
return mLinked != nullptr;
}
bool IndefinitIndexBase::linkedTo(IndefinitIndexBase* link) const
{
//assert(not virt());
return mLinked == link or mSoftLinked == link;
}
void IndefinitIndexBase::setPos(size_t pos)
{

View file

@ -39,13 +39,6 @@ namespace MultiArrayTools
virtual MultiRangeType rangeType() const = 0;
virtual bool link(IndefinitIndexBase* toLink);
virtual void freeLinked();
virtual bool linked() const;
virtual bool linkedTo(IndefinitIndexBase* link) const;
virtual void linkTo(IndefinitIndexBase* target) = 0;
virtual IndefinitIndexBase* getLinked(const std::string& name) = 0;
virtual void setPos(size_t pos);
virtual void setPosRel(int relPos);
@ -72,9 +65,7 @@ namespace MultiArrayTools
int mPos;
size_t mMajorStep;
IndefinitIndexBase* mLinked = nullptr;
IndefinitIndexBase* mMajor = nullptr;
IndefinitIndexBase* mSoftLinked = nullptr;
};
template <class Index>

View file

@ -36,7 +36,7 @@ namespace MultiArrayTools
{
//#error "WRITE MAOR INTRINSIC CONTRACT FUNCTION"
//CHECK;
in.linkIndicesTo(MAOB::mIibPtr);
//CHECK;
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr);
//CHECK;
@ -51,7 +51,7 @@ namespace MultiArrayTools
//assert(not std::isnan( get() ));
}
//CHECK;
MAOB::mIibPtr->freeLinked();
}
template <typename T, class Range>
@ -90,7 +90,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -99,7 +99,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -109,7 +109,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range2>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -120,7 +120,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range2>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -130,7 +130,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(ConstMultiArrayOperationRoot<T,Range2>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -141,7 +141,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(const ConstMultiArrayOperationRoot<T,Range2>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -152,7 +152,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -162,7 +162,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayContraction<T,Operation,Range2,MAOps...>& in)
{
performAssignment(in);
freeIndex();
return *this;
}
@ -305,19 +305,6 @@ namespace MultiArrayTools
return 1;
}
template <typename T, class Range>
IndefinitIndexBase* MultiArrayOperationRoot<T,Range>::getLinked(const std::string& name) const
{
return mIndex.getLinked(name);
}
template <typename T, class Range>
void MultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->linkTo(target);
}
template <typename T, class Range>
T& MultiArrayOperationRoot<T,Range>::get()
{
@ -361,7 +348,6 @@ namespace MultiArrayTools
template <typename T, class Range>
void MultiArrayOperationRoot<T,Range>::freeIndex() const
{
MAOB::mIibPtr->freeLinked();
mIndex = mArrayRef.beginIndex();
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
@ -428,7 +414,7 @@ namespace MultiArrayTools
const std::string& indexName,
const MAOps&... mao) const
{
typename Range2::IndexType* ind = dynamic_cast<typename Range2::IndexType*>( mIndex.getLinked(indexName) );
// !!!!!
return MultiArrayContraction<T,ContractOperation,Range2,
ConstMultiArrayOperationRoot<T,Range>,
MAOps...>(cop, *ind, *this, mao...);
@ -443,7 +429,7 @@ namespace MultiArrayTools
size_t end,
const MAOps&... mao) const
{
typename Range2::IndexType* ind = dynamic_cast<typename Range2::IndexType*>( mIndex.getLinked(indexName) );
// !!!!
return MultiArrayContraction<T,ContractOperation,Range2,
ConstMultiArrayOperationRoot<T,Range>,
MAOps...>(cop, *ind, begin, end, *this, mao...);
@ -508,19 +494,6 @@ namespace MultiArrayTools
return 1;
}
template <typename T, class Range>
IndefinitIndexBase* ConstMultiArrayOperationRoot<T,Range>::getLinked(const std::string& name) const
{
return mIndex.getLinked(name);
}
template <typename T, class Range>
void ConstMultiArrayOperationRoot<T,Range>::linkIndicesTo(IndefinitIndexBase* target) const
{
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->linkTo(target);
}
template <typename T, class Range>
const T& ConstMultiArrayOperationRoot<T,Range>::get() const
{
@ -542,15 +515,6 @@ namespace MultiArrayTools
return *this;
}
template <typename T, class Range>
void ConstMultiArrayOperationRoot<T,Range>::freeIndex() const
{
MAOB::mIibPtr->freeLinked();
mIndex = mArrayRef.beginIndex();
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
}
/********************************
* MultiArrayOperationMap *
********************************/
@ -588,15 +552,10 @@ namespace MultiArrayTools
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
mRoot.linkIndicesTo( &mIndex );
mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex );
in.linkIndicesTo( &mIndex );
// !!!!!
MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
cnto.linkIndicesTo( &mIndex );
cnto.linkIndicesTo( &mMF.index() );
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get();
@ -624,16 +583,9 @@ namespace MultiArrayTools
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
mRoot.linkIndicesTo( &mIndex );
mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex );
in.linkIndicesTo( &mIndex );
//!!!!!!!
MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
cnto.linkIndicesTo( &mIndex );
cnto.linkIndicesTo( &mMF.index() );
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get();
cnto.get() += 1.;
@ -651,24 +603,6 @@ namespace MultiArrayTools
return 1;
}
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
IndefinitIndexBase* MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::
getLinked(const std::string& name) const
{
return mRoot.getLinked(name);
}
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
void MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::
linkIndicesTo(IndefinitIndexBase* target) const
{
mRoot.linkIndicesTo(target);
}
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
void MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::setInternalLinks() const
{ }
template <typename T, class InRange, class TotalInRange, class OutRange, class TotalRange>
const T& MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::get() const
{
@ -685,27 +619,6 @@ namespace MultiArrayTools
* MultiArrayOperation *
*****************************/
template <size_t N>
struct TupleIndicesLinker
{
template <class IndexTuple>
static void linkTupleIndicesTo(IndexTuple& itp, IndefinitIndexBase* target)
{
std::get<N>(itp).linkIndicesTo(target);
TupleIndicesLinker<N-1>::linkTupleIndicesTo(itp, target);
}
};
template <>
struct TupleIndicesLinker<0>
{
template <class IndexTuple>
static void linkTupleIndicesTo(IndexTuple& itp, IndefinitIndexBase* target)
{
std::get<0>(itp).linkIndicesTo(target);
}
};
template <size_t N>
struct OperationCall
{
@ -745,37 +658,6 @@ namespace MultiArrayTools
return op(std::get<0>(tp).get(), args.get()...);
}
};
template <size_t N>
struct LinkedIndexGetter
{
template <class Tuple>
static IndefinitIndexBase* getLinked(const Tuple& optuple,
const std::string& name,
IndefinitIndexBase* current)
{
if(current == nullptr){
current = std::get<N>(optuple).getLinked(name);
LinkedIndexGetter<N-1>::getLinked(optuple, name, current);
}
return current;
}
};
template <>
struct LinkedIndexGetter<0>
{
template <class Tuple>
static IndefinitIndexBase* getLinked(const Tuple& optuple,
const std::string& name,
IndefinitIndexBase* current)
{
if(current == nullptr){
current = std::get<0>(optuple).getLinked(name);
}
return current;
}
};
template <typename T, class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MAOps...>::
@ -816,7 +698,7 @@ namespace MultiArrayTools
const std::string& indexName,
const MAOps2&... mao) const
{
typename Range2::IndexType* ind = dynamic_cast<typename Range2::IndexType*>( getLinked(indexName) );
// !!!
return MultiArrayContraction<T,ContractOperation,Range2,MultiArrayOperation<T,Operation,MAOps...>,
MAOps2...>(cop, *ind, *this, mao...);
}
@ -859,19 +741,6 @@ namespace MultiArrayTools
return sizeof...(MAOps) + 1;
}
template <typename T, class Operation, class... MAOps>
IndefinitIndexBase* MultiArrayOperation<T,Operation,MAOps...>::getLinked(const std::string& name) const
{
return LinkedIndexGetter<sizeof...(MAOps)-1>::getLinked(mArgs, name, nullptr);
}
template <typename T, class Operation, class... MAOps>
void MultiArrayOperation<T,Operation,MAOps...>::linkIndicesTo(IndefinitIndexBase* target) const
{
TupleIndicesLinker<sizeof...(MAOps)-1>::linkTupleIndicesTo(mArgs, target);
}
template <typename T, class Operation, class... MAOps>
const T& MultiArrayOperation<T,Operation,MAOps...>::get() const
{
@ -991,28 +860,6 @@ namespace MultiArrayTools
return sizeof...(MAOps) + 1;
}
template <typename T, class ContractOperation, class Range, class... MAOps>
IndefinitIndexBase* MultiArrayContraction<T,ContractOperation,Range,MAOps...>::getLinked(const std::string& name) const
{
return LinkedIndexGetter<sizeof...(MAOps)-1>::getLinked(mArgs, name, nullptr);
}
template <typename T, class ContractOperation, class Range, class... MAOps>
void MultiArrayContraction<T,ContractOperation,Range,MAOps...>::setInternalLinks() const
{
linkIndicesTo(&mRunIndex);
}
template <typename T, class ContractOperation, class Range, class... MAOps>
void MultiArrayContraction<T,ContractOperation,Range,MAOps...>::linkIndicesTo(IndefinitIndexBase* target) const
{
if(target != &mRunIndex){
setInternalLinks();
}
TupleIndicesLinker<sizeof...(MAOps)-1>::linkTupleIndicesTo(mArgs, target);
}
template <typename T, class ContractOperation, class Range, class... MAOps>
const T& MultiArrayContraction<T,ContractOperation,Range,MAOps...>::get() const
{

View file

@ -26,14 +26,10 @@ namespace MultiArrayTools
virtual size_t argNum() const = 0;
const IndefinitIndexBase& index() const;
virtual IndefinitIndexBase* getLinked(const std::string& name) const = 0;
virtual void linkIndicesTo(IndefinitIndexBase* target) const = 0;
virtual const T& get() const = 0;
virtual void setInternalLinks() const {}
virtual void freeIndex() const;
protected:
mutable IndefinitIndexBase* mIibPtr = nullptr;
@ -145,16 +141,11 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind);
const MultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind) const;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual T& get() override;
virtual const T& get() const override;
const Name& name() const;
virtual void freeIndex() const override;
const MultiArrayBase<T,Range>& getCont() const { return mArrayRef; }
template <typename U, class RangeX>
@ -224,16 +215,10 @@ namespace MultiArrayTools
// set index -> implement !!!!!
const ConstMultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind) const;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual const T& get() const override;
const Name& name() const;
virtual void freeIndex() const override;
const MultiArrayBase<T,Range>& getCont() const { return mArrayRef; }
template <typename U, class RangeX>
@ -264,11 +249,6 @@ namespace MultiArrayTools
MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in);
virtual size_t argNum() const override;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual void setInternalLinks() const override;
virtual const T& get() const override;
virtual T& get() override;
@ -319,9 +299,6 @@ namespace MultiArrayTools
auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec));
virtual size_t argNum() const override;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual const T& get() const override;
@ -377,14 +354,9 @@ namespace MultiArrayTools
template <class MAOp2>
auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec));
virtual void setInternalLinks() const override;
virtual size_t argNum() const override;
virtual IndefinitIndexBase* getLinked(const std::string& name) const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual const T& get() const override;
protected:

View file

@ -237,17 +237,17 @@ namespace MultiArrayTools
struct IndexSetter
{
template <class... Ranges>
static void setBegin(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r)
static void setBegin(MultiRange<Ranges...>::IndexType& i, const MultiRange<Ranges...>::SpaceType& r)
{
std::get<N>(i) = std::get<N>(r).begin();
*std::get<N>(i) = std::get<N>(r)->begin();
IndexSetter<N-1>::setBegin(i,r);
}
template <class... Ranges>
static void setEnd(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r)
static void setEnd(MultiRange<Ranges...>::IndexType& i, const MultiRange<Ranges...>::SpaceType& r)
{
std::get<N>(i) = std::get<N>(r).end();
std::get<N>(i) -= 1;
*std::get<N>(i) = std::get<N>(r)->end();
*std::get<N>(i) -= 1;
IndexSetter<N-1>::setEnd(i,r);
}
};
@ -256,16 +256,16 @@ namespace MultiArrayTools
struct IndexSetter<0>
{
template <class... Ranges>
static void setBegin(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r)
static void setBegin(MultiRange<Ranges...>::IndexType& i, const MultiRange<Ranges...>::SpaceType& r)
{
std::get<0>(i) = std::get<0>(r).begin();
*std::get<0>(i) = std::get<0>(r)->begin();
}
template <class... Ranges>
static void setEnd(std::tuple<typename Ranges::IndexType...>& i, const std::tuple<Ranges...>& r)
static void setEnd(MultiRange<Ranges...>::IndexType& i, const MultiRange<Ranges...>::SpaceType& r)
{
std::get<0>(i) = std::get<0>(r).end();
std::get<0>(i) -= 1;
*std::get<0>(i) = std::get<0>(r)->end();
*std::get<0>(i) -= 1;
}
};
@ -273,9 +273,9 @@ namespace MultiArrayTools
struct RangeVecBuilder
{
template <class... Ranges>
static void buildRangeVec(std::vector<MultiRangeType>& rvec, const std::tuple<Ranges...>& rs)
static void buildRangeVec(std::vector<MultiRangeType>& rvec, const MultiRange<Ranges...>::SpaceType& rs)
{
rvec.push_back(std::get<sizeof...(Ranges)-N-1>(rs).type());
rvec.push_back(std::get<sizeof...(Ranges)-N-1>(rs)->type());
RangeVecBuilder<N-1>::buildRangeVec(rvec, rs);
}
};
@ -283,20 +283,20 @@ namespace MultiArrayTools
struct RangeVecBuilder<0>
{
template <class... Ranges>
static void buildRangeVec(std::vector<MultiRangeType>& rvec, const std::tuple<Ranges...>& rs)
static void buildRangeVec(std::vector<MultiRangeType>& rvec, const MultiRange<Ranges...>::SpaceType& rs)
{
rvec.push_back(std::get<sizeof...(Ranges)-1>(rs).type());
rvec.push_back(std::get<sizeof...(Ranges)-1>(rs)->type());
}
};
// HERE !!!
template <size_t N>
struct MetaPosGetter
{
template <class... Indices>
static void getMetaPos(std::tuple<decltype(Indices().getMetaPos())...>& target,
const std::tuple<Indices...>& source)
const typename MultiIndex<Indices...>::IndexPack& source)
{
std::get<N>(target) = std::get<N>(source).getMetaPos();
std::get<N>(target) = std::get<N>(source)->getMetaPos();
MetaPosGetter<N-1>::getMetaPos(target, source);
}
};
@ -306,9 +306,9 @@ namespace MultiArrayTools
{
template <class... Indices>
static void getMetaPos(std::tuple<decltype(Indices().getMetaPos())...>& target,
const std::tuple<Indices...>& source)
const typename MultiIndex<Indices...>::IndexPack& source)
{
std::get<0>(target) = std::get<0>(source).getMetaPos();
std::get<0>(target) = std::get<0>(source)->getMetaPos();
}
};
@ -527,55 +527,18 @@ namespace MultiArrayTools
}
template <class... Indices>
bool MultiIndex<Indices...>::link(IndefinitIndexBase* toLink)
template <size_t N>
auto getIndex() -> decltype(*std::get<N>(mIPack))&
//typename std::tuple_element<N, std::tuple<Indices...> >::type& MultiIndex<Indices...>::getIndex()
{
if(toLink->rangeType() != rangeType() and
toLink->name() == IIB::name() and
not (IIB::name() == "master")){
// throw !!
assert(0);
}
if(toLink->rangeType() == rangeType() and toLink->name() == IIB::name()){
if(IIB::mLinked == toLink or IIB::mSoftLinked == toLink){
return true; // dont link twice the same
}
else if(IIB::mLinked == nullptr and IIB::mSoftLinked == nullptr){
IIB::mLinked = toLink;
return true;
}
else {
if(IIB::mLinked == nullptr){
return IIB::mSoftLinked->link(toLink);
}
else {
return IIB::mLinked->link(toLink);
}
}
}
else {
if(linkLower(toLink)){
IIB::mSoftLinked = IIB::mLinked;
IIB::mLinked = nullptr;
return true;
}
else {
return false;
}
}
return *std::get<N>(mIPack);
}
template <class... Indices>
template <size_t N>
typename std::tuple_element<N, std::tuple<Indices...> >::type& MultiIndex<Indices...>::getIndex()
auto getIndex() const -> const decltype(*std::get<N>(mIPack))&
{
return std::get<N>(mIPack);
}
template <class... Indices>
template <size_t N>
typename std::tuple_element<N, std::tuple<Indices...> >::type const& MultiIndex<Indices...>::getIndex() const
{
return std::get<N>(mIPack);
return *std::get<N>(mIPack);
}
template <class... Indices>
@ -615,49 +578,12 @@ namespace MultiArrayTools
return *this;
}
template <class... Indices>
bool MultiIndex<Indices...>::linkLower(IndefinitIndexBase* toLink)
{
bool res = false;
for(size_t i = 0; i != sizeof...(Indices); ++i){
res |= get(i).link(toLink);
}
return res;
}
template <class... Indices>
void MultiIndex<Indices...>::linkTo(IndefinitIndexBase* target)
{
target->link(this);
for(size_t i = 0; i != sizeof...(Indices); ++i){
get(i).linkTo(target);
}
}
template <class... Indices>
void MultiIndex<Indices...>::copyPos(const MultiIndex<Indices...>& in)
{
PositionCopy<sizeof...(Indices)-1>::copyPos(*this, in);
}
template <class... Indices>
IndefinitIndexBase* MultiIndex<Indices...>::getLinked(const std::string& name)
{
if(name == IIB::mName){
return this;
}
for(size_t i = 0; i != sizeof...(Indices); ++i){
IndefinitIndexBase* iibPtr = get(i).getLinked(name);
if(iibPtr != nullptr){
//CHECK;
return iibPtr;
}
}
//CHECK;
return nullptr;
}
template <class... Indices>
size_t MultiIndex<Indices...>::giveSubStepSize(IndefinitIndexBase* subIndex)
{
@ -703,23 +629,25 @@ namespace MultiArrayTools
******************/
template <class... Ranges>
MultiRange<Ranges...>::MultiRange(const Ranges&... rs) : mSpace(std::make_tuple(rs...)) {}
MultiRange<Ranges...>::MultiRange(const std::shared_ptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {}
template <class... Ranges>
MultiRange<Ranges...>::MultiRange(const SpaceType& space) : mSpace(space) {}
template <class... Ranges>
template <size_t N>
typename std::tuple_element<N, std::tuple<Ranges...> >::type& MultiRange<Ranges...>::getRange()
auto getRange() -> decltype(*std::get<N>(mSpace))&
//typename std::tuple_element<N, std::tuple<Ranges...> >::type& MultiRange<Ranges...>::getRange()
{
return std::get<N>(mSpace);
return *std::get<N>(mSpace);
}
template <class... Ranges>
template <size_t N>
typename std::tuple_element<N, std::tuple<Ranges...> >::type const& MultiRange<Ranges...>::getRange() const
auto getRange() const -> 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);
return *std::get<N>(mSpace);
}
template <class... Ranges>
@ -745,7 +673,7 @@ namespace MultiArrayTools
template <class... Ranges>
MultiIndex<typename Ranges::IndexType...> MultiRange<Ranges...>::begin() const
{
std::tuple<typename Ranges::IndexType...> is;
std::tuple<std::shared_ptr<typename Ranges::IndexType>...> is;
IndexSetter<sizeof...(Ranges)-1>::setBegin(is,mSpace);
return MultiIndex<typename Ranges::IndexType...>(this, is);
}
@ -753,7 +681,7 @@ namespace MultiArrayTools
template <class... Ranges>
MultiIndex<typename Ranges::IndexType...> MultiRange<Ranges...>::end() const
{
std::tuple<typename Ranges::IndexType...> is;
std::tuple<std::shared_ptr<typename Ranges::IndexType>...> is;
IndexSetter<sizeof...(Ranges)-1>::setEnd(is,mSpace);
return ++MultiIndex<typename Ranges::IndexType...>(this, is);
}

View file

@ -5,6 +5,7 @@
#include <cstdlib>
#include <tuple>
#include <memory>
#include "base_def.h"
#include "range_base.h"
@ -17,9 +18,9 @@ namespace MultiArrayTools
class MultiIndex : public IndexBase<MultiIndex<Indices...> >
{
public:
typedef std::tuple<Indices...> IndexPack;
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef IndefinitIndexBase IIB;
typedef IndexBase<MultiIndex<Indices...> > IB;
typedef IndexBase<MultiIndex<std::shared_ptr<Indices>...> > IB;
typedef std::tuple<decltype(Indices().getMetaPos())...> MetaType;
protected:
@ -38,12 +39,12 @@ namespace MultiArrayTools
MultiIndex(const MultiIndex& in);
MultiIndex& operator=(const MultiIndex& in);
MultiIndex(RangeBase<MultiIndex<Indices...> > const* range);
MultiIndex(RangeBase<MultiIndex<std::shared_ptr<Indices>...> > const* range);
MultiIndex(RangeBase<MultiIndex<Indices...> > const* range,
MultiIndex(RangeBase<MultiIndex<std::shared_ptr<Indices>...> > const* range,
Indices&&... inds);
MultiIndex(RangeBase<MultiIndex<Indices...> > const* range,
MultiIndex(RangeBase<MultiIndex<std::shared_ptr<Indices>...> > const* range,
const IndexPack& ipack);
//virtual ~MultiIndex();
@ -60,10 +61,12 @@ namespace MultiArrayTools
virtual MultiRangeType rangeType() const override;
template <size_t N>
typename std::tuple_element<N, std::tuple<Indices...> >::type& getIndex();
auto getIndex() ->;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Indices>...> >::type& getIndex();
template <size_t N>
typename std::tuple_element<N, std::tuple<Indices...> >::type const& getIndex() const;
auto getIndex() const ->;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Indices>...> >::type const& getIndex() const;
IndefinitIndexBase& get(size_t n);
const IndefinitIndexBase& get(size_t n) const;
@ -79,12 +82,8 @@ namespace MultiArrayTools
// dimension of MultiRange; includes ALL degrees of freedom
virtual size_t dim() const override;
virtual bool link(IndefinitIndexBase* toLink) override;
virtual void linkTo(IndefinitIndexBase* target) override;
virtual void copyPos(const MultiIndex<std::shared_ptr<Indices>...>& in) override;
virtual void copyPos(const MultiIndex<Indices...>& in) override;
virtual IndefinitIndexBase* getLinked(const std::string& name) override;
virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) override;
//virtual void eval() override;
@ -102,23 +101,24 @@ namespace MultiArrayTools
{
public:
typedef std::tuple<Ranges...> SpaceType;
typedef typename RangeBase<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
typedef typename RangeBase<MultiIndex<typename Ranges::IndexType...> >::IndexType
IndexType;
DEFAULT_MEMBERS(MultiRange);
MultiRange(const Ranges&... rs);
MultiRange(const std::shared_ptr<Ranges>&... rs);
MultiRange(const SpaceType& space);
static const size_t dim = sizeof...(Ranges);
static MultiRange<Ranges...> oType() { return MultiRange<Ranges...>(); }
template <size_t N>
typename std::tuple_element<N, std::tuple<Ranges...> >::type& getRange();
template <size_t N> // !!! return ref to range, not the corresp. shared ptr
auto getRange() -> ;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Ranges>...> >::type& getRange();
template <size_t N>
typename std::tuple_element<N, std::tuple<Ranges...> >::type const& getRange() const;
template <size_t N> // !!!
auto getRange() const ->;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Ranges>...> >::type const& getRange() const;
size_t size() const override;
const SpaceType& space() const;

View file

@ -347,31 +347,12 @@ namespace MultiArrayTools
return in.pos();
}
template <typename U, RangeType TYPE>
void SingleIndex<U,TYPE>::linkTo(IndefinitIndexBase* target)
{
target->link(this);
}
template <typename U, RangeType TYPE>
void SingleIndex<U,TYPE>::copyPos(const SingleIndex<U,TYPE>& in)
{
IIB::setPos(in.pos());
}
template <typename U, RangeType TYPE>
IndefinitIndexBase* SingleIndex<U,TYPE>::getLinked(const std::string& name)
{
//VCHECK(name);
//VCHECK(IIB::mName);
if(name == IIB::mName){
return this;
}
else {
return nullptr;
}
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::giveSubStepSize(IndefinitIndexBase* subIndex)
{

View file

@ -47,11 +47,8 @@ namespace MultiArrayTools
virtual SingleIndex& atMeta(const U& metaPos);
virtual size_t dim() const override; // = 1
virtual void linkTo(IndefinitIndexBase* target) override;
virtual void copyPos(const SingleIndex& in) override;
virtual IndefinitIndexBase* getLinked(const std::string& name) override;
virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) override;
//virtual void eval() override;