...continuing

This commit is contained in:
Christian Zimmermann 2017-05-24 19:01:02 +02:00
parent 3fde2b9f66
commit b63d56e315
9 changed files with 133 additions and 179 deletions

View file

@ -51,6 +51,9 @@ namespace MultiArrayTools
// range_base.h // range_base.h
class MultiRangeType; class MultiRangeType;
// range_base.h
class IndefinitRangeBase;
// range_base.h // range_base.h
template <class Index> template <class Index>
class RangeBase; class RangeBase;

View file

@ -7,37 +7,68 @@ namespace MultiArrayTools
* IndefinitIndexBase * * IndefinitIndexBase *
************************/ ************************/
IndefinitIndexBase::~IndefinitIndexBase()
{
mMajor = nullptr;
}
size_t IndefinitIndexBase::pos() const size_t IndefinitIndexBase::pos() const
{ {
//assert(not virt()); //assert(not virt());
return static_cast<size_t>( mPos ); return static_cast<size_t>( mPos );
} }
void IndefinitIndexBase::setPos(size_t pos) bool IndefinitIndexBase::operator==(const IndefinitIndexBase& i) const
{
return rangeType() == in.rangeType() and pos() == in.pos();
}
bool IndefinitIndexBase::operator!=(const IndefinitIndexBase& i) const
{
return rangeType() != in.rangeType() or pos() != in.pos();
}
IndefinitIndexBase& IndefinitIndexBase::setPos(size_t pos, IndefinitIndexBase* ctrlPtr)
{ {
//CHECK;
//assert(not virt());
mPos = pos; mPos = pos;
for(auto mm: mMajor){
if(mm.first == ctrlPtr){
continue;
}
mm.first->setPos(mm.first->pos() % mm.second + mm.second * pos, this);
}
return *this;
} }
void IndefinitIndexBase::setPosRel(int relPos) IndefinitIndexBase& IndefinitIndexBase::setPosRel(int relPos, IndefinitIndexBase* ctrlPtr)
{ {
mPos += relPos; mPos += relPos;
for(auto mm: mMajor){
if(mm.first == ctrlPtr){
continue;
}
mm.first->setPosRel(mm.second * relPos, this);
}
return *this;
} }
// MAJOR INDEX UPDATE !!!!!
void IndefinitIndexBase::toFirst() IndefinitIndexBase& IndefinitIndexBase::toFirst(IndefinitIndexBase* ctrlPtr)
{ {
mPos = 0; mPos = 0;
for(auto mm: mMajor){
if(mm.first == ctrlPtr){
continue;
}
mm.first->setPos(mm.first->pos() % mm.second, this);
}
return *this;
} }
void IndefinitIndexBase::toLast() IndefinitIndexBase& IndefinitIndexBase::toLast(IndefinitIndexBase* ctrlPtr)
{ {
mPos = max() - 1; mPos = max() - 1;
for(auto mm: mMajor){
if(mm.first == ctrlPtr){
continue;
}
mm.first->setPos(mm.first->pos() % mm.second + mm.second * mPos, this);
}
return *this;
} }
int IndefinitIndexBase::outOfRange() const int IndefinitIndexBase::outOfRange() const
@ -58,49 +89,15 @@ namespace MultiArrayTools
return mPos == max(); return mPos == max();
} }
bool IndefinitIndexBase::toNull() const bool IndefinitIndexBase::master() const
{ {
//assert(not virt()); return mMajor.size() == 0;
return true;
} }
void IndefinitIndexBase::evalMajor() IndefinitIndexBase& IndefinitIndexBase::subOrd(IndefinitIndexBase* major)
{ {
//assert(not virt()); mMajor[major] = major->giveSubStepSize(this);
if(not master()){ return *this;
//int start = mMajor->pos();
mMajor->eval();
//VCHECK(static_cast<int>( mMajor->pos() ) - start);
}
}
void IndefinitIndexBase::evalMajor(int num)
{
//assert(not virt());
//CHECK;
if(not master()){
//int start = mMajor->pos();
mMajor->setPosRel( num * mMajorStep);
//VCHECK(static_cast<int>( mMajor->pos() ) - start);
}
}
bool IndefinitIndexBase::master()
{
//assert(not virt());
return mMajor == nullptr;
}
void IndefinitIndexBase::subOrd(IndefinitIndexBase* major)
{
//assert(not virt());
mMajor = major;
mMajorStep = mMajor->giveSubStepSize(this);
}
size_t IndefinitIndexBase::majorStep() const
{
return mMajorStep;
} }
/************** /**************
@ -117,13 +114,6 @@ namespace MultiArrayTools
return mRange->size(); return mRange->size();
} }
template <class Index>
bool IndexBase<Index>::toNull() const
{
//assert(not virt());
return mRange == nullptr;
}
template <class Index> template <class Index>
void IndexBase<Index>::assignRange(RangeBase<Index> const* range) void IndexBase<Index>::assignRange(RangeBase<Index> const* range)
{ {
@ -132,10 +122,4 @@ namespace MultiArrayTools
mRange = range; mRange = range;
} }
} }
template <class Index>
void IndexBase<Index>::eval()
{
setPos( evaluate(*dynamic_cast<Index const*>( this )) );
}
} }

View file

@ -18,7 +18,7 @@ namespace MultiArrayTools
{ {
public: public:
DEFAULT_MEMBERS(IndefinitIndexBase); DEFAULT_MEMBERS(IndefinitIndexBase);
virtual ~IndefinitIndexBase(); virtual ~IndefinitIndexBase() = default;
virtual IndefinitIndexBase& operator=(size_t pos) = 0; virtual IndefinitIndexBase& operator=(size_t pos) = 0;
virtual IndefinitIndexBase& operator++() = 0; virtual IndefinitIndexBase& operator++() = 0;
@ -26,32 +26,26 @@ namespace MultiArrayTools
virtual IndefinitIndexBase& operator+=(int n) = 0; virtual IndefinitIndexBase& operator+=(int n) = 0;
virtual IndefinitIndexBase& operator-=(int n) = 0; virtual IndefinitIndexBase& operator-=(int n) = 0;
// Make this somehow better... !!! bool operator==(const IndefinitIndexBase& i) const;
//virtual bool operator==(const IndefinitIndexBase& i) = 0; bool operator!=(const IndefinitIndexBase& i) const;
//virtual bool operator!=(const IndefinitIndexBase& i) = 0;
virtual size_t dim() const = 0; virtual size_t dim() const = 0;
virtual size_t pos() const; virtual size_t pos() const;
virtual MultiRangeType rangeType() const = 0; virtual MultiRangeType rangeType() const = 0;
virtual void setPos(size_t pos); virtual IndefinitIndexBase& setPos(size_t pos, IndefinitIndexBase* ctrlPtr = nullptr);
virtual void setPosRel(int relPos); virtual IndefinitIndexBase& setPosRel(int relPos, IndefinitIndexBase* ctrlPtr = nullptr);
virtual IndefinitIndexBase& toFirst(); virtual IndefinitIndexBase& toFirst(IndefinitIndexBase* ctrlPtr = nullptr);
virtual IndefinitIndexBase& toLast(); virtual IndefinitIndexBase& toLast(IndefinitIndexBase* ctrlPtr = nullptr);
virtual size_t max() const = 0; virtual size_t max() const = 0;
virtual int outOfRange() const; virtual int outOfRange() const;
virtual bool atEdge() const; virtual bool atEdge() const;
virtual bool toNull() const; virtual bool master() const;
virtual void eval() = 0; virtual IndefinitIndexBase& subOrd(IndefinitIndexBase* major);
virtual void evalMajor();
virtual void evalMajor(int num);
virtual bool master();
virtual void subOrd(IndefinitIndexBase* major);
virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) = 0; virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) = 0;
protected: protected:
@ -72,11 +66,8 @@ namespace MultiArrayTools
//virtual size_t pos() const override; // = mPos; implement !!! //virtual size_t pos() const override; // = mPos; implement !!!
virtual size_t max() const override; virtual size_t max() const override;
virtual bool toNull() const override;
virtual void assignRange(RangeBase<Index> const* range); virtual void assignRange(RangeBase<Index> const* range);
virtual void eval() override;
virtual void copyPos(const Index& in) = 0; virtual void copyPos(const Index& in) = 0;
protected: protected:

View file

@ -291,7 +291,7 @@ namespace MultiArrayTools
{ {
return mNm; return mNm;
} }
template <typename T, class Range> template <typename T, class Range>
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>::operator[](const IndexType& ind) MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>::operator[](const IndexType& ind)
{ {
@ -469,14 +469,15 @@ namespace MultiArrayTools
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() ); mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
mNm = in.name(); mNm = in.name();
mIndex.name(mNm); // to be sure...
typename TotalInRange::IndexType endIndex = mIndex; typename TotalInRange::IndexType endIndex = mIndex;
endIndex.setPos( mIndex.max() ); ++endIndex.toLast();
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl; std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
// !!!!! IndexList il = in.getIndices();
setInternalIndex(il);
in.setInternalIndex(il);
MultiArray<T,TotalRange> cnt(mRoot->range()); MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name()); MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
@ -485,7 +486,6 @@ namespace MultiArrayTools
get() += in.get(); get() += in.get();
cnto.get() += 1.; cnto.get() += 1.;
} }
mRoot.freeIndex();
// CHECK whether T / size_t mixture works!! // CHECK whether T / size_t mixture works!!
mRoot /= cnt(mRoot.name(), true); mRoot /= cnt(mRoot.name(), true);
return *this; return *this;
@ -497,16 +497,17 @@ namespace MultiArrayTools
operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in) operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in)
{ {
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() ); mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
mNm = in.name(); mNm = in.name();
mIndex.name(mNm); // to be sure...
typename TotalInRange::IndexType endIndex = mIndex; typename TotalInRange::IndexType endIndex = mIndex;
++endIndex.toLast(); ++endIndex.toLast();
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl; std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
//!!!!!!! IndexList il = in.getIndices();
setInternalIndex(il);
in.setInternalIndex(il);
MultiArray<T,TotalRange> cnt(mRoot->range()); MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name()); MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
for(mIndex.toFirst(), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){ for(mIndex.toFirst(), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){

View file

@ -13,7 +13,7 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
typedef std::vector<std::shared_ptr<IndefinitIndexBase> > IndexList; typedef std::map<Name,std::shared_ptr<IndefinitIndexBase> > IndexList;
template <typename T> template <typename T>
class MultiArrayOperationBase class MultiArrayOperationBase
@ -29,12 +29,8 @@ namespace MultiArrayTools
const IndefinitIndexBase& index() const = 0; const IndefinitIndexBase& index() const = 0;
virtual const T& get() const = 0; virtual const T& get() const = 0;
virtual IndexList getIndices() const = 0;
virtual void setInternalIndex(const IndexList& il) = 0;
}; };
template <typename T> template <typename T>
class MutableMultiArrayOperationBase : public MultiArrayOperationBase<T> class MutableMultiArrayOperationBase : public MultiArrayOperationBase<T>
{ {
@ -143,7 +139,6 @@ namespace MultiArrayTools
virtual const T& get() const override; virtual const T& get() const override;
const Name& name() const; const Name& name() const;
const MultiArrayBase<T,Range>& getCont() const { return mArrayRef; } const MultiArrayBase<T,Range>& getCont() const { return mArrayRef; }
template <typename U, class RangeX> template <typename U, class RangeX>
@ -216,7 +211,6 @@ namespace MultiArrayTools
virtual const T& get() const override; virtual const T& get() const override;
const Name& name() const; const Name& name() const;
const MultiArrayBase<T,Range>& getCont() const { return mArrayRef; } const MultiArrayBase<T,Range>& getCont() const { return mArrayRef; }
template <typename U, class RangeX> template <typename U, class RangeX>
@ -250,6 +244,7 @@ namespace MultiArrayTools
virtual const T& get() const override; virtual const T& get() const override;
virtual T& get() override; virtual T& get() override;
// !!!! // !!!!
protected: protected:
IndexMapFunction<InRange,OutRange> mMF; IndexMapFunction<InRange,OutRange> mMF;
@ -297,9 +292,8 @@ namespace MultiArrayTools
auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec)); auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec));
virtual size_t argNum() const override; virtual size_t argNum() const override;
virtual const T& get() const override; virtual const T& get() const override;
protected: protected:
mutable T mVal; mutable T mVal;
@ -355,9 +349,8 @@ namespace MultiArrayTools
auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec)); auto operator/(const MAOp2& sec) -> decltype(operator()(std::divides<T>(), sec));
virtual size_t argNum() const override; virtual size_t argNum() const override;
virtual const T& get() const override; virtual const T& get() const override;
protected: protected:
mutable T mVal; mutable T mVal;

View file

@ -77,17 +77,18 @@ namespace MultiArrayTools
template <size_t DIGIT> template <size_t DIGIT>
struct SubIteration struct SubIteration
{ {
// use 'plus' as few as possible !!
template <class MultiIndex> template <class MultiIndex>
static inline void plus(MultiIndex& index, int num) static inline void plus(MultiIndex& index, int num)
{ {
auto& si = index.template getIndex<DIGIT>(); auto& si = index.template getIndex<DIGIT>();
si.setPosRel(num); si.setPosRel(num, &index);
size_t oor = si.outOfRange(); size_t oor = si.outOfRange();
if(oor > 0){ while(oor > 0){
SubIteration<DIGIT-1>::pp(index); SubIteration<DIGIT-1>::pp(index);
SubIteration<DIGIT>::plus(index, -si.max()); SubIteration<DIGIT>::plus(index, -si.max());
} }
else if(oor < 0){ while(oor < 0){
SubIteration<DIGIT-1>::mm(index); SubIteration<DIGIT-1>::mm(index);
SubIteration<DIGIT>::plus(index, si.max()); SubIteration<DIGIT>::plus(index, si.max());
} }
@ -97,13 +98,12 @@ namespace MultiArrayTools
static inline void pp(MultiIndex& index) static inline void pp(MultiIndex& index)
{ {
auto& si = index.template getIndex<DIGIT>(); auto& si = index.template getIndex<DIGIT>();
//IndefinitIndexBase& si = index.get(DIGIT); if(si.pos() == si.atEdge()){
if(si.pos() == si.max()-1){ si.setPos(0, &index);
si.setPos(0);
SubIteration<DIGIT-1>::pp(index); SubIteration<DIGIT-1>::pp(index);
} }
else { else {
si.setPosRel(1); si.setPosRel(1, &index);
} }
} }
@ -111,13 +111,12 @@ namespace MultiArrayTools
static inline void mm(MultiIndex& index) static inline void mm(MultiIndex& index)
{ {
auto& si = index.template getIndex<DIGIT>(); auto& si = index.template getIndex<DIGIT>();
//IndefinitIndexBase& si = index.get(DIGIT); if(si.pos() == si.atEdge()){
if(si.pos() == si.max()-1){ si.setPos(si.atEdge(), &index);
si.setPos(si.max()-1);
SubIteration<DIGIT-1>::mm(index); SubIteration<DIGIT-1>::mm(index);
} }
else { else {
si.setPosRel(1); si.setPosRel(1, &index);
} }
} }
}; };
@ -129,45 +128,21 @@ namespace MultiArrayTools
static inline void plus(MultiIndex& index, int num) static inline void plus(MultiIndex& index, int num)
{ {
auto& si = index.template getIndex<0>(); auto& si = index.template getIndex<0>();
//IndefinitIndexBase& si = index.get(0); si.setPosRel(num, &index);
si.setPosRel(num);
} }
template <class MultiIndex> template <class MultiIndex>
static inline void pp(MultiIndex& index) static inline void pp(MultiIndex& index)
{ {
auto& si = index.template getIndex<0>(); auto& si = index.template getIndex<0>();
//IndefinitIndexBase& si = index.get(0); si.setPosRel(1, &index);
si.setPosRel(1);
} }
template <class MultiIndex> template <class MultiIndex>
static inline void mm(MultiIndex& index) static inline void mm(MultiIndex& index)
{ {
auto& si = index.template getIndex<0>(); auto& si = index.template getIndex<0>();
//IndefinitIndexBase& si = index.get(0); si.setPosRel(-1, &index);
si.setPosRel(-1);
}
};
template <size_t N>
struct TupleNamer
{
template <class IndexPack, class Name>
static void nameTuple(IndexPack& iPack, Name& name)
{
std::get<N>(iPack).name(name.get(N));
TupleNamer<N-1>::nameTuple(iPack, name);
}
};
template <>
struct TupleNamer<0>
{
template <class IndexPack, class Name>
static void nameTuple(IndexPack& iPack, Name& name)
{
std::get<0>(iPack).name(name.get(0));
} }
}; };
@ -415,6 +390,10 @@ namespace MultiArrayTools
IIB::mPos = evaluate(*this); IIB::mPos = evaluate(*this);
} }
template <class... Indices>
MultiIndex<Indices...>::MultiIndex(std::vector<std::shared_ptr<IndefinitIndexBase> >& indexList) :
// !!!!
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++() MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
{ {
@ -464,7 +443,7 @@ namespace MultiArrayTools
} }
template <class... Indices> template <class... Indices>
IndefinitIndexBase& MultiIndex<Indices...>::operator=(size_t pos) MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
{ {
IIB::setPos( pos ); IIB::setPos( pos );
IndexPackSetter<sizeof...(Indices)-1>::setIndexPack(mIPack, pos); IndexPackSetter<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
@ -484,20 +463,6 @@ namespace MultiArrayTools
return res; return res;
} }
template <class... Indices>
void MultiIndex<Indices...>::name(const Name& nm)
{
IIB::mName = nm.own();
if(nm.size() >= sizeof...(Indices)){
TupleNamer<sizeof...(Indices)-1>::nameTuple(mIPack, nm);
}
else {
Name nm2 = nm;
nm2.autoName(sizeof...(Indices));
TupleNamer<sizeof...(Indices)-1>::nameTuple(mIPack, nm2);
}
}
template <class... Indices> template <class... Indices>
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(Indices&&... inds) MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(Indices&&... inds)
{ {
@ -602,7 +567,7 @@ namespace MultiArrayTools
return 0; return 0;
} }
} }
template <size_t N> template <size_t N>
struct TuplePrinter struct TuplePrinter
{ {
@ -685,6 +650,15 @@ namespace MultiArrayTools
IndexSetter<sizeof...(Ranges)-1>::setEnd(is,mSpace); IndexSetter<sizeof...(Ranges)-1>::setEnd(is,mSpace);
return ++MultiIndex<typename Ranges::IndexType...>(this, is); return ++MultiIndex<typename Ranges::IndexType...>(this, is);
} }
template <class... Ranges>
std::shared_ptr<IndefinitIndexBase> MultiRange<Ranges...>::indexInstance() const
{
std::tuple<std::shared_ptr<typename Ranges::IndexType>...> is;
IndexSetter<sizeof...(Ranges)-1>::setBegin(is,mSpace);
std::shared_ptr<IndefinitIndexBase> sptr(new MultiIndex<typename Ranges::IndexType...>(this, is));
return sptr;
}
} }
template <typename... Ts> template <typename... Ts>

View file

@ -46,8 +46,8 @@ namespace MultiArrayTools
MultiIndex(RangeBase<MultiIndex<std::shared_ptr<Indices>...> > const* range, MultiIndex(RangeBase<MultiIndex<std::shared_ptr<Indices>...> > const* range,
const IndexPack& ipack); const IndexPack& ipack);
//virtual ~MultiIndex(); MultiIndex(std::vector<std::shared_ptr<IndefinitIndexBase> >& indexList);
virtual MultiIndex& operator++() override; virtual MultiIndex& operator++() override;
virtual MultiIndex& operator--() override; virtual MultiIndex& operator--() override;
@ -57,15 +57,15 @@ namespace MultiArrayTools
bool operator==(const MultiIndex& in); bool operator==(const MultiIndex& in);
bool operator!=(const MultiIndex& in); bool operator!=(const MultiIndex& in);
virtual IIB& operator=(size_t pos) override; virtual MultiIndex& operator=(size_t pos) override;
virtual MultiRangeType rangeType() const override; virtual MultiRangeType rangeType() const override;
template <size_t N> template <size_t N>
auto getIndex() ->; auto getIndex() -> decltype(*std::get<N>(mIPack))&;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Indices>...> >::type& getIndex(); //typename std::tuple_element<N, std::tuple<std::shared_ptr<Indices>...> >::type& getIndex();
template <size_t N> template <size_t N>
auto getIndex() const ->; auto getIndex() const -> decltype(*std::get<N>(mIPack))&;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Indices>...> >::type const& getIndex() const; //typename std::tuple_element<N, std::tuple<std::shared_ptr<Indices>...> >::type const& getIndex() const;
IndefinitIndexBase& get(size_t n); IndefinitIndexBase& get(size_t n);
@ -77,18 +77,9 @@ namespace MultiArrayTools
MultiIndex& operator()(Indices&&... inds); MultiIndex& operator()(Indices&&... inds);
MultiIndex& operator()(const Indices&... inds); MultiIndex& operator()(const Indices&... inds);
virtual void name(const Name& nm) override;
// dimension of MultiRange; includes ALL degrees of freedom // dimension of MultiRange; includes ALL degrees of freedom
virtual size_t dim() const override; virtual size_t dim() const override;
virtual void copyPos(const MultiIndex<std::shared_ptr<Indices>...>& in) override;
virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) override; virtual size_t giveSubStepSize(IndefinitIndexBase* subIndex) override;
//virtual void eval() override;
//virtual bool virt() const override { return false; }
//virtual void assignRange(RangeBase<MultiIndex<Indices...> > const* range) override;
}; };
/***************************** /*****************************
@ -111,7 +102,7 @@ namespace MultiArrayTools
MultiRange(const SpaceType& space); MultiRange(const SpaceType& space);
static const size_t dim = sizeof...(Ranges); static const size_t dim = sizeof...(Ranges);
template <size_t N> // !!! return ref to range, not the corresp. shared ptr template <size_t N> // !!! return ref to range, not the corresp. shared ptr
auto getRange() -> ; auto getRange() -> ;
//typename std::tuple_element<N, std::tuple<std::shared_ptr<Ranges>...> >::type& getRange(); //typename std::tuple_element<N, std::tuple<std::shared_ptr<Ranges>...> >::type& getRange();
@ -127,6 +118,8 @@ namespace MultiArrayTools
virtual MultiIndex<typename Ranges::IndexType...> begin() const override; virtual MultiIndex<typename Ranges::IndexType...> begin() const override;
virtual MultiIndex<typename Ranges::IndexType...> end() const override; virtual MultiIndex<typename Ranges::IndexType...> end() const override;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const override;
protected: protected:
SpaceType mSpace; SpaceType mSpace;

View file

@ -112,6 +112,11 @@ namespace MultiArrayTools
{ {
return true; return true;
} }
template <class Index>
RangeBase<Index>* SubRangeBase<Index>::base()
{
return mBase;
}
} }

View file

@ -55,20 +55,30 @@ namespace MultiArrayTools
std::vector<MultiRangeType>* mMultiType; std::vector<MultiRangeType>* mMultiType;
}; };
class IndefinitRangeBase
{
public:
virtual ~IndefinitRangeBase() = default;
virtual size_t size() const = 0;
virtual bool isSubRange() const = 0;
virtual MultiRangeType type() const = 0;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const = 0;
protected:
DEFAULT_MEMBERS(RangeBase);
};
template <class Index> template <class Index>
class RangeBase class RangeBase : public IndefinitRangeBase
{ {
public: public:
typedef Index IndexType; typedef Index IndexType;
virtual ~RangeBase() = default;
virtual size_t size() const = 0;
virtual Index begin() const = 0; virtual Index begin() const = 0;
virtual Index end() const = 0; virtual Index end() const = 0;
virtual RangeBase<Index>* base(); virtual RangeBase<Index>* base();
virtual bool isSubRange() const; virtual bool isSubRange() const override;
virtual MultiRangeType type() const = 0;
protected: protected:
DEFAULT_MEMBERS(RangeBase); DEFAULT_MEMBERS(RangeBase);