torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Linker.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 
19 namespace {
20 
21 using namespace torc::generic;
22 
23 class LinkAction
24 {
25  public:
26  LinkAction(const ViewSharedPtr& inView)
27  :mView(inView) {
28  }
29 
30  void
31  operator()( const InstanceSharedPtr& outInstance
32  ) const throw(Error) {
33  try
34  {
35  outInstance->bindToMasterView(mView);
36  }
37  catch(Error& e)
38  {
39  e.setCurrentLocation( __FUNCTION__,
40  __FILE__, __LINE__ );
41  throw;
42  }
43  }
44  private:
45  ViewSharedPtr mView;
46 };
47 }
48 
49 namespace torc {
50 
51 namespace generic {
52 
54  :mLibraryName(),
55  mCellName(),
56  mViewName() {}
57 
59  const std::string& inCellName,
60  const std::string& inViewName )
61  : mLibraryName(inLibraryName),
62  mCellName(inCellName),
63  mViewName(inViewName) {}
64 
66 
68  :mLibraryName(inSource.mLibraryName),
69  mCellName(inSource.mCellName),
70  mViewName(inSource.mViewName) {}
71 
74  const Linker::NameSpec& inSource) {
75  if(this != &inSource)
76  {
77  mLibraryName = inSource.mLibraryName;
78  mCellName = inSource.mCellName;
79  mViewName = inSource.mViewName;
80  }
81  return *this;
82 }
83 
84 void
86  const std::string& inValue) {
87  mLibraryName = inValue;
88 }
89 
90 void
92  mCellName = inValue;
93 }
94 
95 void
97  mViewName = inValue;
98 }
99 
100 void
102  const ViewSharedPtr& inValue) {
103  mExternView = inValue;
104 }
105 
106 void
108  const InstanceSharedPtr& inInstance) {
109  mInstances.push_back(inInstance);
110 }
111 
112 void
114  const std::vector< InstanceSharedPtr >& inValue
115  ) {
116  mInstances = inValue;
117 }
118 
120  :mExternView(),
121  mInstances() {}
122 
124 
126  const Linker::UnresolvedInstances& inSource)
127  :mExternView(inSource.mExternView),
128  mInstances(inSource.mInstances) {}
129 
132  const Linker::UnresolvedInstances& inSource) {
133  if(this != &inSource)
134  {
135  mExternView = inSource.mExternView;
136  mInstances = inSource.mInstances;
137  }
138  return *this;
139 }
140 
141 /**
142  * Find the extern View if already present. Otherwise null
143  *
144  * @param[in] inNameSpec Name of the view
145  *
146  * @return Extern view
147  */
150  const Linker::NameSpec& inNameSpec) {
152  mInfos.get(inNameSpec, info);
153  if(info)
154  {
155  return info->getExternView();
156  }
157  return ViewSharedPtr();
158 }
159 
160 /**
161  * Set an extern View
162  *
163  * @param[in] inNameSpec Name of the view
164  * @param[in] externView an Extern View
165  */
166 void
168  const Linker::NameSpec& inNameSpec,
169  const ViewSharedPtr& inExternView) {
171  mInfos.get(inNameSpec, info);
172  if(!info)
173  {
175  mInfos.set(inNameSpec, info);
176  }
177  info->setExternView(inExternView);
178  return;
179 }
180 
181 /**
182  * Find the list of instances that are waiting for a view with the specified name.
183  *
184  * @param[in] inNameSpec Name of the view to be linked with.
185  * @param[out] outInstances Pointer to unresolved object
186  *
187  * @return True if such instance exists
188  */
189 bool
191  const Linker::NameSpec& inNameSpec,
192  Linker::UnresolvedInstancesPtr& outInstances) throw(Error) {
193  return mInfos.get(inNameSpec, outInstances);
194 }
195 
196 /**
197  * Add an instance to the list of unresolved instances for a given name specification. If a new UnresolvedInstances object is to be created, this method will also call the setExternView() method to update the externView, with the view set for this object.
198  *
199  * @param[in] inNameSpec name specification for a view.
200  * @param[in] inInstance instance to be added.
201  *
202  * @exception Error The master for this instance is not an extern or no extern is set for this view.
203  */
204 void
206  const Linker::NameSpec& inNameSpec,
207  const InstanceSharedPtr& inInstance) throw(Error) {
209  mInfos.get(inNameSpec, info);
210  if(!info)
211  {
213  mInfos.set(inNameSpec, info);
214  }
215  info->addInstance(inInstance);
216  return;
217 }
218 
219 /**
220  * Remove all unresolved objects for the given name specification.
221  *
222  * @param[in] inNameSpec Name specification
223  */
224 void
226  const Linker::NameSpec& inNameSpec) throw(Error) {
227  mInfos.remove(inNameSpec);
228 }
229 
230 void
232  ViewSharedPtr& inView) throw(Error) {
234  mInfos.get(inNameSpec, info);
235  LinkAction linkAction(inView);
236  if(info)
237  {
238  try
239  {
240  info->applyActionOnInstances(linkAction);
241  }
242  catch(Error& e)
243  {
244  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
245  throw;
246  }
247  removeUnresolvedInstances(inNameSpec);
248  }
249 }
250 
251 /**
252  * Constructor
253  *
254  * @param[in] root Root of the OM.
255  */
257  :mRoot(inRoot),
258  mInfos() {}
259 
260 Linker::~Linker() throw() {}
261 
262 Linker::Linker(const Linker& inSource)
263  : mRoot(inSource.mRoot),
264  mInfos(inSource.mInfos) {}
265 
266 Linker&
267 Linker::operator=(const Linker& inSource) {
268  if(this != &inSource)
269  {
270  mRoot = inSource.mRoot;
271  mInfos = inSource.mInfos;
272  }
273  return *this;
274 }
275 
276 
277 } // namespace generic
278 } // namespace torc
boost::shared_ptr< Instance > InstanceSharedPtr
bool findUnresolvedInstances(const NameSpec &inNameSpec, UnresolvedInstancesPtr &outInstances)
Definition: Linker.cpp:190
Linker(const RootSharedPtr &root)
Definition: Linker.cpp:256
UnresolvedInstances & operator=(const UnresolvedInstances &inSource)
Definition: Linker.cpp:131
NameSpec & operator=(const NameSpec &inSource)
Definition: Linker.cpp:73
Linker & operator=(const Linker &inSource)
Definition: Linker.cpp:267
bool set(const KeyType &inKey, const ValueType &inValue)
Definition: SymTab.hpp:132
bool remove(const KeyType &inKey)
Definition: SymTab.hpp:153
std::string string
void linkUnresolved(const NameSpec &inNameSpec, ViewSharedPtr &inView)
Definition: Linker.cpp:231
RootSharedPtr mRoot
Definition: Linker.hpp:207
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void setExternView(const ViewSharedPtr &inValue)
Definition: Linker.cpp:101
void addInstance(const InstanceSharedPtr &inInstance)
Definition: Linker.cpp:107
void setExternView(const NameSpec &inNameSpec, const ViewSharedPtr &inExternView)
Definition: Linker.cpp:167
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
Represents a repository of unresolved usage references.
Definition: Linker.hpp:51
void setCellName(const std::string &inValue)
Definition: Linker.cpp:91
boost::shared_ptr< View > ViewSharedPtr
ViewSharedPtr findExternView(const NameSpec &inNameSpec)
Definition: Linker.cpp:149
void setLibraryName(const std::string &inValue)
Definition: Linker.cpp:85
void removeUnresolvedInstances(const NameSpec &inNameSpec)
Definition: Linker.cpp:225
std::vector< InstanceSharedPtr > mInstances
Definition: Linker.hpp:128
void setViewName(const std::string &inValue)
Definition: Linker.cpp:96
boost::shared_ptr< UnresolvedInstances > UnresolvedInstancesPtr
Definition: Linker.hpp:131
void registerUnresolvedInstance(const NameSpec &inNameSpec, const InstanceSharedPtr &inInstance)
Definition: Linker.cpp:205
UnresolvedInfoMap mInfos
Definition: Linker.hpp:208
void setInstances(const std::vector< InstanceSharedPtr > &value)
Definition: Linker.cpp:113
boost::shared_ptr< Root > RootSharedPtr
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73