torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InterfaceJoinedInfo.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_INTERFACEJOINEDINFO_HPP
17 #define TORC_GENERIC_INTERFACEJOINEDINFO_HPP
18 
20 #include "torc/generic/Error.hpp"
25 
26 #include <list>
27 #include <vector>
28 
29 namespace torc { namespace generic { class Port; } }
30 namespace torc { namespace generic { class PortList; } }
31 namespace torc { namespace generic { class BaseVisitor; } }
32 
33 namespace torc {
34 namespace generic {
35 
36 /**
37  * @brief Represents the Interface joining information.
38  *
39  * The InterfaceJoinedInfo class is used to hold interface joining information.
40  * Joining information specify which ports (scalar port, array of ports, bundle of ports)
41  * or port lists are shorted together.
42  */
43 class InterfaceJoinedInfo : public Visitable, public SelfReferencing<InterfaceJoinedInfo> {
45 
46 public:
47  /**
48  * @enum JoinedType
49  * Interface joining type
50  */
51  enum JoinedType {
53  };
54 
55  /**
56  * @enum RelationType
57  *
58  * Type of the InterfaceJoinedInfo, Is it parent or child.
59  */
60  enum RelationType {
62  };
63 
64  /**
65  * Convenience class to visit an interface joining information.
66  */
68 
69  /**
70  * Convenience class to create an interface joining information.
71  */
72  class Factory : public FactoryType<InterfaceJoinedInfo> {
73  public:
75  /**
76  * Create an interface joining information .
77  *
78  * @param[in] inPorts List of ports to this joining information.
79  * @param[in] inPortLists List of portLists to this joining information.
80  * @param[in] inViewPtr Pointer to parented(View) object.
81  * @param[in] inParentJoinedInfo Pointer to parent joining information.
82  *
83  * @return Pointer to created interface joining information.
84  */
86  const std::list<PortSharedPtr>& inPorts,
87  const std::list<PortListSharedPtr>& inPortLists, const ViewSharedPtr& inViewPtr,
88  const InterfaceJoinedInfoSharedPtr& inParentJoinedInfo = InterfaceJoinedInfoSharedPtr())
89  throw (Error);
90  };
91 
92  /**
93  * @brief Receive a visitor to this class.
94  * The visit method of the visitor is called and a reference to this
95  * object is passed as a parameter. It has to be noted however,
96  * that a dynamic_cast is performed inside this method. If the cast fails,
97  * an appropriate exception is thrown by this method. This situation can arise
98  * when the passed Visitor object does not inherit from the appropriate
99  * visitor specialization. See Visitor documentation for more details.
100  *
101  * @param[in,out] visitor A reference to the visitor object
102  * @exception Error Visitor type inappropriate for visiting this object
103  * or any other error thrown by the Visitor::throw() method.
104  */
105  virtual void accept(BaseVisitor& visitor) throw (Error);
106 
107  /**
108  * Get the interface joining type
109  *
110  * @return Interface joining type
111  */
112  inline const JoinedType getJoinedType() const;
113 
114  /**
115  * Set the interface joining type
116  *
117  * @param[in] inSource Interface joining type
118  */
119  void setJoinedType(const JoinedType& inSource);
120 
121  /**
122  * Add a port to the list of ports. Empty pointer is ignored.
123  *
124  * @param[in] inPort Pointer to port to be added.
125  * @exception Error Could not add port, because Port name is empty
126  */
127  void addPort(const PortSharedPtr& inPort) throw (Error);
128 
129  /**
130  * Get the list of pointers to the joined ports of an interface
131  *
132  * @return outPorts List of ports to be appended to
133  */
134  inline void getPorts(std::list<PortSharedPtr>& outPorts) const;
135 
136  /**
137  * Set the list of joined ports of an interface
138  *
139  * @param[in] inSource List of ports to be joined to an interface
140  */
141  void setPorts(const std::list<PortSharedPtr>& inSource);
142 
143  /**
144  * Add a portList to the list of portLists. Empty pointer is ignored.
145  *
146  * @param[in] inPortList Pointer to portList to be added.
147  */
148  void addPortList(const PortListSharedPtr& inPortList);
149 
150  /**
151  * Get the list of joined portLists of an interface
152  *
153  * @return outPortLists List of joined portLists to be appended to
154  */
155  inline void getPortLists(std::list<PortListSharedPtr>& outPortLists) const;
156 
157  /**
158  * Set the list of joined portLists of an interface
159  *
160  * @param[in] inSource List of portLists to be joined to an interface
161  */
162  void setPortLists(const std::list<PortListSharedPtr>& inSource);
163 
164  /**
165  * Get the nested interface joined info.
166  *
167  * @param[out] outJoinedInfos Vector of interface joined info to be appended to
168  */
169  inline void getChildren(std::vector<InterfaceJoinedInfoSharedPtr> & outJoinedInfos) const;
170 
171  /**
172  * Set the nested joining information
173  *
174  * @param[in] inSource Vector containing joining informations
175  * @exception Error Could not add child joined info because
176  * pointer to the joined info does not exist
177  */
178  void setChildren(const std::vector<InterfaceJoinedInfoSharedPtr> & inSource);
179 
180  /**
181  * Add a joined info to parent joined info
182  *
183  * @param[in] inChildJoinInfo Child interface joined info to be added to parent
184  */
185  bool addChildJoinedInfo(const InterfaceJoinedInfoSharedPtr& inChildJoinInfo);
186 
187  /**
188  * Apply action on all children
189  * @param[in] action Action to be applied
190  */
191  template <typename _Action> inline void applyOnAllChildren(const _Action& action) throw (Error);
192 
193  /**
194  * Get the relation type.
195  *
196  * @return RelationType
197  */
198  inline const RelationType getRelationType() const;
199 
200  /**
201  * Set the relation type.
202  *
203  * @param[in] inSource RelationType
204  */
205  void setRelationType(const RelationType& inSource);
206 
207  /**
208  * Get the total number of bits of the composition
209  * @return Number of bits
210  */
211  size_t getSize() const;
212 
213  virtual ~InterfaceJoinedInfo() throw ();
214 
215 protected:
217 
218 private:
224 
225 };
226 
227 /**
228  * Get the interface joining type
229  *
230  * @return Interface joining type
231  */
232 inline const InterfaceJoinedInfo::JoinedType InterfaceJoinedInfo::getJoinedType() const {
233  return mJoinedType;
234 }
235 
236 /**
237  * Get the list of pointers to the joined ports of an interface
238  *
239  * @return outPorts List of ports to be appended to
240  */
241 inline void InterfaceJoinedInfo::getPorts(std::list<PortSharedPtr>& outPorts) const {
242  outPorts.insert(outPorts.end(), mJoinedPorts.begin(), mJoinedPorts.end());
243 }
244 
245 /**
246  * Get the list of joined portLists of an interface
247  *
248  * @return outPorts List of joined portLists to be appended to
249  */
250 inline void InterfaceJoinedInfo::getPortLists(std::list<PortListSharedPtr>& outPortLists) const {
251  outPortLists.insert(outPortLists.end(), mJoinedPortLists.begin(), mJoinedPortLists.end());
252 }
253 
254 /**
255  * Get the nested interface joined info.
256  *
257  * @param[out] outJoinedInfos Vector of interface joined info to be appended to
258  */
260  std::vector<InterfaceJoinedInfoSharedPtr> & outJoinedInfos) const {
261  outJoinedInfos.insert(outJoinedInfos.end(), mChildren.begin(), mChildren.end());
262 }
263 
264 /**
265  * Apply action on all children
266  * @param[in] action Action to be applied
267  */
268 template <typename _Action> inline void InterfaceJoinedInfo::applyOnAllChildren(
269  const _Action& action) throw (Error) {
270  try {
271  std::vector<InterfaceJoinedInfoSharedPtr>::iterator it = mChildren.begin();
272  for(; it != mChildren.end(); ++it) {
273  action(*it);
274  }
275  } catch(Error& e) {
276  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
277  throw;
278  }
279 }
280 
281 /**
282  * Get the relation type.
283  *
284  * @return RelationType
285  */
287  return mRelationType;
288 }
289 
290 } // namespace generic
291 } // namespace torc
292 #endif // TORC_GENERIC_INTERFACEJOINEDINFO_HPP
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
void applyOnAllChildren(const _Action &action)
void getPortLists(std::list< PortListSharedPtr > &outPortLists) const
std::list< PortSharedPtr > mJoinedPorts
const JoinedType getJoinedType() const
std::list< PortListSharedPtr > mJoinedPortLists
void addPort(const PortSharedPtr &inPort)
virtual InterfaceJoinedInfoSharedPtr newInterfaceJoinedInfoPtr(const std::list< PortSharedPtr > &inPorts, const std::list< PortListSharedPtr > &inPortLists, const ViewSharedPtr &inViewPtr, const InterfaceJoinedInfoSharedPtr &inParentJoinedInfo=InterfaceJoinedInfoSharedPtr())
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void setRelationType(const RelationType &inSource)
A base class for Visitor.
Definition: VisitorType.hpp:31
Represents the Interface joining information.
bool addChildJoinedInfo(const InterfaceJoinedInfoSharedPtr &inChildJoinInfo)
boost::shared_ptr< PortList > PortListSharedPtr
void setPortLists(const std::list< PortListSharedPtr > &inSource)
void addPortList(const PortListSharedPtr &inPortList)
void getChildren(std::vector< InterfaceJoinedInfoSharedPtr > &outJoinedInfos) const
boost::shared_ptr< View > ViewSharedPtr
boost::shared_ptr< InterfaceJoinedInfo > InterfaceJoinedInfoSharedPtr
void setJoinedType(const JoinedType &inSource)
boost::shared_ptr< Port > PortSharedPtr
const RelationType getRelationType() const
std::vector< InterfaceJoinedInfoSharedPtr > mChildren
void getPorts(std::list< PortSharedPtr > &outPorts) const
A placeholder for a factory method.
Definition: FactoryType.hpp:35
VisitorType< InterfaceJoinedInfo > Visitor
void setChildren(const std::vector< InterfaceJoinedInfoSharedPtr > &inSource)
virtual void accept(BaseVisitor &visitor)
Receive a visitor to this class. The visit method of the visitor is called and a reference to this ob...
An object that receives an inoutVisitor.
Definition: Visitable.hpp:38
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73
void setPorts(const std::list< PortSharedPtr > &inSource)