Skip to content

Commit 29bc3b8

Browse files
committed
Port idea
1 parent c7fd82a commit 29bc3b8

File tree

3 files changed

+363
-5
lines changed

3 files changed

+363
-5
lines changed

src/Dataflow/Network/PortInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ namespace Networks {
6767
virtual void detach(Connection* conn) = 0;
6868
virtual const Connection* connection(size_t) const = 0;
6969
virtual void setIndex(size_t index) = 0;
70+
virtual void setId(const PortId& id) = 0;
7071
};
7172

7273
typedef boost::signals2::signal<void(const PortId&, SCIRun::Core::Datatypes::DatatypeHandle)> DataOnPortHasChangedSignalType;

src/Dataflow/Network/PortManager.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ class PortManager : boost::noncopyable
5050
{
5151
private:
5252
typedef std::map<PortId, T> PortMap;
53+
typedef std::map<std::string, bool> DynamicMap;
5354
PortMap ports_;
55+
DynamicMap isDynamic_;
5456
ModuleInterface* module_;
5557

5658
public:
5759
PortManager();
5860
size_t size() const;
5961
size_t add(const T& item);
6062
void remove(const PortId& id);
61-
T operator[](const PortId& id) const;
63+
T operator[](const PortId& id);
6264
std::vector<T> operator[](const std::string& name) const;
6365
bool hasPort(const PortId& id) const;
6466
void set_module(ModuleInterface* mod) { module_ = mod; }
@@ -85,6 +87,7 @@ size_t
8587
PortManager<T>::add(const T& item)
8688
{
8789
ports_[item->id()] = item;
90+
isDynamic_[item->id().name] = item->isDynamic();
8891
/// @todo: who should manage port indexes?
8992
//item->setIndex(size() - 1);
9093
auto index = size() - 1;
@@ -110,19 +113,35 @@ PortManager<T>::remove(const PortId& id)
110113

111114
template<class T>
112115
T
113-
PortManager<T>::operator[](const PortId& id) const
116+
PortManager<T>::operator[](const PortId& id)
114117
{
115118
auto it = ports_.find(id);
116119
if (it == ports_.end())
117120
{
121+
if (isDynamic_[id.name])
122+
{
123+
auto byName = this->operator[](id.name);
124+
if (byName.empty())
125+
{
126+
std::ostringstream ostr;
127+
ostr << "PortManager tried to access a port that does not exist: " << id;
128+
BOOST_THROW_EXCEPTION(PortOutOfBoundsException() << Core::ErrorMessage(ostr.str()));
129+
}
130+
auto newPort = byName[0]->clone();
131+
newPort->setId(id);
132+
add(newPort);
133+
return newPort;
134+
}
135+
136+
118137
/// @todo: need a way to detect and create arbitrary dynamic ports from serialized files.
119138
//if (id.dynamic)
120139
// std::cout << "DYNAMIC PORT NEEDS TO INSERT ITSELF HERE SOMEHOW" << std::endl;
121140
//else
122141
// std::cout << "NOT SETTING PORT FLAGS CORRECT" << std::endl;
123-
std::ostringstream ostr;
124-
ostr << "PortManager tried to access a port that does not exist: " << id;
125-
BOOST_THROW_EXCEPTION(PortOutOfBoundsException() << Core::ErrorMessage(ostr.str()));
142+
//std::ostringstream ostr;
143+
//ostr << "PortManager tried to access a port that does not exist: " << id;
144+
//BOOST_THROW_EXCEPTION(PortOutOfBoundsException() << Core::ErrorMessage(ostr.str()));
126145
}
127146
return it->second;
128147
}

0 commit comments

Comments
 (0)