torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Connectable.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_CONNECTABLE_HPP
17 #define TORC_GENERIC_CONNECTABLE_HPP
18 
19 #include <list>
20 #include <vector>
21 
22 //BOOST
23 //#include <boost/signal.hpp>
24 #include <boost/signals2.hpp>
25 #ifdef GENOM_SERIALIZATION
26 #include <boost/serialization/access.hpp>
27 #include <boost/serialization/is_abstract.hpp>
28 #endif //GENOM_SERIALIZATION
30 #include "torc/generic/Error.hpp"
31 
32 namespace torc { namespace generic { class Net; } }
33 
34 namespace torc {
35 namespace generic {
36 
37 /**
38  * @brief An object that is connectable to a Net
39  *
40  * The Connectable class can act as a base for objects that can connect to a Net. This interface
41  * provides event functionality for connection and disconnection. It also provides polymorphic
42  * methods to implement connectivity beween different components in a design.
43  */
44 class Connectable {
45 #ifdef GENOM_SERIALIZATION
46  friend class boost::serialization::access;
47 #endif //GENOM_SERIALIZATION
48 public:
49  /**
50  * A connection between a net and this object
51  */
52  typedef std::list<NetSharedPtr>::iterator Connection;
53 
54  /**
55  * A signal to indicate that a new connection has been made
56  */
57  typedef boost::signals2::signal<void(const NetSharedPtr&)> Connected;
58 
59  /**
60  * A signal to indicate that a connection has been removed
61  */
62  typedef boost::signals2::signal<void(const NetSharedPtr&)> Disconnected;
63 
64 public:
65  /**
66  * A signal to indicate that a new connection has been made
67  */
68  inline Connected& signalNetConnected();
69 
70  /**
71  * A signal to indicate that a new connection has been made
72  */
74 
75  /**
76  * Get the vector of Nets that are Connected to the current object. The connected elements are
77  * appended to the given vector
78  *
79  * @param[out] outNets A vector of Connected nets
80  */
81  virtual void getConnectedNets(std::vector<NetSharedPtr>& outNets, bool inSkipChildConnections =
82  false) const throw (Error);
83 
84  /**
85  * Connect a Net to this object.
86  *
87  * @note This metod can be overridden by derived classes. However, the method must call the
88  * on_connected() method after this. The sigConnected_ signal must also be invoked in the
89  * overriding method.
90  *
91  * @param[in] inNet A pointer to the Net object that needs to be Connected
92  * @return A connection that has been established. This can be used later for disconnection.
93  */
94  virtual Connection connect(const NetSharedPtr& inNet) throw (Error) = 0;
95 
96  /**
97  * Disconnect a Net from this object.
98  * @note This metod can be overridden by derived classes. However, the method must call the
99  * on_connected() method after this. The sigConnected_ signal must also be invoked in the
100  * overriding method.
101 
102  * @param[in] inConnection A connection as returned by the connect() method
103  * @exception Error Provided connection is invalid
104  */
105  virtual void disconnect(const Connection& inConnection) throw (Error) = 0;
106 
107  /**
108  * Disconnect the named Net from this object.
109  @note This metod can be overridden by derived classes. However, the method must call the
110  on_connected() method after this. The sigConnected_ signal must also be invoked in the
111  overriding method.
112 
113  * @param[in] inName Name of the net to be Disconnected
114  * @exception Error Provided net was not found
115  */
116  void disconnect(const std::string& inName) throw (Error);
117 
118  /**
119  * Disconnect the given Net from this object.
120  @note This metod can be overridden by derived classes. However, the method must call the
121  on_disconnected() method after this. The sigDisconnected_ signal must also be invoked in the
122  overriding method.
123 
124  * @param[in] net Pointer to a net
125  * @exception Error Provided net was not found
126  */
127  void disconnect(const NetSharedPtr& net) throw (Error);
128 
129  /**
130  * Disconnect all connections to this port.
131  *
132  */
133  virtual void disconnect() throw (Error);
134 
135 protected:
136  /**
137  * A polymorphic function that is called after a net is Connected to this object
138  */
139  virtual void onConnect() throw (Error);
140 
141  /**
142  * A polymorphic function that is called after a net is Disconnected from this object
143  */
144  virtual void onDisconnect() throw (Error);
145 
146  Connectable();
147 
148  virtual ~Connectable() throw ();
149 
150 private:
151  Connectable(const Connectable& rhs);
152 
153  Connectable& operator =(const Connectable& rhs);
154 
155 #ifdef GENOM_SERIALIZATION
156  template <class Archive> void serialize(Archive& ar, unsigned int);
157 #endif //GENOM_SERIALIZATION
158 private:
159  std::list<NetSharedPtr> mConnectedNets;
162 };
163 
164 /**
165  * A signal to indicate that a new connection has been made
166  */
168  return mSigNetConnected;
169 }
170 
171 /**
172  * A signal to indicate that a new connection has been made
173  */
175  return mSigNetDisconnected;
176 }
177 
178 } // namespace generic
179 } // namespace torc
180 
181 #ifdef GENOM_SERIALIZATION
182 BOOST_IS_ABSTRACT(torc::generic::Connectable)
183 #endif // GENOM_SERIALIZATION
184 #endif // TORC_GENERIC_CONNECTABLE_HPP
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
Connected & signalNetConnected()
An object that is connectable to a Net.
Definition: Connectable.hpp:44
Disconnected & signalNetDisconnected()
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
std::list< NetSharedPtr > mConnectedNets
Disconnected mSigNetDisconnected
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
Definition: Connectable.cpp:45
boost::shared_ptr< Net > NetSharedPtr
boost::signals2::signal< void(const NetSharedPtr &)> Disconnected
Definition: Connectable.hpp:62
boost::signals2::signal< void(const NetSharedPtr &)> Connected
Definition: Connectable.hpp:57