torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
generic/Net.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_NET_HPP
17 #define TORC_GENERIC_NET_HPP
18 
20 
21 #include <algorithm>
22 #include <vector>
23 
24 #ifdef GENOM_SERIALIZATION
25 #include <boost/serialization/access.hpp>
26 #endif //GENOM_SERIALIZATION
30 #include "torc/generic/Error.hpp"
35 #include "torc/generic/SymTab.hpp"
37 #include "torc/generic/View.hpp"
39 
40 namespace torc { namespace generic { class ConnectionHandler; } }
41 namespace torc { namespace generic { class Port; } }
42 namespace torc { namespace generic { class PortReference; } }
43 namespace torc { namespace generic { class NetAttributes; } }
44 
45 namespace torc {
46 namespace generic {
47 
48 /**
49  * @brief Represents an EDIF Net
50  *
51  * The Net class is an interface to EDIF nets. Net is an interface for scalar nets, vector nets,
52  * vector nets bits and net bundles. This class provides a simplified view of all three types of
53  * nets. To get a handle to an actual net, the client will have to use a Visitor with proper
54  * overloads of the visit() function, or dynamic_cast can be used. The latter method is however not
55  * recommended. A net object supports storing properties for storing different EDIF properties. See
56  * documentation of the Property and PropertyContainer classes for more details.
57  */
58 class Net : public Commentable, public Connectable, public Nameable, public PropertyContainer,
59  public Renamable, public Visitable, virtual public Composite<Net>, public ParentedObject<View>,
60  public UserDataContainer {
61 #ifdef GENOM_SERIALIZATION
62  friend class boost::serialization::access;
63 #endif //GENOM_SERIALIZATION
64  friend class ConnectionHandler;
65 
66 public:
67  /**
68  * Add a subnet to this net.
69  *
70  * @param[in] inSubnet Subnet to be added
71  *
72  * @exception Error Could not add subnet, because subnet name is empty
73  * <ul>
74  * <li>
75  * Id : eMessageIdErrorEmptyItemName
76  * </li>
77  * <li> Context Data
78  * <ul>
79  * <li>Subnet name - <i>String</i></li>
80  * </ul>
81  * </li>
82  * </ul>
83  *
84  * @exception Error Could not add subnet, because subnet name is already exists
85  * <ul>
86  * <li>
87  * Id : eMessageIdErrorItemAlreadyExists
88  * </li>
89  * <li> Context Data
90  * <ul>
91  * <li>Subnet name - <i>String</i></li>
92  * </ul>
93  * </li>
94  * </ul>
95  */
96  void addSubnet(const NetSharedPtr& inSubnet) throw (Error);
97 
98  /**
99  * Find a subnet from belonging to this net.
100  *
101  * @param[in] inName Name of the subnet. If not found, empty pointer is returned
102  *
103  */
104  NetSharedPtr findSubnet(const std::string& inName) throw (Error);
105 
106  /**
107  * Remove a subnet from this net.
108  *
109  * @param inName Name of the object to be delete
110  *
111  * @exception Error Could not remove subnet, because subnet name is empty
112  * <ul>
113  * <li>
114  * Id : eMessageIdErrorEmptyItemName
115  * </li>
116  * <li> Context Data
117  * <ul>
118  * <li>Subnet name - <i>String</i></li>
119  * </ul>
120  * </li>
121  * </ul>
122  *
123  * @exception Error Could not remove subnet, because subnet not present.
124  * <ul>
125  * <li>
126  * Id : eMessageIdErrorItemNotFound
127  * </li>
128  * <li> Context Data
129  * <ul>
130  * <li>Subnet name - <i>String</i></li>
131  * </ul>
132  * </li>
133  * </ul>
134  *
135  */
136  void removeSubnet(const std::string& inName) throw (Error);
137 
138  inline void getSubnets(std::vector<NetSharedPtr>& outSubnets) const;
139 
140  void setSubnets(const std::vector<NetSharedPtr> & inSource) throw (Error);
141  /**
142  * Apply action on all Subnets.
143  * @param[in] action Action to be applied
144  *
145  */
146  template <typename _Action> inline void applyOnAllSubnets(const _Action& action) throw (Error);
147 
148  inline NetSharedPtr getParentNet() const;
149 
150  void setParentNet(const NetSharedPtr& inParent);
151 
152  /**
153  * Get the attributes of the net. Attributes include criticality, netDelay etc.
154  *
155  * @return Pointer to NetAttributes object.
156  */
157  inline const NetAttributesSharedPtr getAttributes() const;
158 
159  /**
160  * Set the attributes of the net. Attributes include criticality, netDelay etc.
161  *
162  * @param[in] inSource Pointer to NetAttributes object.
163  */
164  void setAttributes(const NetAttributesSharedPtr& inSource);
165 
166 protected:
167  void addConnectedPort(const PortSharedPtr& inPort) throw (Error);
168 
169  void removeConnectedPort(const PortSharedPtr& inPort) throw (Error);
170 
171  void addConnectedPortList(const PortListSharedPtr& inPort) throw (Error);
172 
173  void removeConnectedPortList(const PortListSharedPtr& inList) throw (Error);
174 
175 public:
176  /**
177  * Find a port connected to this net.
178  *
179  * @param[in] inName Name of the port. If not found, empty pointer is returned
180  */
181  PortSharedPtr findConnectedPort(const std::string& inName) throw (Error);
182 
183  /**
184  * Appends vector of connected ports
185  * @param[in] outPort vector of port to be appended to
186  * @param[in] inSkipChildConnections Return only ports connected to this port and skip
187  * returning elements that have been connected to the child
188  */
189  virtual void getConnectedPorts(std::vector<PortSharedPtr>& outPort,
190  bool inSkipChildConnections = false) const;
191 
192  /**
193  * Apply action on all connected ports.
194  * @param[in] action Action to be applied
195  *
196  */
197  template <typename _Action> inline void applyOnAllConnectedPorts(const _Action& action)
198  throw (Error);
199 
200  /**
201  * Appends vector of connected port lists
202  * @param[in] outPortList vector of port lists to be appended to
203  */
204  virtual void getConnectedPortLists(std::vector<PortListSharedPtr>& outPortList) const;
205 
206  /**
207  * Apply action on all connected port lists.
208  * @param[in] action Action to be applied
209  *
210  */
211  template <typename _Action> inline void applyOnAllConnectedPortLists(const _Action& action)
212  throw (Error);
213 
215 
216  virtual void disconnect() throw (Error);
217 
218 protected:
219  //TBD::UNUSED?
220  void
221  setConnectedPorts(const std::vector<PortSharedPtr>& inSource) throw (Error);
222 
223 protected:
224 
225  void addConnectedPortReference(const PortReferenceSharedPtr& portRef) throw (Error);
226 
227  void removeConnectedPortReference(const PortReferenceSharedPtr& inPortRef) throw (Error);
228 
229 public:
230  /**
231  * Find a port reference connected to this net.
232  *
233  * @param[in] inName Name of the port reference. If not found, empty pointer is returned
234  */
235  PortReferenceSharedPtr findConnectedPortReference(const std::string& inName) throw (Error);
236 
237  /**
238  * Appends vector of connected port references
239  * @param[in] outPortRefs vector of port refs to be appended to
240  */
241  virtual void getConnectedPortRefs(std::vector<PortReferenceSharedPtr>& outPortRefs,
242  bool inSkipChildConnections = false) const;
243 
244  /**
245  * Apply action on all connected port refs.
246  * @param[in] action Action to be applied
247  *
248  */
249  template <typename _Action> inline void applyOnAllConnectedPortRefs(const _Action& action)
250  throw (Error);
251 
252 protected:
253  Net();
254 
255 public:
256  virtual ~Net() throw ();
257 
258 private:
259 #ifdef GENOM_SERIALIZATION
260  template <class Archive> void serialize(Archive& ar, unsigned int);
261 #endif //GENOM_SERIALIZATION
262  Net(const Net& source);
263 
264  Net& operator=(const Net& source);
265 
266 protected:
267  //TBD::UNUSED?
268  void setConnectedPortRefs(const std::vector<PortReferenceSharedPtr>& inSource) throw (Error);
269 
270 private:
272  std::list<PortSharedPtr> mConnectedPorts;
273  std::list<PortListSharedPtr> mConnectedPortLists;
274  std::list<PortReferenceSharedPtr> mConnectedPortRefs;
277 };
278 
279 inline void Net::getSubnets(std::vector<NetSharedPtr>& outSubnets) const {
280  mSubnets.getValues(outSubnets);
281  return;
282 }
283 
284 template <typename _Action> inline void Net::applyOnAllSubnets(const _Action& action)
285  throw (Error) {
286  try {
287  mSubnets.applyOnAll(action);
288  } catch(Error& e) {
289  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
290  throw;
291  }
292 }
293 
295  return mParentNet;
296 }
297 
298 /**
299  * Get the attributes of the net. Attributes include criticality, netDelay etc.
300  *
301  * @return Pointer to NetAttributes object.
302  */
304  return mAttributes;
305 }
306 
307 template <typename _Action> inline void Net::applyOnAllConnectedPorts(const _Action& action)
308  throw (Error) {
309  try {
310  std::for_each(mConnectedPorts.begin(), mConnectedPorts.end(), action);
311  } catch(Error& e) {
312  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
313  throw;
314  }
315 }
316 
317 template <typename _Action> inline void Net::applyOnAllConnectedPortLists(const _Action& action)
318  throw (Error) {
319  try {
320  std::for_each(mConnectedPortLists.begin(), mConnectedPortLists.end(), action);
321  } catch(Error& e) {
322  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
323  throw;
324  }
325 }
326 
327 template <typename _Action> inline void Net::applyOnAllConnectedPortRefs(const _Action& action)
328  throw (Error) {
329  try {
330  std::for_each(mConnectedPortRefs.begin(), mConnectedPortRefs.end(), action);
331  } catch(Error& e) {
332  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
333  throw;
334  }
335 }
336 
337 } // namespace generic
338 } // namespace torc
339 
340 #endif // TORC_GENERIC_NET_HPP
void getValues(std::vector< ValueType > &outValues) const
Definition: SymTab.hpp:158
void removeConnectedPort(const PortSharedPtr &inPort)
An object that has a parent.
void applyOnAllSubnets(const _Action &action)
std::list< PortReferenceSharedPtr > mConnectedPortRefs
boost::shared_ptr< NetAttributes > NetAttributesSharedPtr
Represents objects that have properties.
void applyOnAllConnectedPortLists(const _Action &action)
void setParentNet(const NetSharedPtr &inParent)
void setConnectedPorts(const std::vector< PortSharedPtr > &inSource)
Interface for objects that can be composed within each other.
Definition: Composite.hpp:45
void removeSubnet(const std::string &inName)
Definition: generic/Net.cpp:99
void removeConnectedPortReference(const PortReferenceSharedPtr &inPortRef)
An object that is connectable to a Net.
Definition: Connectable.hpp:44
PortSharedPtr findConnectedPort(const std::string &inName)
PortReferenceSharedPtr findConnectedPortReference(const std::string &inName)
Represents an EDIF Net.
Definition: generic/Net.hpp:58
NetSharedPtr getParentNet() const
void applyOnAllConnectedPorts(const _Action &action)
Represents all classes that can hold user comments.
Definition: Commentable.hpp:36
std::list< PortSharedPtr > mConnectedPorts
Represents class that can hold userData.
virtual void getConnectedPorts(std::vector< PortSharedPtr > &outPort, bool inSkipChildConnections=false) const
std::string string
Net & operator=(const Net &source)
void getSubnets(std::vector< NetSharedPtr > &outSubnets) const
virtual void getConnectedPortRefs(std::vector< PortReferenceSharedPtr > &outPortRefs, bool inSkipChildConnections=false) const
void addSubnet(const NetSharedPtr &inSubnet)
Definition: generic/Net.cpp:63
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
boost::shared_ptr< Net > NetSharedPtr
boost::shared_ptr< PortReference > PortReferenceSharedPtr
boost::shared_ptr< PortList > PortListSharedPtr
void addConnectedPort(const PortSharedPtr &inPort)
void addConnectedPortList(const PortListSharedPtr &inPort)
const NetAttributesSharedPtr getAttributes() const
virtual void getConnectedPortLists(std::vector< PortListSharedPtr > &outPortList) const
virtual void disconnect()
NetAttributesSharedPtr mAttributes
void applyOnAllConnectedPortRefs(const _Action &action)
NetSharedPtr findSubnet(const std::string &inName)
Definition: generic/Net.cpp:85
void removeConnectedPortList(const PortListSharedPtr &inList)
An object that has a name.
Definition: Nameable.hpp:34
void setAttributes(const NetAttributesSharedPtr &inSource)
boost::shared_ptr< Port > PortSharedPtr
Represents objects that can be renamed.
void setConnectedPortRefs(const std::vector< PortReferenceSharedPtr > &inSource)
SymTab< std::string, NetSharedPtr, true > mSubnets
void addConnectedPortReference(const PortReferenceSharedPtr &portRef)
std::list< PortListSharedPtr > mConnectedPortLists
void setSubnets(const std::vector< NetSharedPtr > &inSource)
An object that receives an inoutVisitor.
Definition: Visitable.hpp:38
NetSharedPtr mParentNet
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73