@@ -50,15 +50,17 @@ class PortManager : boost::noncopyable
5050{
5151private:
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
5658public:
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; }
8587PortManager<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
111114template <class T >
112115T
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