+anonymous range

This commit is contained in:
Christian Zimmermann 2017-05-31 16:44:28 +02:00
parent 2a627a7ab3
commit 370dc2efee
7 changed files with 53 additions and 31 deletions

13
src/anonymous_range.cc Normal file
View file

@ -0,0 +1,13 @@
// -*- C++ -*-
#include "anonymous_range.h"
namespace MultiArrayTools
{
}

23
src/anonymous_range.h Normal file
View file

@ -0,0 +1,23 @@
// -*- C++ -*-
#ifndef __anonymous_range_h__
#define __anonymous_range_h__
#include <cstdlib>
#include "base_def.h"
namespace MultiArrayTools
{
typedef SingleIndex<size_t,NONE> AnonymousIndex;
class AnonymousRange : public RangeBase<AnonymousIndex>
{
};
}
#include "anonymous_range.cc"
#endif

View file

@ -13,12 +13,12 @@ namespace MultiArrayTools
return static_cast<size_t>( mPos ); return static_cast<size_t>( mPos );
} }
bool IndefinitIndexBase::operator==(const IndefinitIndexBase& i) const bool IndefinitIndexBase::operator==(const IndefinitIndexBase& in) const
{ {
return rangeType() == in.rangeType() and pos() == in.pos(); return rangeType() == in.rangeType() and pos() == in.pos();
} }
bool IndefinitIndexBase::operator!=(const IndefinitIndexBase& i) const bool IndefinitIndexBase::operator!=(const IndefinitIndexBase& in) const
{ {
return rangeType() != in.rangeType() or pos() != in.pos(); return rangeType() != in.rangeType() or pos() != in.pos();
} }
@ -84,9 +84,9 @@ namespace MultiArrayTools
} }
} }
bool atEdge() const bool IndefinitIndexBase::atEdge() const
{ {
return mPos == max(); return static_cast<size_t>( mPos ) == max();
} }
bool IndefinitIndexBase::master() const bool IndefinitIndexBase::master() const
@ -105,7 +105,7 @@ namespace MultiArrayTools
**************/ **************/
template <class Index> template <class Index>
IndexBase<Index>::IndexBase(RangeBase<Index> const* range) : mRange(range) {} IndexBase<Index>::IndexBase(std::shared_ptr<const RangeBase<Index> >& rangePtr) : mRangePtr(rangePtr) {}
template <class Index> template <class Index>
size_t IndexBase<Index>::max() const size_t IndexBase<Index>::max() const
@ -113,13 +113,4 @@ namespace MultiArrayTools
//assert(not virt()); //assert(not virt());
return mRange->size(); return mRange->size();
} }
template <class Index>
void IndexBase<Index>::assignRange(RangeBase<Index> const* range)
{
//assert(not virt());
if(toNull()){
mRange = range;
}
}
} }

View file

@ -26,8 +26,8 @@ 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;
bool operator==(const IndefinitIndexBase& i) const; bool operator==(const IndefinitIndexBase& in) const;
bool operator!=(const IndefinitIndexBase& i) const; bool operator!=(const IndefinitIndexBase& in) const;
virtual size_t dim() const = 0; virtual size_t dim() const = 0;
virtual size_t pos() const; virtual size_t pos() const;
@ -62,19 +62,17 @@ namespace MultiArrayTools
typedef IndefinitIndexBase IIB; typedef IndefinitIndexBase IIB;
DEFAULT_MEMBERS(IndexBase); DEFAULT_MEMBERS(IndexBase);
IndexBase(RangeBase<Index> const* range); IndexBase(std::shared_ptr<const RangeBase<Index> >& rangePtr);
//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 void assignRange(RangeBase<Index> const* range);
virtual void copyPos(const Index& in) = 0; virtual void copyPos(const Index& in) = 0;
protected: protected:
// translate index into position // translate index into position
virtual size_t evaluate(const Index& in) const = 0; virtual size_t evaluate(const Index& in) const = 0;
RangeBase<Index> const* mRange; std::shared_ptr<const RangeBase<Index> > mRangePtr;
}; };
} }

View file

@ -58,15 +58,15 @@ namespace MultiArrayTools
class IndefinitRangeBase class IndefinitRangeBase
{ {
public: public:
virtual ~IndefinitRangeBase() = default; virtual ~IndefinitRangeBase() = default;
static std::shared_ptr<IndefinitRangeBase> makeInstance(const MultiRangeType& mrt); // !!!
virtual size_t size() const = 0; virtual size_t size() const = 0;
virtual bool isSubRange() const = 0; virtual bool isSubRange() const = 0;
virtual MultiRangeType type() const = 0; virtual MultiRangeType type() const = 0;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const = 0; virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const = 0;
protected:
DEFAULT_MEMBERS(RangeBase);
}; };
template <class Index> template <class Index>
@ -75,14 +75,12 @@ namespace MultiArrayTools
public: public:
typedef Index IndexType; typedef Index IndexType;
virtual Index begin() const = 0; virtual IndexType begin() const = 0;
virtual Index end() const = 0; virtual IndexType end() const = 0;
virtual RangeBase<Index>* base(); virtual RangeBase<Index>* base();
virtual bool isSubRange() const override; virtual bool isSubRange() const override;
protected: virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const override;
DEFAULT_MEMBERS(RangeBase);
}; };
//template <class Range> //template <class Range>
@ -96,6 +94,7 @@ namespace MultiArrayTools
{ {
public: public:
virtual bool isSubRange() const override; virtual bool isSubRange() const override;
virtual RangeBase<Index>* base() override;
protected: protected:
DEFAULT_MEMBERS(SubRangeBase); DEFAULT_MEMBERS(SubRangeBase);
RangeBase<Index>* mBase; RangeBase<Index>* mBase;

View file

@ -1 +0,0 @@
// -*- C++ -*-

View file

@ -1 +0,0 @@
// -*- C++ -*-