torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InterfaceJoinedInfo.cpp
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 
17 #include "torc/generic/Port.hpp"
19 
20 namespace torc {
21 namespace generic {
22 
23 /**
24  * Create an interface joining information .
25  *
26  * @param[in] inPorts List of ports to this joining information.
27  * @param[in] inPortLists List of portLists to this joining information.
28  * @param[in] inViewPtr Pointer to parented(View) object.
29  * @param[in] inParentJoinedInfo Pointer to parent joining information.
30  *
31  * @return Pointer to created interface joining information.
32  */
34  const std::list<PortSharedPtr>& inPorts, const std::list<PortListSharedPtr>& inPortLists,
35  const ViewSharedPtr& inViewPtr, const InterfaceJoinedInfoSharedPtr& inParentJoinedInfo)
36  throw (Error) {
37  try {
38  InterfaceJoinedInfoSharedPtr newInterfaceJoinedInfo;
39  create(newInterfaceJoinedInfo);
40  newInterfaceJoinedInfo->setPorts(inPorts);
41  if(inParentJoinedInfo) {
42  inParentJoinedInfo->addChildJoinedInfo(newInterfaceJoinedInfo);
43  } else if(inViewPtr) {
44  inViewPtr->addInterfaceJoinedInfo(newInterfaceJoinedInfo);
45  }
46  return newInterfaceJoinedInfo;
47  } catch(Error& e) {
48  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
49  throw;
50  }
51 }
52 
53 /**
54  * Set the interface joining type
55  * @param[in] inSource Interface joining type
56  */
58  mJoinedType = value;
59 }
60 
61 /**
62  * Add a port to the list of ports. Empty pointer is ignored.
63  *
64  * @param[in] inPort Pointer to port to be added.
65  * @exception Error Could not add port, because Port name is empty
66  */
67 void InterfaceJoinedInfo::addPort(const PortSharedPtr& inPort) throw (Error) {
68  if(!inPort) {
69  return;
70  }
71  std::string name = inPort->getName();
72  if(name.empty()) {
73  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
74  e.saveContextData("Port name", name);
75  throw e;
76  }
77  mJoinedPorts.push_back(inPort);
78 }
79 
80 /**
81  * Add a portList to the list of portLists. Empty pointer is ignored.
82  *
83  * @param[in] inPortList Pointer to portList to be added.
84  */
86  if(!inPortList) {
87  return;
88  }
89  mJoinedPortLists.push_back(inPortList);
90 }
91 
92 /**
93  * Set the list of joined ports of an interface
94  *
95  * @param[in] inSource List of ports to be joined to an interface
96  */
97 void InterfaceJoinedInfo::setPorts(const std::list<PortSharedPtr>& inSource) {
98  std::list<PortSharedPtr>::const_iterator port = inSource.begin();
99  std::list<PortSharedPtr>::const_iterator end = inSource.end();
100  for(; port != end; ++port) {
101  try {
102  addPort(*port);
103  } catch(Error& e) {
104  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
105  throw;
106  }
107  }
108 }
109 
110 /**
111  * Set the list of joined portLists of an interface
112  *
113  * @param[in] inSource List of portLists to be joined to an interface
114  */
115 void InterfaceJoinedInfo::setPortLists(const std::list<PortListSharedPtr>& inSource) {
116  std::list<PortListSharedPtr>::const_iterator portList = inSource.begin();
117  std::list<PortListSharedPtr>::const_iterator end = inSource.end();
118  for(; portList != end; ++portList) {
119  try {
120  addPortList(*portList);
121  } catch(Error& e) {
122  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
123  throw;
124  }
125  }
126 }
127 
128 /**
129  * Set the nested joining information
130  *
131  * @param[in] inSource Vector containing joining informations
132  * @exception Error Could not add child joined info because
133  * pointer to the joined info does not exist
134  */
135 void InterfaceJoinedInfo::setChildren(const std::vector<InterfaceJoinedInfoSharedPtr>& inSource) {
136  std::vector<InterfaceJoinedInfoSharedPtr>::const_iterator entry = inSource.begin();
137  std::vector<InterfaceJoinedInfoSharedPtr>::const_iterator end = inSource.end();
138  for(; entry != end; ++entry) {
139  try {
140  addChildJoinedInfo(*entry);
141  } catch(Error& e) {
142  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
143  throw;
144  }
145  }
146 }
147 
148 /**
149  * Add a joined info to parent joined info
150  *
151  * @param[in] inChildJoinInfo Child interface joined info to be added to parent
152  */
154  if(!inChildJoinInfo) {
155  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
156  e.saveContextData("Pointer to the joined info object does not exist", inChildJoinInfo);
157  throw e;
158  }
159  if(inChildJoinInfo) {
160  mChildren.push_back(inChildJoinInfo);
161  return true;
162  } else {
163  return false;
164  }
165 }
166 
168  try {
169  runVisitor(*this, visitor);
170  } catch(Error& e) {
171  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
172  throw;
173  }
174 }
175 
176 /**
177  * Set the relation type.
178  *
179  * @param[in] inSource RelationType
180  */
182  mRelationType = inSource;
183 }
184 
185 /**
186  * Get the total number of bits of the composition
187  * @return Number of bits
188  */
190  size_t size = 0;
191  size_t pSize = 0;
192  size_t cSize = 0;
194 
195  std::vector<InterfaceJoinedInfoSharedPtr> outJoinedInfos;
196  getChildren(outJoinedInfos);
197  std::vector<InterfaceJoinedInfoSharedPtr>::iterator joinedInfoIt = outJoinedInfos.begin();
198 
199  std::list<PortSharedPtr> outPorts;
200  getPorts(outPorts);
201  std::list<PortSharedPtr>::iterator portIt = outPorts.begin();
202 
203  std::list<PortListSharedPtr> outPortLists;
204  getPortLists(outPortLists);
205  std::list<PortListSharedPtr>::iterator portListIt = outPortLists.begin();
206 
208  if(!outPorts.empty()) {
209  pSize = (*portIt)->getSize();
210  } else if(!outPortLists.empty()) {
211  pSize = (*portListIt)->getSize();
212  } else if(!outJoinedInfos.empty()) {
213  for(; joinedInfoIt != outJoinedInfos.end(); joinedInfoIt++) {
214  pSize += (*joinedInfoIt)->getSize();
215  for(; portIt != outPorts.end(); portIt++) {
216  pSize += (*portIt)->getSize();
217  }
218  for(; portListIt != outPortLists.end(); portListIt++) {
219  pSize += (*portListIt)->getSize();
220  }
221  }
222  } else {
223  pSize = 0;
224  }
225  } else {
226  if(!outPorts.empty()) {
227  for(; portIt != outPorts.end(); portIt++) {
228  cSize += (*portIt)->getSize();
229  }
230  }
231  if(!outPortLists.empty()) {
232  for(; portListIt != outPortLists.end(); portListIt++) {
233  cSize += (*portListIt)->getSize();
234  }
235  }
236  if(!outJoinedInfos.empty()) {
237  for(; joinedInfoIt != outJoinedInfos.end(); joinedInfoIt++) {
238  cSize += (*joinedInfoIt)->getSize();
239  }
240  }
241  }
242  size = pSize + cSize;
243  return size;
244 }
245 
247  mJoinedType(), mRelationType(), mJoinedPorts(), mJoinedPortLists(), mChildren() {}
248 
250 
251 } // namespace generic
252 } // namespace torc
void getPortLists(std::list< PortListSharedPtr > &outPortLists) const
std::list< PortListSharedPtr > mJoinedPortLists
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
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 saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
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
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)