torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PortList.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_PORTLIST_HPP
17 #define TORC_GENERIC_PORTLIST_HPP
18 
19 //BOOST
20 #ifdef GENOM_SERIALIZATION
21 #include <boost/serialization/access.hpp>
22 #endif //GENOM_SERIALIZATION
23 #include <list>
24 
30 
31 namespace torc { namespace generic { class PortElement; } }
32 
33 namespace torc {
34 namespace generic {
35 
36 /**
37  * @brief Represents an ordered list of port references.
38  *
39  * The PortList class represents an ordered list of port references.
40  * Such objects in EDIF are declard using the (portList portRefName1 portRefName2 ... ) syntax.
41  */
42 
43 class PortList : public Connectable, public SelfReferencing<PortList> {
44 
45 #ifdef GENOM_SERIALIZATION
46  friend class boost::serialization::access;
47 #endif //GENOM_SERIALIZATION
48  friend class FactoryType<PortList> ;
49 
50 public:
52 
54 
55  /**
56  * Convenience class to create a port list.
57  */
58  class Factory : public FactoryType<PortList> {
59  public:
61  /**
62  * Create a port list.
63  *
64  * @param[in] inPorts List of ports to this composition.
65  * @param[in] inPortReferences List of port references to this composition.
66  *
67  * @return Pointer to created port list.
68  */
69  virtual PortListSharedPtr newPortListPtr(const std::list<PortSharedPtr>& inPorts,
70  const std::list<PortReferenceSharedPtr>& inPortReferences) throw (Error);
71  };
72 
73  /**
74  * Receive a visitor to this class. The visit method of the visitor is called
75  * and a reference to this object is passed as a parameter. It has to be noted however,
76  * that a dynamic_cast is performed inside this method. If the cast fails,
77  * an appropriate exception is thrown by this method. This situation can arise when
78  * the passed Visitor object does not inherit from the appropriate visitor specialization.
79  * See Visitor documentation for more details.
80  *
81  * @param[in,out] inoutVisitor A reference to the visitor object
82  * @exception Error Visitor type inappropriate for visiting this object
83  * or any other error thrown by the Visitor::throw() method.
84  */
85  virtual void accept(BaseVisitor& inoutVisitor) throw (Error);
86 
87  /**
88  * Connect a Net to this object.
89  *
90  * @param[in] inNet A pointer to the Net object that needs to be connected
91  * @return A connection that has been established. This can be used later for disconnection.
92  */
93  virtual Connection connect(const NetSharedPtr& inNet) throw (Error);
94 
96 
97  /**
98  * Disconnect a Net from this object.
99  *
100  * @param[in] inConnection A connection as returned by the connect() method
101  * @exception Error Provided connection is invalid
102  */
103 
104  virtual void disconnect(const Connection& inConnection) throw (Error);
105 
106  /**
107  * Get the total number of bits of the composition
108  * @return Number of bits
109  */
110  size_t getSize() const;
111 
112  /**
113  * Add a port to the port list.
114  *
115  * @param[in] inPort Pointer to port to be added.
116  */
117  void addChildPort(const PortSharedPtr& inPort);
118 
119  /**
120  * Add a port reference to the port list.
121  *
122  * @param[in] inPortRef Pointer to port reference to be added.
123  */
124  void addChildPortReference(const PortReferenceSharedPtr& inPortRef);
125 
126  /**
127  * Get all the children of this composition
128  * @return[out] outPorts List containing all children
129  */
130  void getChildren(std::list<PortListElement>& outPorts);
131 
132  virtual ~PortList() throw ();
133 
134 protected:
135  PortList();
136 
137 private:
138  template <typename _Tp> void connectElementToNet(const NetSharedPtr& inNet,
139  const boost::shared_ptr<_Tp>& inType, size_t& inoutCurrentWidth) throw (Error);
140 
141 #ifdef GENOM_SERIALIZATION
142  template <class Archive> void serialize(Archive& ar, unsigned int);
143 #endif //GENOM_SERIALIZATION
144 private:
145  std::list<PortListElement> mElements;
146 };
147 
148 } // namespace generic
149 } // namespace torc
150 
151 #endif // TORC_GENERIC_PORTLIST_HPP
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
void getChildren(std::list< PortListElement > &outPorts)
Definition: PortList.cpp:211
Represents port element like port or port reference.
Definition: PortElement.hpp:32
An object that is connectable to a Net.
Definition: Connectable.hpp:44
virtual PortListSharedPtr newPortListPtr(const std::list< PortSharedPtr > &inPorts, const std::list< PortReferenceSharedPtr > &inPortReferences)
Definition: PortList.cpp:45
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
size_t getSize() const
Definition: PortList.cpp:185
void connectElementToNet(const NetSharedPtr &inNet, const boost::shared_ptr< _Tp > &inType, size_t &inoutCurrentWidth)
Definition: PortList.cpp:74
void addChildPortReference(const PortReferenceSharedPtr &inPortRef)
Definition: PortList.cpp:207
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
boost::shared_ptr< Net > NetSharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
boost::shared_ptr< PortReference > PortReferenceSharedPtr
boost::shared_ptr< PortList > PortListSharedPtr
VisitorType< PortList > Visitor
Definition: PortList.hpp:53
Represents an ordered list of port references.
Definition: PortList.hpp:43
virtual void accept(BaseVisitor &inoutVisitor)
Definition: PortList.cpp:65
boost::shared_ptr< Port > PortSharedPtr
virtual Connection connect(const NetSharedPtr &inNet)
Definition: PortList.cpp:140
A placeholder for a factory method.
Definition: FactoryType.hpp:35
void addChildPort(const PortSharedPtr &inPort)
Definition: PortList.cpp:203
PortElement PortListElement
Definition: PortList.hpp:51
std::list< PortListElement > mElements
Definition: PortList.hpp:145