torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Simulate.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 
18 #include "torc/generic/Apply.hpp"
20 #include "torc/generic/View.hpp"
21 
22 namespace torc {
23 namespace generic {
24 
25 /**
26  * Create a simulate.
27  *
28  * @param[in] inName Name of the simulate to be created.
29  * @param[in] inPortListAliases Vector of port list aliases to this simulate.
30  * @param[in] inAllApply Vector of apply to this simulate.
31  * @param[in] inWaveValues Vector of WaveValues to this simulate.
32  * @param[in] inView Pointer to parented (view) object.
33  * @param[in] inOriginalName Original name of the simulate [optional].
34  * @param[in] inInterfaceAttributes Pointer to
35  * parented (InterfaceAttributes) object [optional]. If mentioned then this
36  * will decompile within (contents ...) construct.
37  *
38  * @return Pointer to created simulate.
39  */
41  const std::vector<PortListAliasSharedPtr>& inPortListAliases,
42  const std::vector<ApplySharedPtr>& inAllApply,
43  const std::vector<WaveValueSharedPtr>& inWaveValues, const ViewSharedPtr& inView,
44  const std::string& inOriginalName, const InterfaceAttributesSharedPtr& inInterfaceAttributes)
45  throw (Error) {
46  try {
47  SimulateSharedPtr newSimulate;
48  create(newSimulate);
49  newSimulate->setName(inName);
50  newSimulate->setPortListAliases(inPortListAliases);
51  newSimulate->setAllApply(inAllApply);
52  newSimulate->setWaveValues(inWaveValues);
53  newSimulate->setOriginalName(inOriginalName);
54  if(inInterfaceAttributes) {
55  inInterfaceAttributes->setSimulate(newSimulate);
56  inView->setInterfaceAttributes(inInterfaceAttributes);
57  } else {
58  inView->setSimulate(newSimulate);
59  }
60  return newSimulate;
61  } catch(Error& e) {
62  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
63  throw;
64  }
65 }
66 
67 void Simulate::accept(BaseVisitor& inoutVisitor) throw (Error) {
68  try {
69  runVisitor(*this, inoutVisitor);
70  } catch(Error& e) {
71  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
72  throw;
73  }
74 }
75 
76 /**
77  * Add a port list alias to the symbol table of port list alias.
78  * If an empty pointer is supplied, it returns without doing anything.
79  *
80  * @param[in] inPortListAlias A pointer to a port list alias object.
81  *
82  * @exception Error PortListAlias could not be added, empty PortListAlias name
83  * @exception Error PortListAlias already exists in simulate
84  */
85 void Simulate::addPortListAlias(const PortListAliasSharedPtr& inPortListAlias) throw (Error) {
86  if(!inPortListAlias) {
87  return;
88  }
89  std::string name = inPortListAlias->getName();
90  if(name.empty()) {
91  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
92  e.saveContextData("Empty port list alias name ", name);
93  throw e;
94  }
95  if(false == mPortListAliasSymTab.set(name, inPortListAlias)) {
96  Error e(eMessageIdErrorItemAlreadyExists, __FUNCTION__, __FILE__, __LINE__);
97  e.saveContextData("Port list alias name", name);
98  throw e;
99  }
100 }
101 
102 /**
103  * Set all the PortListAlias of this simulation.
104  *
105  * @param[in] inPortListAliases Vector of PortListAlias to be appended to
106  */
107 void Simulate::setPortListAliases(const std::vector<PortListAliasSharedPtr>& inPortListAliases)
108  throw (Error) {
109  std::vector<PortListAliasSharedPtr>::const_iterator it = inPortListAliases.begin();
110  for(; it != inPortListAliases.end(); it++) {
111  try {
112  addPortListAlias(*it);
113  } catch(Error& e) {
114  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
115  throw;
116  }
117  }
118 }
119 
120 /**
121  * Find a PortListAlias by name, in the symbol table of port list alias.
122  *
123  * @param[in] inName String specifying the name of the PortListAlias.
124  *
125  * @return A pointer to the PortListAlias if found, an empty pointer otherwise.
126  */
128  if(inName.empty()) {
129  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
130  e.saveContextData("Empty PortListAlias name", inName);
131  throw e;
132  }
133  PortListAliasSharedPtr portListAlias;
134  mPortListAliasSymTab.get(inName, portListAlias);
135  return portListAlias;
136 }
137 
138 /**
139  * Add an apply to the vector of Apply objects.
140  *
141  * @param[in] inSource Pointer to Apply object to be appended to
142  */
143 void Simulate::addApply(const ApplySharedPtr& inSource) throw (Error) {
144  try {
145  mAllApply.push_back(inSource);
146  } catch(Error& e) {
147  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
148  throw;
149  }
150 }
151 
152 /**
153  * Set all the apply objects.
154  *
155  * @param[in] inAllApply Vector of apply objects to be appended to
156  */
157 void Simulate::setAllApply(const std::vector<ApplySharedPtr>& inAllApply) throw (Error) {
158  std::vector<ApplySharedPtr>::const_iterator it = inAllApply.begin();
159  for(; it != inAllApply.end(); it++) {
160  try {
161  addApply(*it);
162  } catch(Error& e) {
163  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
164  throw;
165  }
166  }
167 }
168 
169 /**
170  * Set the vector of wave values.
171  *
172  * @param[in] inWaveValues Vector of wave values to be appended to
173  */
174 void Simulate::setWaveValues(const std::vector<WaveValueSharedPtr>& inWaveValues) throw (Error) {
175  std::vector<WaveValueSharedPtr>::const_iterator it = inWaveValues.begin();
176  for(; it != inWaveValues.end(); it++) {
177  try {
178  addWaveValue(*it);
179  } catch(Error& e) {
180  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
181  throw;
182  }
183  }
184 }
185 
186 /**
187  * A dd a wave value to the symbol table of wave values.
188  *
189  * @param[in] inSource Pointer to WaveValue to be appended to
190  *
191  * @exception Error WaveValue could not be added, empty WaveValue name
192  * @exception Error WaveValue already exists in simulate
193  */
194 void Simulate::addWaveValue(const WaveValueSharedPtr& inSource) throw (Error) {
195  if(!inSource) {
196  return;
197  }
198  std::string name = inSource->getName();
199  if(name.empty()) {
200  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
201  e.saveContextData("Empty WaveValue name ", name);
202  throw e;
203  }
204  if(false == mWaveValueSymTab.set(name, inSource)) {
205  Error e(eMessageIdErrorItemAlreadyExists, __FUNCTION__, __FILE__, __LINE__);
206  e.saveContextData("WaveValue name", name);
207  throw e;
208  }
209 }
210 
211 /**
212  * Find a WaveValue by name, in the symbol table of port list alias.
213  *
214  * @param[in] inName String specifying the name of the WaveValue.
215  *
216  * @return A pointer to the WaveValue if found, an empty pointer otherwise.
217  */
219  if(inName.empty()) {
220  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
221  e.saveContextData("Empty WaveValue name", inName);
222  throw e;
223  }
224  WaveValueSharedPtr waveValue;
225  mWaveValueSymTab.get(inName, waveValue);
226  return waveValue;
227 }
228 
230  SelfReferencing<Simulate>(), UserDataContainer(), mPortListAliasSymTab(), mWaveValueSymTab(),
231  mAllApply() {}
232 
233 Simulate::~Simulate() throw () {}
234 
235 } // namespace generic
236 } // namespace torc
WaveValueSharedPtr findWaveValue(const std::string &inName)
Definition: Simulate.cpp:218
boost::shared_ptr< WaveValue > WaveValueSharedPtr
void addPortListAlias(const PortListAliasSharedPtr &inPortListAlias)
Definition: Simulate.cpp:85
Represents all classes that can hold user comments.
Definition: Commentable.hpp:36
Represents class that can hold userData.
boost::shared_ptr< Simulate > SimulateSharedPtr
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
PortListAliasSharedPtr findPortListAlias(const std::string &inName)
Definition: Simulate.cpp:127
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
A base class for Visitor.
Definition: VisitorType.hpp:31
void addApply(const ApplySharedPtr &inSource)
Definition: Simulate.cpp:143
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
SymTab< std::string, PortListAliasSharedPtr > mPortListAliasSymTab
Definition: Simulate.hpp:203
boost::shared_ptr< Apply > ApplySharedPtr
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
virtual SimulateSharedPtr newSimulatePtr(const std::string &inName, const std::vector< PortListAliasSharedPtr > &inPortListAliases, const std::vector< ApplySharedPtr > &inAllApply, const std::vector< WaveValueSharedPtr > &inWaveValues, const ViewSharedPtr &inView, const std::string &inOriginalName=std::string(), const InterfaceAttributesSharedPtr &inInterfaceAttributes=InterfaceAttributesSharedPtr())
Definition: Simulate.cpp:40
void setWaveValues(const std::vector< WaveValueSharedPtr > &inWaveValues)
Definition: Simulate.cpp:174
boost::shared_ptr< InterfaceAttributes > InterfaceAttributesSharedPtr
SymTab< std::string, WaveValueSharedPtr > mWaveValueSymTab
Definition: Simulate.hpp:204
boost::shared_ptr< View > ViewSharedPtr
An object that has a name.
Definition: Nameable.hpp:34
boost::shared_ptr< PortListAlias > PortListAliasSharedPtr
virtual void accept(BaseVisitor &inoutVisitor)
Definition: Simulate.cpp:67
Represents objects that can be renamed.
void setAllApply(const std::vector< ApplySharedPtr > &inAllApply)
Definition: Simulate.cpp:157
This class is to model simulate construct which is a named collection of simulation stimulus and resp...
Definition: Simulate.hpp:46
void setPortListAliases(const std::vector< PortListAliasSharedPtr > &inPortListAliases)
Definition: Simulate.cpp:107
void addWaveValue(const WaveValueSharedPtr &inSource)
Definition: Simulate.cpp:194
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