index linkage

This commit is contained in:
Christian Zimmermann 2017-02-15 11:26:47 +01:00
parent 3363671d35
commit d4f8402f29
2 changed files with 58 additions and 25 deletions

View file

@ -36,6 +36,26 @@ namespace ME
return mType != nullptr; 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) void MultiRangeType::setType(RangeType type)
{ {
mType = type; mType = type;
@ -100,23 +120,21 @@ namespace ME
bool IndefinitIndexBase::link(IndefinitIndexBase* toLink) bool IndefinitIndexBase::link(IndefinitIndexBase* toLink)
{ {
if(toLink->name() == name() and toLink->rangeType() == rangeType()){ if(toLink->rangeType() != rangeType() and toLink->name() == name()){
bool isAlready = false; // throw !!
if(mLinked != nullptr){
for(auto& x: *mLinked){
if(x == toLink){
isAlready = true;
break;
} }
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 { else {
mLinked = new std::vector<IndefinitIndexBase*>(); return mLinked->link(toLink);
} }
if(not isAlready){
mLinked->push_back(toLink);
}
return true;
} }
else { else {
return false; return false;
@ -125,10 +143,22 @@ namespace ME
void IndefinitIndexBase::freeLinked() void IndefinitIndexBase::freeLinked()
{ {
delete mLinked;
mLinked = nullptr; mLinked = nullptr;
} }
bool IndefinitIndexBase::linked() const
{
return mLinked != nullptr;
}
void IndefinitIndexBase::setPos(size_t pos)
{
mPos = pos;
if(linked()){
mLinked->setPos(pos);
}
}
/************** /**************
* IndexBase * * IndexBase *
**************/ **************/
@ -136,41 +166,41 @@ namespace ME
template <class Index> template <class Index>
Index& IndexBase<Index>::operator=(const Index& in) Index& IndexBase<Index>::operator=(const Index& in)
{ {
mPos = evaluate(in); setPos( evaluate(in) );
} }
template <class Index> template <class Index>
Index& IndexBase<Index>::operator=(size_t pos) Index& IndexBase<Index>::operator=(size_t pos)
{ {
mPos = pos; setPos( pos );
return *this; return *this;
} }
template <class Index> template <class Index>
Index& IndexBase<Index>::operator++() Index& IndexBase<Index>::operator++()
{ {
++mPos; setPos( ++mPos );
return *this; return *this;
} }
template <class Index> template <class Index>
Index& IndexBase<Index>::operator--() Index& IndexBase<Index>::operator--()
{ {
--mPos; setPos( --mPos );
return *this; return *this;
} }
template <class Index> template <class Index>
Index& IndexBase<Index>::operator+=(int n) Index& IndexBase<Index>::operator+=(int n)
{ {
mPos += n; setPos( mPos += n );
return *this; return *this;
} }
template <class Index> template <class Index>
Index& IndexBase<Index>::operator-=(int n) Index& IndexBase<Index>::operator-=(int n)
{ {
mPos -= n; setPos( mPos -= n );
return *this; return *this;
} }

View file

@ -78,6 +78,9 @@ namespace ME
bool multi() const; bool multi() const;
bool operator==(const MultiRangeType& in) const;
bool operator!=(const MultiRangeType& in) const;
private: private:
void setType(RangeType type); void setType(RangeType type);
void setMultiType(const std::vector<MultiRangeType>& multiType); void setMultiType(const std::vector<MultiRangeType>& multiType);
@ -175,16 +178,16 @@ namespace ME
virtual bool link(IndefinitIndexBase* toLink); virtual bool link(IndefinitIndexBase* toLink);
virtual void freeLinked(); virtual void freeLinked();
virtual bool linked() const;
virtual void setPos(size_t pos);
protected: protected:
std::string mName; std::string mName;
size_t mPos; size_t mPos;
// => change: if two should be linked, link the second in *mLinked IndefinitIndexBase* mLinked;
// and so on for even more Indices
// IndefinitIndexBase* mLinked;
std::vector<IndefinitIndexBase*>* mLinked; // if *this modified, modify mLinked the same way
}; };
template <class Index> template <class Index>