From 370dc2efee4ea89bee0f1c9cd943f127bcf4a419 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 31 May 2017 16:44:28 +0200 Subject: [PATCH] +anonymous range --- src/anonymous_range.cc | 13 +++++++++++++ src/anonymous_range.h | 23 +++++++++++++++++++++++ src/index_base.cc | 19 +++++-------------- src/index_base.h | 10 ++++------ src/range_base.h | 17 ++++++++--------- src/range_factory.cc | 1 - src/range_factory.h | 1 - 7 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 src/anonymous_range.cc create mode 100644 src/anonymous_range.h delete mode 100644 src/range_factory.cc delete mode 100644 src/range_factory.h diff --git a/src/anonymous_range.cc b/src/anonymous_range.cc new file mode 100644 index 0000000..9363cdc --- /dev/null +++ b/src/anonymous_range.cc @@ -0,0 +1,13 @@ +// -*- C++ -*- + +#include "anonymous_range.h" + +namespace MultiArrayTools +{ + + + + + + +} diff --git a/src/anonymous_range.h b/src/anonymous_range.h new file mode 100644 index 0000000..efe21c2 --- /dev/null +++ b/src/anonymous_range.h @@ -0,0 +1,23 @@ +// -*- C++ -*- + +#ifndef __anonymous_range_h__ +#define __anonymous_range_h__ + +#include +#include "base_def.h" + +namespace MultiArrayTools +{ + + typedef SingleIndex AnonymousIndex; + + class AnonymousRange : public RangeBase + { + + }; + +} + +#include "anonymous_range.cc" + +#endif diff --git a/src/index_base.cc b/src/index_base.cc index d530340..cb72e46 100644 --- a/src/index_base.cc +++ b/src/index_base.cc @@ -13,12 +13,12 @@ namespace MultiArrayTools return static_cast( mPos ); } - bool IndefinitIndexBase::operator==(const IndefinitIndexBase& i) const + bool IndefinitIndexBase::operator==(const IndefinitIndexBase& in) const { 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(); } @@ -84,9 +84,9 @@ namespace MultiArrayTools } } - bool atEdge() const + bool IndefinitIndexBase::atEdge() const { - return mPos == max(); + return static_cast( mPos ) == max(); } bool IndefinitIndexBase::master() const @@ -105,7 +105,7 @@ namespace MultiArrayTools **************/ template - IndexBase::IndexBase(RangeBase const* range) : mRange(range) {} + IndexBase::IndexBase(std::shared_ptr >& rangePtr) : mRangePtr(rangePtr) {} template size_t IndexBase::max() const @@ -113,13 +113,4 @@ namespace MultiArrayTools //assert(not virt()); return mRange->size(); } - - template - void IndexBase::assignRange(RangeBase const* range) - { - //assert(not virt()); - if(toNull()){ - mRange = range; - } - } } diff --git a/src/index_base.h b/src/index_base.h index bd9676f..fcd4c30 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -26,8 +26,8 @@ namespace MultiArrayTools virtual IndefinitIndexBase& operator+=(int n) = 0; virtual IndefinitIndexBase& operator-=(int n) = 0; - bool operator==(const IndefinitIndexBase& i) const; - bool operator!=(const IndefinitIndexBase& i) const; + bool operator==(const IndefinitIndexBase& in) const; + bool operator!=(const IndefinitIndexBase& in) const; virtual size_t dim() const = 0; virtual size_t pos() const; @@ -62,19 +62,17 @@ namespace MultiArrayTools typedef IndefinitIndexBase IIB; DEFAULT_MEMBERS(IndexBase); - IndexBase(RangeBase const* range); + IndexBase(std::shared_ptr >& rangePtr); //virtual size_t pos() const override; // = mPos; implement !!! virtual size_t max() const override; - - virtual void assignRange(RangeBase const* range); virtual void copyPos(const Index& in) = 0; protected: // translate index into position virtual size_t evaluate(const Index& in) const = 0; - RangeBase const* mRange; + std::shared_ptr > mRangePtr; }; } diff --git a/src/range_base.h b/src/range_base.h index 6774a99..8b6ad7a 100644 --- a/src/range_base.h +++ b/src/range_base.h @@ -58,15 +58,15 @@ namespace MultiArrayTools class IndefinitRangeBase { public: + virtual ~IndefinitRangeBase() = default; + static std::shared_ptr makeInstance(const MultiRangeType& mrt); // !!! + virtual size_t size() const = 0; virtual bool isSubRange() const = 0; virtual MultiRangeType type() const = 0; virtual std::shared_ptr indexInstance() const = 0; - - protected: - DEFAULT_MEMBERS(RangeBase); }; template @@ -75,14 +75,12 @@ namespace MultiArrayTools public: typedef Index IndexType; - virtual Index begin() const = 0; - virtual Index end() const = 0; + virtual IndexType begin() const = 0; + virtual IndexType end() const = 0; virtual RangeBase* base(); virtual bool isSubRange() const override; - - protected: - DEFAULT_MEMBERS(RangeBase); - + + virtual std::shared_ptr indexInstance() const override; }; //template @@ -96,6 +94,7 @@ namespace MultiArrayTools { public: virtual bool isSubRange() const override; + virtual RangeBase* base() override; protected: DEFAULT_MEMBERS(SubRangeBase); RangeBase* mBase; diff --git a/src/range_factory.cc b/src/range_factory.cc deleted file mode 100644 index 4c58044..0000000 --- a/src/range_factory.cc +++ /dev/null @@ -1 +0,0 @@ -// -*- C++ -*- diff --git a/src/range_factory.h b/src/range_factory.h deleted file mode 100644 index 4c58044..0000000 --- a/src/range_factory.h +++ /dev/null @@ -1 +0,0 @@ -// -*- C++ -*-