diff --git a/src/multi_range.h b/src/multi_range.h index 3770262..b877d3f 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -95,12 +95,7 @@ namespace MultiArrayTools typedef std::tuple...> SpaceType; typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(MultiRange); - MultiRange(const std::shared_ptr&... rs); - MultiRange(const SpaceType& space); - static const size_t dim = sizeof...(Ranges); template // !!! return ref to range, not the corresp. shared ptr @@ -122,6 +117,14 @@ namespace MultiArrayTools virtual std::shared_ptr indexInstance() const override; protected: + + MultiRange() = delete; + MultiRange(const MultiRange& in) = delete; + MultiRange& operator=(const MultiRange& in) = delete; + + MultiRange(const std::shared_ptr&... rs); + MultiRange(const SpaceType& space); + SpaceType mSpace; }; diff --git a/src/range_base.cc b/src/range_base.cc index b88d57a..cbeddff 100644 --- a/src/range_base.cc +++ b/src/range_base.cc @@ -86,6 +86,7 @@ namespace MultiArrayTools mMultiType = new std::vector( multiType ); mType = RangeType::NIL; } + /****************** * RangeBase * diff --git a/src/range_base.h b/src/range_base.h index 8b6ad7a..459c4dc 100644 --- a/src/range_base.h +++ b/src/range_base.h @@ -61,12 +61,17 @@ namespace MultiArrayTools 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: + // only constructable via Factory + + IndefinitRangeBase() = default; + IndefinitRangeBase(const IndefinitRangeBase& in) = delete; + IndefinitRangeBase& operator=(const IndefinitRangeBase& in) = delete; }; template @@ -81,6 +86,11 @@ namespace MultiArrayTools virtual bool isSubRange() const override; virtual std::shared_ptr indexInstance() const override; + + protected: + RangeBase() = default; + RangeBase(const RangeBase& in) = delete; + RangeBase& operator=(const RangeBase& in) = delete; }; //template diff --git a/src/range_factory.cc b/src/range_factory.cc new file mode 100644 index 0000000..4ab5e40 --- /dev/null +++ b/src/range_factory.cc @@ -0,0 +1,8 @@ +// -*- C++ -*- + +#include "range_factory.h" + +namespace MultiArrayTools +{ + +} //namespace MultiArrayTools diff --git a/src/range_factory.h b/src/range_factory.h new file mode 100644 index 0000000..daca600 --- /dev/null +++ b/src/range_factory.h @@ -0,0 +1,26 @@ +// -*- C++ -*- + +#ifndef __range_factory_h__ +#define __range_factory_h__ + +#include +#include +#include "base_def.h" + +namespace MultiArrayTools +{ + + class RangeFactoryBase + { + public: + DEFAULT_MEMBERS(RangeFactoryBase); + virtual std::shared_ptr create() const = 0; + + }; + + +} //namespace MultiArrayTools + +#include "range_factory.cc" + +#endif diff --git a/src/single_range.cc b/src/single_range.cc index 3a328ec..13235b8 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -3,6 +3,134 @@ namespace MultiArrayTools { + /****************** + * SingleIndex * + ******************/ + + template + SingleIndex::SingleIndex(const U& upos, + std::shared_ptr > >& rangePtr) : + IndexBase >(rangePtr) + { + IIB::setPos( dynamic_pointer_cast >( IB::mRangePtr )->get(upos) ); + } + + template + SingleIndex::SingleIndex(std::shared_ptr > >& rangePtr, + size_t pos) : IndexBase >(range) + { + IIB::setPos( pos ); + } + + template + SingleIndex& SingleIndex::operator=(size_t pos) + { + IIB::setPos( pos ); + return *this; + } + + template + SingleIndex& SingleIndex::operator++() + { + IIB::setPos( IIB::pos() + 1 ); + return *this; + } + + template + SingleIndex& SingleIndex::operator--() + { + IIB::setPos( IIB::pos() - 1 ); + return *this; + } + + template + SingleIndex& SingleIndex::operator+=(int n) + { + IIB::setPos( IIB::pos() + n ); + return *this; + } + + template + SingleIndex& SingleIndex::operator-=(int n) + { + IIB::setPos( IIB::pos() - n ); + return *this; + } + + template + bool SingleIndex::operator==(const SingleIndex& i) + { + return IB::mRange == i.mRange and IIB::pos() == static_cast( i.mPos ); + } + + template + bool SingleIndex::operator!=(const SingleIndex& i) + { + return IB::mRange != i.mRange or IIB::pos() != static_cast( i.mPos ); + } + + template + MultiRangeType SingleIndex::rangeType() const + { + return MultiRangeType(TYPE); + } + + template + U SingleIndex::getMetaPos() const + { + return dynamic_cast const*>( IB::mRange )->get(IIB::pos()); + } + + template + SingleIndex& SingleIndex::atMeta(const U& metaPos) + { + operator=( dynamic_cast const*>( IB::mRange )->getMeta(metaPos) ); + return *this; + } + + template + size_t SingleIndex::dim() const + { + return 1; + } + + template + size_t SingleIndex::evaluate(const SingleIndex& in) const + { + return in.pos(); + } + + template + void SingleIndex::copyPos(const SingleIndex& in) + { + IIB::setPos(in.pos()); + } + + template + size_t SingleIndex::giveSubStepSize(IndefinitIndexBase* subIndex) + { + if(subIndex == this){ + return 1; + } + else { + return 0; + } + } + + std::ostream& operator<<(std::ostream& os, VET vet) + { + os << ( (vet == VET::VALUE) ? std::string("VALUE") : std::string("ERROR") ); + return os; + } + + /* + template + void SingleIndex::eval() + { + IIB::setPos( evaluate( *this ) ); + } + */ + /******************** * SingleRange * ********************/ @@ -251,130 +379,4 @@ namespace MultiArrayTools return SingleIndex(this, size()); } - /****************** - * SingleIndex * - ******************/ - - template - SingleIndex::SingleIndex(RangeBase > const* range, - const U& upos, size_t disambig) : IndexBase >(range) - { - IIB::setPos( dynamic_cast const*>( IB::mRange )->get(upos) ); - } - - template - SingleIndex::SingleIndex(RangeBase > const* range, - size_t pos) : IndexBase >(range) - { - IIB::setPos( pos ); - } - - template - SingleIndex& SingleIndex::operator=(size_t pos) - { - IIB::setPos( pos ); - return *this; - } - - template - SingleIndex& SingleIndex::operator++() - { - IIB::setPos( IIB::pos() + 1 ); - return *this; - } - - template - SingleIndex& SingleIndex::operator--() - { - IIB::setPos( IIB::pos() - 1 ); - return *this; - } - - template - SingleIndex& SingleIndex::operator+=(int n) - { - IIB::setPos( IIB::pos() + n ); - return *this; - } - - template - SingleIndex& SingleIndex::operator-=(int n) - { - IIB::setPos( IIB::pos() - n ); - return *this; - } - - template - bool SingleIndex::operator==(const SingleIndex& i) - { - return IB::mRange == i.mRange and IIB::pos() == static_cast( i.mPos ); - } - - template - bool SingleIndex::operator!=(const SingleIndex& i) - { - return IB::mRange != i.mRange or IIB::pos() != static_cast( i.mPos ); - } - - template - MultiRangeType SingleIndex::rangeType() const - { - return MultiRangeType(TYPE); - } - - template - U SingleIndex::getMetaPos() const - { - return dynamic_cast const*>( IB::mRange )->get(IIB::pos()); - } - - template - SingleIndex& SingleIndex::atMeta(const U& metaPos) - { - operator=( dynamic_cast const*>( IB::mRange )->getMeta(metaPos) ); - return *this; - } - - template - size_t SingleIndex::dim() const - { - return 1; - } - - template - size_t SingleIndex::evaluate(const SingleIndex& in) const - { - return in.pos(); - } - - template - void SingleIndex::copyPos(const SingleIndex& in) - { - IIB::setPos(in.pos()); - } - - template - size_t SingleIndex::giveSubStepSize(IndefinitIndexBase* subIndex) - { - if(subIndex == this){ - return 1; - } - else { - return 0; - } - } - - std::ostream& operator<<(std::ostream& os, VET vet) - { - os << ( (vet == VET::VALUE) ? std::string("VALUE") : std::string("ERROR") ); - return os; - } - - /* - template - void SingleIndex::eval() - { - IIB::setPos( evaluate( *this ) ); - } - */ } diff --git a/src/single_range.h b/src/single_range.h index 5ac2ea4..cbc5c34 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -5,6 +5,7 @@ #include #include +#include #include "base_def.h" #include "index_base.h" @@ -23,12 +24,10 @@ namespace MultiArrayTools DEFAULT_MEMBERS(SingleIndex); - // find better solution !!! - SingleIndex(RangeBase > const* range, - const U& upos, size_t disambig); + SingleIndex(const U& upos, std::shared_ptr > >& rangePtr); - SingleIndex(RangeBase > const* range, - size_t pos); + SingleIndex(std::shared_ptr > >& rangePtr, + size_t pos = 0); //virtual SingleIndex& operator=(const U& upos); @@ -63,10 +62,6 @@ namespace MultiArrayTools { public: typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(SingleRange); - - SingleRange(const std::vector& space); static SingleRange oType() { return SingleRange(); } @@ -82,6 +77,9 @@ namespace MultiArrayTools SingleIndex end() const override; protected: + + SingleRange(const std::vector& space); + std::vector mSpace; }; @@ -92,10 +90,6 @@ namespace MultiArrayTools { public: typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(SingleRange); - - SingleRange(size_t ext); static SingleRange oType() { return SingleRange(); } @@ -110,6 +104,9 @@ namespace MultiArrayTools SingleIndex end() const override; protected: + + SingleRange(size_t ext); + size_t mExt; }; @@ -118,10 +115,6 @@ namespace MultiArrayTools { public: typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(SingleRange); - - SingleRange(size_t ext); static SingleRange oType() { return SingleRange(); } @@ -136,6 +129,9 @@ namespace MultiArrayTools SingleIndex end() const override; protected: + + SingleRange(size_t ext); + size_t mExt; }; @@ -144,10 +140,6 @@ namespace MultiArrayTools { public: typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(SingleRange); - - SingleRange(size_t num); static SingleRange oType() { return SingleRange(); } @@ -162,6 +154,9 @@ namespace MultiArrayTools SingleIndex end() const override; protected: + + SingleRange(size_t num); + size_t mNum; }; @@ -178,8 +173,6 @@ namespace MultiArrayTools { public: typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(SingleRange); static SingleRange oType() { return SingleRange(); } @@ -200,8 +193,6 @@ namespace MultiArrayTools { public: typedef typename RangeBase >::IndexType IndexType; - - DEFAULT_MEMBERS(SingleRange); static SingleRange oType() { return SingleRange(); }