torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::PortList Class Reference

Represents an ordered list of port references. More...

#include <PortList.hpp>

+ Inheritance diagram for torc::generic::PortList:
+ Collaboration diagram for torc::generic::PortList:

Data Structures

class  Factory
 

Public Types

typedef PortElement PortListElement
 
typedef VisitorType< PortListVisitor
 
typedef std::list
< NetSharedPtr >::iterator 
Connection
 
typedef
boost::signals2::signal< void(const
NetSharedPtr &)> 
Connected
 
typedef
boost::signals2::signal< void(const
NetSharedPtr &)> 
Disconnected
 
typedef PortList Type
 
typedef boost::shared_ptr< TypePointer
 
typedef boost::weak_ptr< TypeWeakPointer
 

Public Member Functions

virtual void accept (BaseVisitor &inoutVisitor) throw (Error)
 
virtual Connection connect (const NetSharedPtr &inNet) throw (Error)
 
virtual void disconnect (const Connection &inConnection) throw (Error)
 
size_t getSize () const
 
void addChildPort (const PortSharedPtr &inPort)
 
void addChildPortReference (const PortReferenceSharedPtr &inPortRef)
 
void getChildren (std::list< PortListElement > &outPorts)
 
virtual ~PortList () throw ()
 
ConnectedsignalNetConnected ()
 
DisconnectedsignalNetDisconnected ()
 
virtual void getConnectedNets (std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const throw (Error)
 
void disconnect (const std::string &inName) throw (Error)
 
void disconnect (const NetSharedPtr &net) throw (Error)
 
virtual void disconnect () throw (Error)
 
void setWeakThis (const WeakPointer &inWeakThis)
 
Pointer getSharedThis () const
 

Protected Member Functions

 PortList ()
 
virtual void onConnect () throw (Error)
 
virtual void onDisconnect () throw (Error)
 

Private Member Functions

template<typename _Tp >
void connectElementToNet (const NetSharedPtr &inNet, const boost::shared_ptr< _Tp > &inType, size_t &inoutCurrentWidth) throw (Error)
 

Private Attributes

std::list< PortListElementmElements
 

Friends

class FactoryType< PortList >
 

Detailed Description

Represents an ordered list of port references.

The PortList class represents an ordered list of port references. Such objects in EDIF are declard using the (portList portRefName1 portRefName2 ... ) syntax.

Definition at line 43 of file PortList.hpp.

Member Typedef Documentation

typedef boost::signals2::signal<void(const NetSharedPtr&)> torc::generic::Connectable::Connected
inherited

A signal to indicate that a new connection has been made

Definition at line 57 of file Connectable.hpp.

typedef std::list<NetSharedPtr>::iterator torc::generic::Connectable::Connection
inherited

A connection between a net and this object

Definition at line 52 of file Connectable.hpp.

typedef boost::signals2::signal<void(const NetSharedPtr&)> torc::generic::Connectable::Disconnected
inherited

A signal to indicate that a connection has been removed

Definition at line 62 of file Connectable.hpp.

typedef boost::shared_ptr<Type> torc::generic::SelfReferencing< PortList >::Pointer
inherited

Definition at line 36 of file SelfReferencing.hpp.

Definition at line 35 of file SelfReferencing.hpp.

typedef boost::weak_ptr<Type> torc::generic::SelfReferencing< PortList >::WeakPointer
inherited

Definition at line 37 of file SelfReferencing.hpp.

Constructor & Destructor Documentation

torc::generic::PortList::~PortList ( )
throw (
)
virtual

Definition at line 217 of file PortList.cpp.

217  {
218  mElements.clear();
219 }
std::list< PortListElement > mElements
Definition: PortList.hpp:145
torc::generic::PortList::PortList ( )
protected

Definition at line 215 of file PortList.cpp.

215 : Connectable(), mElements() {}
std::list< PortListElement > mElements
Definition: PortList.hpp:145

Member Function Documentation

void torc::generic::PortList::accept ( BaseVisitor inoutVisitor)
throw (Error
)
virtual

Receive a visitor to this class. The visit method of the visitor is called and a reference to this object is passed as a parameter. It has to be noted however, that a dynamic_cast is performed inside this method. If the cast fails, an appropriate exception is thrown by this method. This situation can arise when the passed Visitor object does not inherit from the appropriate visitor specialization. See Visitor documentation for more details.

Parameters
[in,out]inoutVisitorA reference to the visitor object
Exceptions
ErrorVisitor type inappropriate for visiting this object or any other error thrown by the Visitor::throw() method.

Definition at line 65 of file PortList.cpp.

65  {
66  try {
67  runVisitor(*this, inoutVisitor);
68  } catch(Error& e) {
69  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
70  throw;
71  }
72 }
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78

+ Here is the call graph for this function:

void torc::generic::PortList::addChildPort ( const PortSharedPtr inPort)

Add a port to the port list.

Parameters
[in]inPortPointer to port to be added.

Definition at line 203 of file PortList.cpp.

203  {
204  mElements.push_back(PortListElement(inPort));
205 }
PortElement PortListElement
Definition: PortList.hpp:51
std::list< PortListElement > mElements
Definition: PortList.hpp:145
void torc::generic::PortList::addChildPortReference ( const PortReferenceSharedPtr inPortRef)

Add a port reference to the port list.

Parameters
[in]inPortRefPointer to port reference to be added.

Definition at line 207 of file PortList.cpp.

207  {
208  mElements.push_back(PortListElement(inPortRef));
209 }
PortElement PortListElement
Definition: PortList.hpp:51
std::list< PortListElement > mElements
Definition: PortList.hpp:145
Connectable::Connection torc::generic::PortList::connect ( const NetSharedPtr inNet)
throw (Error
)
virtual

Connect a Net to this object.

Parameters
[in]inNetA pointer to the Net object that needs to be connected
Returns
A connection that has been established. This can be used later for disconnection.

Implements torc::generic::Connectable.

Definition at line 140 of file PortList.cpp.

140  {
141  size_t count = 0;
142  for(std::list<PortListElement>::iterator it = mElements.begin(); it != mElements.end(); ++it) {
143  try {
144  switch((*it).getType()) {
146  connectElementToNet(inNet, (*it).getPort(), count);
147  break;
148  }
150  connectElementToNet(inNet, (*it).getPortReference(), count);
151  break;
152  }
153  }
154  } catch(Error& e) {
155  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
156  throw;
157  }
158  }
159  Connectable::Connection newConnection;
160  try {
161  ConnectionHandler handler(inNet);
162  handler.connectPortListToNet(getSharedThis());
163  newConnection = Connectable::connect(inNet);
164  } catch(Error& e) {
165  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
166  throw;
167  }
168  return newConnection;
169 }
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
void connectElementToNet(const NetSharedPtr &inNet, const boost::shared_ptr< _Tp > &inType, size_t &inoutCurrentWidth)
Definition: PortList.cpp:74
std::list< PortListElement > mElements
Definition: PortList.hpp:145

+ Here is the call graph for this function:

template<typename _Tp >
void torc::generic::PortList::connectElementToNet ( const NetSharedPtr inNet,
const boost::shared_ptr< _Tp > &  inType,
size_t &  inoutCurrentWidth 
)
throw (Error
)
private

Definition at line 74 of file PortList.cpp.

75  {
76  try {
77  typedef _Tp Type;
78  typedef boost::shared_ptr<_Tp> Pointer;
79  size_t updatedSize = inoutCurrentWidth + inType->getSize();
80  if(updatedSize > inNet->getSize()) {
81  //TBD::ERROR
82  }
83  //Element can be connected to scalar or Vector only
84  switch(inNet->getCompositionType()) {
87  if(1 == inType->getSize()) {
88  Connectable::Connection conn = inType->connect(inNet);
89  inoutCurrentWidth++;
90  (void) conn; // NJS
91  }
92  break;
93  }
95  //We explode the vector net
96  std::vector<NetSharedPtr> children;
97  inNet->getChildren(children);
98 
99  switch(inType->getCompositionType()) {
102  //One element vector net to a scalar port
103  {
104  connectElementToNet(children[inoutCurrentWidth], inType, inoutCurrentWidth);
105  break;
106  }
108  //Part of vector net to vector port
109  {
110  std::vector<Pointer> cTypes;
111  inType->getChildren(cTypes);
112  size_t j = 0;
113  for(size_t i = inoutCurrentWidth; i < updatedSize; i++, j++) {
114  connectElementToNet(children[i], cTypes[j], inoutCurrentWidth);
115  }
116  break;
117  }
118  case eCompositionTypeBundle: {
119  std::vector<Pointer> cTypes;
120  inType->getChildren(cTypes);
121  for(typename std::vector<Pointer>::iterator it = cTypes.begin(); it != cTypes.end();
122  ++it) {
123  connectElementToNet(inNet, *it, inoutCurrentWidth);
124  }
125  break;
126  }
127  }
128  }
130  default: {
131  //NOT POSSIBLE
132  }
133  }
134  } catch(Error& e) {
135  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
136  throw;
137  }
138 }
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
void connectElementToNet(const NetSharedPtr &inNet, const boost::shared_ptr< _Tp > &inType, size_t &inoutCurrentWidth)
Definition: PortList.cpp:74

+ Here is the call graph for this function:

void torc::generic::PortList::disconnect ( const Connection inConnection)
throw (Error
)
virtual

Disconnect a Net from this object.

Parameters
[in]inConnectionA connection as returned by the connect() method
Exceptions
ErrorProvided connection is invalid

Implements torc::generic::Connectable.

Definition at line 171 of file PortList.cpp.

171  {
172  NetSharedPtr inNet = *inConnection;
173  //Do not clear components from here ...
174  //They are connected to individual bits of some net
175  // and would be cleared in due course
176  try {
177  ConnectionHandler handler(inNet);
178  handler.disconnectPortListFromNet(getSharedThis());
179  } catch(Error& e) {
180  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
181  throw;
182  }
183 }
boost::shared_ptr< Net > NetSharedPtr

+ Here is the call graph for this function:

void torc::generic::Connectable::disconnect ( const std::string &  inName)
throw (Error
)
inherited

Disconnect the named Net from this object.

Note
This metod can be overridden by derived classes. However, the method must call the on_connected() method after this. The sigConnected_ signal must also be invoked in the overriding method.
Parameters
[in]inNameName of the net to be Disconnected
Exceptions
ErrorProvided net was not found

Disconnect the named Net from this object.

Note
This metod can be overridden by derived classes. However, the method must call the on_connected() method after this. The sigConnected_ signal must also be invoked in the overriding method.
Parameters
[in]inNnameName of the net to be Disconnected
Exceptions
ErrorProvided net was not found

Definition at line 111 of file Connectable.cpp.

111  {
112  disconnect(std::find_if(mConnectedNets.begin(), mConnectedNets.end(),
113  boost::bind<bool>(std::equal_to<std::string>(),
114  boost::bind(boost::mem_fn(&Net::getName), _1), inName)));
115 }
std::list< NetSharedPtr > mConnectedNets
virtual const std::string getName() const
Definition: Nameable.hpp:89

+ Here is the call graph for this function:

void torc::generic::Connectable::disconnect ( const NetSharedPtr inNet)
throw (Error
)
inherited

Disconnect the given Net from this object.

Note
This metod can be overridden by derived classes. However, the method must call the on_disconnected() method after this. The sigDisconnected_ signal must also be invoked in the overriding method.
Parameters
[in]netPointer to a net
Exceptions
ErrorProvided net was not found

Disconnect the given Net from this object.

Note
This metod can be overridden by derived classes. However, the method must call the on_disconnected() method after this. The sigDisconnected_ signal must also be invoked in the overriding method.
Parameters
[in]inNetPointer to a net
Exceptions
ErrorProvided net was not found

Definition at line 128 of file Connectable.cpp.

128  {
129  disconnect(std::find(mConnectedNets.begin(), mConnectedNets.end(), inNet));
130 }
std::list< NetSharedPtr > mConnectedNets
void torc::generic::Connectable::disconnect ( )
throw (Error
)
virtualinherited

Disconnect all connections to this port.

Reimplemented in torc::generic::Net, torc::generic::VectorNet, and torc::generic::NetBundle.

Definition at line 132 of file Connectable.cpp.

132  {
133  log("Disconnecting all\n");
134  std::vector<NetSharedPtr> nets;
135  getConnectedNets(nets, true);
136  for(std::vector<NetSharedPtr>::iterator it = nets.begin(); it != nets.end(); ++it) {
137  disconnect(*it);
138  }
139 }
void log(const char *fmt,...)
Definition: Log.cpp:89
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
Definition: Connectable.cpp:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void torc::generic::PortList::getChildren ( std::list< PortListElement > &  outPorts)

Get all the children of this composition

Returns
[out] outPorts List containing all children

Definition at line 211 of file PortList.cpp.

211  {
212  outElements.insert(outElements.end(), mElements.begin(), mElements.end());
213 }
std::list< PortListElement > mElements
Definition: PortList.hpp:145
void torc::generic::Connectable::getConnectedNets ( std::vector< NetSharedPtr > &  outNets,
bool  inSkipChildConnections = false 
) const
throw (Error
)
virtualinherited

Get the vector of Nets that are Connected to the current object. The connected elements are appended to the given vector

Parameters
[out]outNetsA vector of Connected nets

Get the vector of Nets that are Connected to the current object. The connected elements are appended to the given vector

Returns
A vector of Connected nets

Reimplemented in torc::generic::VectorPortReference, torc::generic::VectorNet, torc::generic::VectorPort, torc::generic::VectorNetBit, torc::generic::VectorPortBit, and torc::generic::VectorPortBitReference.

Definition at line 45 of file Connectable.cpp.

46  {
47  outNets.insert(outNets.end(), mConnectedNets.begin(), mConnectedNets.end());
48 }
std::list< NetSharedPtr > mConnectedNets

+ Here is the caller graph for this function:

Pointer torc::generic::SelfReferencing< PortList >::getSharedThis ( ) const
inlineinherited

Get a shared pointer to this object. A valid pointer is returned if weakThis was set. Otherwise this returns a NULL pointer. For Vector types, the second scenario is an exception condition and should be treated as such.

Returns
A shared pointer to this object

Get a shared pointer to this object. A valid pointer is returned if weakThis was set. Otherwise this returns a NULL pointer. For Vector types, the second scenario is an exception condition and should be treated as such.

Parameters
[out]ptrSet to a shared pointer to this object
size_t torc::generic::PortList::getSize ( void  ) const

Get the total number of bits of the composition

Returns
Number of bits

Definition at line 185 of file PortList.cpp.

185  {
186  size_t size = 0;
187  for(std::list<PortListElement>::const_iterator it = mElements.begin(); it != mElements.end();
188  ++it) {
189  switch((*it).getType()) {
191  size += (*it).getPort()->getSize();
192  break;
193  }
195  size += (*it).getPortReference()->getSize();
196  break;
197  }
198  }
199  }
200  return size;
201 }
std::list< PortListElement > mElements
Definition: PortList.hpp:145

+ Here is the caller graph for this function:

void torc::generic::Connectable::onConnect ( )
throw (Error
)
protectedvirtualinherited

A polymorphic function that is called after a net is Connected to this object

Definition at line 144 of file Connectable.cpp.

144 {}
void torc::generic::Connectable::onDisconnect ( )
throw (Error
)
protectedvirtualinherited

A polymorphic function that is called after a net is Disconnected from this object

Definition at line 149 of file Connectable.cpp.

149 {}
void torc::generic::SelfReferencing< PortList >::setWeakThis ( const WeakPointer inWeakThis)
inlineinherited

Set a weak pointer to this object. This will be used later to get a shared pointer to this object from within other member methods if required. This should be called by the Factory creating the object.

Parameters
[in]weakThisA weak pointer to this object
Connectable::Connected & torc::generic::Connectable::signalNetConnected ( )
inlineinherited

A signal to indicate that a new connection has been made

Definition at line 167 of file Connectable.hpp.

167  {
168  return mSigNetConnected;
169 }
Connectable::Disconnected & torc::generic::Connectable::signalNetDisconnected ( )
inlineinherited

A signal to indicate that a new connection has been made

Definition at line 174 of file Connectable.hpp.

174  {
175  return mSigNetDisconnected;
176 }
Disconnected mSigNetDisconnected

Friends And Related Function Documentation

friend class FactoryType< PortList >
friend

Definition at line 48 of file PortList.hpp.

Field Documentation

std::list<PortListElement> torc::generic::PortList::mElements
private

Definition at line 145 of file PortList.hpp.


The documentation for this class was generated from the following files: