3434
3535#include < Dataflow/Network/Port.h>
3636#include < Core/Utils/Exception.h>
37- // #include <iostream>
3837
3938#include < boost/range/adaptors.hpp>
4039#include < boost/range/algorithm/copy.hpp>
@@ -111,19 +110,19 @@ PortManager<T>::add(const T& item)
111110 {
112111 // std::cout << "\t id " << portPair.second->id().toString() << " index before setting " << portPair.second->getIndex() << std::endl;
113112 if (portPair.second ->getIndex () >= newPortIndex)
114- portPair.second ->setIndex (portPair. second -> getIndex () + 1 );
113+ portPair.second ->incrementIndex ( );
115114 }
116115
117116 // for (const auto& portPair : ports_)
118117 // {
119- // std::cout << "\t id " << portPair.second->id().toString() << " index after setting " << portPair.second->getIndex() << std::endl;
118+ // std::cout << "\t id " << portPair.second->id().toString() << " index after setting " << portPair.second->getIndex() << std::endl;
120119 // }
121120
122121 return newPortIndex;
123122 }
124123 }
125124 // if (item->isDynamic())
126- // std::cout << "original port: " << item->id().toString() << " newIndex: " << size() - 1 << std::endl;
125+ // std::cout << "original port: " << item->id().toString() << " newIndex: " << size() - 1 << std::endl;
127126 return size () - 1 ;
128127}
129128
@@ -158,7 +157,7 @@ PortManager<T>::checkDynamicPortInvariant(const std::string& name)
158157 if (0 == port->nconnections () && i != lastIndex)
159158 toRemove.push_back (port->id ());
160159 }
161- for (const PortId & id : toRemove)
160+ for (const auto & id : toRemove)
162161 remove (id);
163162}
164163
@@ -173,13 +172,16 @@ PortManager<T>::remove(const PortId& id)
173172 ostr << " PortManager tried to remove a port that does not exist: " << id;
174173 BOOST_THROW_EXCEPTION (PortOutOfBoundsException () << Core::ErrorMessage (ostr.str ()));
175174 }
176- // std::cout << "~~~removing port " << id.toString() << std::endl;
175+ auto removedIndex = it->second ->getIndex ();
176+ // std::cout << "~~~removing port " << id.toString() << " index " << removedIndex << std::endl;
177177 ports_.erase (it);
178- size_t i = 0 ;
179178 for (auto & portPair : ports_)
180179 {
181- // std::cout << "\t resetting index " << portPair.second->id().toString() << " " << i;
182- portPair.second ->setIndex (i++);
180+ if (portPair.second ->getIndex () > removedIndex)
181+ {
182+ // std::cout << "\t resetting index " << portPair.second->id().toString() << " " << portPair.second->getIndex()-1 << std::endl;
183+ portPair.second ->decrementIndex ();
184+ }
183185 }
184186}
185187
0 commit comments