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

@ -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<IndefinitIndexBase*>();
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 <class Index>
Index& IndexBase<Index>::operator=(const Index& in)
{
mPos = evaluate(in);
setPos( evaluate(in) );
}
template <class Index>
Index& IndexBase<Index>::operator=(size_t pos)
{
mPos = pos;
setPos( pos );
return *this;
}
template <class Index>
Index& IndexBase<Index>::operator++()
{
++mPos;
setPos( ++mPos );
return *this;
}
template <class Index>
Index& IndexBase<Index>::operator--()
{
--mPos;
setPos( --mPos );
return *this;
}
template <class Index>
Index& IndexBase<Index>::operator+=(int n)
{
mPos += n;
setPos( mPos += n );
return *this;
}
template <class Index>
Index& IndexBase<Index>::operator-=(int n)
{
mPos -= n;
setPos( mPos -= n );
return *this;
}

View file

@ -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<IndefinitIndexBase*>* mLinked; // if *this modified, modify mLinked the same way
IndefinitIndexBase* mLinked;
};
template <class Index>