diff --git a/src/me.cc b/src/me.cc index 49c12d1..6399ba7 100644 --- a/src/me.cc +++ b/src/me.cc @@ -35,6 +35,26 @@ namespace ME { return mType != nullptr; } + + bool MultiRangeType::operator==(const MultiRangeType& in) const + { + if(multi()){ + return *mMultiType == *in.mMultiType; + } + else { + return mType == in.mType; + } + } + + bool MultiRangeType::operator!=(const MultiRangeType& in) const + { + if(multi()){ + return *mMultiType != *in.mMultiType; + } + else { + return mType != in.mType; + } + } void MultiRangeType::setType(RangeType type) { @@ -100,23 +120,21 @@ namespace ME bool IndefinitIndexBase::link(IndefinitIndexBase* toLink) { - if(toLink->name() == name() and toLink->rangeType() == rangeType()){ - bool isAlready = false; - if(mLinked != nullptr){ - for(auto& x: *mLinked){ - if(x == toLink){ - isAlready = true; - break; - } - } + if(toLink->rangeType() != rangeType() and toLink->name() == name()){ + // 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 { - mLinked = new std::vector(); + return mLinked->link(toLink); } - if(not isAlready){ - mLinked->push_back(toLink); - } - return true; } else { return false; @@ -125,9 +143,21 @@ namespace ME void IndefinitIndexBase::freeLinked() { - delete mLinked; mLinked = nullptr; } + + bool IndefinitIndexBase::linked() const + { + return mLinked != nullptr; + } + + void IndefinitIndexBase::setPos(size_t pos) + { + mPos = pos; + if(linked()){ + mLinked->setPos(pos); + } + } /************** * IndexBase * @@ -136,41 +166,41 @@ namespace ME template Index& IndexBase::operator=(const Index& in) { - mPos = evaluate(in); + setPos( evaluate(in) ); } template Index& IndexBase::operator=(size_t pos) { - mPos = pos; + setPos( pos ); return *this; } template Index& IndexBase::operator++() { - ++mPos; + setPos( ++mPos ); return *this; } template Index& IndexBase::operator--() { - --mPos; + setPos( --mPos ); return *this; } template Index& IndexBase::operator+=(int n) { - mPos += n; + setPos( mPos += n ); return *this; } template Index& IndexBase::operator-=(int n) { - mPos -= n; + setPos( mPos -= n ); return *this; } diff --git a/src/me.h b/src/me.h index a5a95a9..03462c9 100644 --- a/src/me.h +++ b/src/me.h @@ -77,6 +77,9 @@ namespace ME const MultiRangeType& operator[](size_t num) const; bool multi() const; + + bool operator==(const MultiRangeType& in) const; + bool operator!=(const MultiRangeType& in) const; private: void setType(RangeType type); @@ -175,16 +178,16 @@ namespace ME virtual bool link(IndefinitIndexBase* toLink); virtual void freeLinked(); + virtual bool linked() const; + virtual void setPos(size_t pos); + protected: std::string mName; size_t mPos; - // => change: if two should be linked, link the second in *mLinked - // and so on for even more Indices - // IndefinitIndexBase* mLinked; - std::vector* mLinked; // if *this modified, modify mLinked the same way + IndefinitIndexBase* mLinked; }; template