Skip to content

Commit 0ad5eb6

Browse files
committed
Closes #678
1 parent 25e78ae commit 0ad5eb6

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/Dataflow/Network/Port.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@ class SCISHARE Port : virtual public PortInterface, boost::noncopyable
5858
Port(ModuleInterface* module, const ConstructionParams& params);
5959
virtual ~Port();
6060

61-
size_t nconnections() const;
62-
const Connection* connection(size_t) const;
61+
size_t nconnections() const override;
62+
const Connection* connection(size_t) const override;
6363

64-
virtual PortId id() const { return id_; }
65-
virtual void setId(const PortId& id) { id_ = id; }
66-
std::string get_typename() const { return typeName_; }
64+
virtual PortId id() const override { return id_; }
65+
virtual void setId(const PortId& id) override { id_ = id; }
66+
std::string get_typename() const override { return typeName_; }
6767
std::string get_colorname() const { return colorName_; }
68-
std::string get_portname() const { return portName_; }
68+
std::string get_portname() const override { return portName_; }
6969

70-
virtual void attach(Connection* conn);
71-
virtual void detach(Connection* conn);
70+
virtual void attach(Connection* conn) override;
71+
virtual void detach(Connection* conn) override;
7272

73-
virtual ModuleId getUnderlyingModuleId() const;
74-
virtual size_t getIndex() const;
75-
virtual void setIndex(size_t index);
73+
virtual ModuleId getUnderlyingModuleId() const override;
74+
virtual size_t getIndex() const override;
75+
virtual void setIndex(size_t index) override;
7676

7777
/// @todo:
7878
// light interface

src/Dataflow/Network/PortInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ namespace Networks {
6868
virtual void detach(Connection* conn) = 0;
6969
virtual const Connection* connection(size_t) const = 0;
7070
virtual void setIndex(size_t index) = 0;
71+
void incrementIndex() { setIndex(getIndex() + 1); }
72+
void decrementIndex() { setIndex(getIndex() - 1); }
7173
virtual void setId(const PortId& id) = 0;
7274
};
7375

src/Dataflow/Network/PortManager.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
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

Comments
 (0)