torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Library.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_LIBRARY_HPP
17 #define TORC_GENERIC_LIBRARY_HPP
18 
20 
21 //BOOST
22 #ifdef GENOM_SERIALIZATION
23 #include <boost/serialization/access.hpp>
24 #include <boost/serialization/split_member.hpp>
25 #endif //GENOM_SERIALIZATION
27 #include "torc/generic/Extern.hpp"
29 #include "torc/generic/Error.hpp"
34 #include "torc/generic/Root.hpp"
37 #include "torc/generic/SymTab.hpp"
40 #include "torc/generic/Unit.hpp"
43 
44 namespace torc {
45 namespace generic {
46 class BaseVisitor;
47 
48 class Cell;
49 }
50 }
51 
52 namespace torc {
53 namespace generic {
54 
55 /**
56  * @brief An EDIF cell library
57  *
58  * A Library object defines a collection of EDIF libraries
59  */
60 class Library : public Commentable, public Extern, public Nameable, public Renamable,
61  public Visitable, public ParentedObject<Root>, public SelfReferencing<Library>,
62  public UserDataContainer, public StatusContainer {
63 
64 #ifdef GENOM_SERIALIZATION
65  friend class boost::serialization::access;
66 #endif //GENOM_SERIALIZATION
67  friend class FactoryType<Library> ;
68 
69 public:
70  /**
71  * Convenience typedef for visiting a library
72  */
74 
75  /**
76  * Convenience class for creating a library
77  */
78 
79  class Factory : public FactoryType<Library> {
80  public:
82  /**
83  * Create a library
84  *
85  * @param[in] inName Name of the library to be created.
86  * @param[in] inRootPtr Pointer to parented(Root) object.
87  * @param[in] inEdifLevel Edif level.
88  * @param[in] inOriginalName Original name of the library [optional]
89  *
90  * @return Pointer to created library.
91  **/
92  virtual LibrarySharedPtr newLibraryPtr(const std::string& inName,
93  const RootSharedPtr& inRootPtr, const EdifLevel& inEdifLevel = eEdifLevel0,
94  const std::string& inOriginalName = std::string()) throw (Error);
95  };
96 
97  virtual void accept(BaseVisitor& inoutVisitor) throw (Error);
98 
99  /**
100  * The the level of EDIF file.
101  *
102  * @return The EDIF level for this file
103  */
104  inline const EdifLevel getLevel() const;
105 
106  /**
107  * Set the EDIF level.
108  *
109  * @note Current parser supports LEVEL_1 edif only.
110  *
111  * @param[in] inSource EdifLevel object
112  */
113  void setLevel(const EdifLevel& inSource);
114 
115  /**
116  * Get scale factors for different units in the library.
117  *
118  * @return Scale factors
119  */
120  inline const std::map<Unit, ScaleFactor> getScaleFactors() const;
121 
122  /**
123  * Find a scale factor for the given unit.
124  *
125  * @param[in] inUnit Units for which scale factor is to be found.
126  * @param[out] outResult The scale factor if found.
127  *
128  * @return true if found, false otherwise
129  */
130  bool findScaleFactor(Unit inUnit, ScaleFactor& outResult) const;
131 
132  /**
133  * Set a scale factor for the given unit.
134  *
135  * @param[in] inUnit Units for which scale factor is to be set.
136  * @param[out] inScale The scale factor to store.
137  * @return True if set
138  */
139  bool setScaleFactor(Unit inUnit, const ScaleFactor& inScale);
140 
141  /**
142  * Add a cell to the list of cells. If an empty pointer is supplied, it returns without doing
143  * anything.
144  * If an cell already exists in EDIF file in same library, parser ignores the cell.
145  *
146  * @param[in] inCell A pointer to a cell object.
147  *
148  * @exception Error Cell could not be added, because Cell name is empty
149  * <ul>
150  * <li>
151  * Id : eMessageIdErrorEmptyItemName
152  * </li>
153  * <li> Context Data
154  * <ul>
155  * <li>Cell name - <i>String</i></li>
156  * </ul>
157  * </li>
158  * </ul>
159  *
160  * @exception Error Cell could not be added, because Cell name is already exists
161  * <ul>
162  * <li>
163  * Id : eMessageIdErrorItemAlreadyExists
164  * </li>
165  * <li> Context Data
166  * <ul>
167  * <li>Cell name - <i>String</i></li>
168  * </ul>
169  * </li>
170  * </ul>
171  *
172  */
173  void addCell(const CellSharedPtr& inCell) throw (Error);
174 
175  /**
176  * Find a cell by name, in the list of cells.
177  *
178  * @param[in] inName String inSource specifying the name of the cell.
179  *
180  * @return A pointer to the cell if found, an empty pointer otherwise.
181  * @exception Error Cell could not be found, because Cell name is empty
182  * <ul>
183  * <li>
184  * Id : eMessageIdErrorEmptyItemName
185  * </li>
186  * <li> Context Data
187  * <ul>
188  * <li>Cell name - <i>String</i></li>
189  * </ul>
190  * </li>
191  * </ul>
192  *
193  * @note If some cells are yet to be restored, this method is not thread safe. For
194  * non-serializable mode this is thread safe. For dump mode derived classes can override this
195  * to make it thread safe by placing appropriate locks.
196  */
197  virtual CellSharedPtr findCell(const std::string& inName) throw (Error);
198 
199  /**
200  * Remove the specified cell from the list of cells. If an empty pointer is passed, it returns
201  * without doing anything
202  *
203  * @param inName Name of the object to be delete
204  *
205  * @exception Error Cell name is empty
206  * <ul>
207  * <li>
208  * Id : eMessageIdErrorEmptyItemName
209  * </li>
210  * <li> Context Data
211  * <ul>
212  * <li>Cell name - <i>String</i></li>
213  * </ul>
214  * </li>
215  * </ul>
216  *
217  * @exception Error Cell name not preset in collection.
218  * <ul>
219  * <li>
220  * Id : eMessageIdErrorItemNotFound
221  * </li>
222  * <li> Context Data
223  * <ul>
224  * <li>Cell name - <i>String</i></li>
225  * </ul>
226  * </li>
227  * </ul>
228  *
229  */
230  void removeCell(const std::string& inName) throw (Error);
231 
232  /**
233  * Get the list of cells. The list of cells is appended to the provided list
234  * @param[out] outCells List of cells to be populated
235  * @return List of cells in the library.
236  * @note If some cells are yet to be restored, this method is not thread safe. For
237  * non-serializable mode this is thread safe. For dump mode derived classes can override this
238  * to make it thread safe by placing appropriate locks. In dump mode using this method will
239  * lead to restoration of all children.
240  */
241  virtual void getCells(std::vector<CellSharedPtr>& outCells);
242 
243  /**
244  * Apply action on all Cells.
245  * @param[in] action Action to be applied
246  * @note If some cells are yet to be restored, this method is not thread safe. For
247  * non-serializable mode this is thread safe. For dump mode derived classes can write an
248  * appropriate thread safe wrapper method that can be accesed using visitors. However, using
249  * this method in dump mode should be avoided unless under dire situations, as it will lead to
250  * restoration of all cells under the library.
251  */
252  template <typename _Action> inline void applyOnAllCells(const _Action& action) throw (Error);
253 
254  /**
255  * Get the pointer to the simulation info.
256  *
257  * @return Pointer to the simulation info
258  */
259  inline const SimulationInfoSharedPtr getSimulationInfo() const;
260 
261  /**
262  * Set the pointer to the simulation info.
263  *
264  * @param[in] inSource Pointer to the simulation info
265  */
266  void setSimulationInfo(const SimulationInfoSharedPtr& inSource);
267 
268  virtual ~Library() throw ();
269 
270 protected:
271  Library();
272 
273 private:
274  Library(const Library&);
275 
276  Library& operator =(const Library&);
277 
278 private:
279 #ifdef GENOM_SERIALIZATION
280  template <class Archive> void load(Archive& ar, unsigned int);
281 
282  template <class Archive> void save(Archive& ar, unsigned int) const;
283 
284  CellSharedPtr restoreSingleCell(const std::string& inName) throw (Error);
285 
286  void restoreAllCells() throw (Error);
287 
288  BOOST_SERIALIZATION_SPLIT_MEMBER()
289 
290 #endif //GENOM_SERIALIZATION
295 #ifdef GENOM_SERIALIZATION
296  mutable std::list<std::string> mDumpedCells;
297 #endif //GENOM_SERIALIZATION
298 };
299 
300 /**
301  * The the level of EDIF file.
302  *
303  * @return The EDIF level for this file
304  */
305 inline const EdifLevel Library::getLevel() const {
306  return mLevel;
307 }
308 
309 /**
310  * Get scale factors for different units in the library.
311  *
312  * @return Scale factors
313  */
314 inline const std::map<Unit, ScaleFactor> Library::getScaleFactors() const {
315  std::map<Unit, ScaleFactor> temp;
316  mScaleFactors.getValueMap(temp);
317  return temp;
318 }
319 
320 /**
321  * Apply action on all Cells.
322  * @param[in] action Action to be applied
323  *
324  */
325 template <typename _Action> inline void Library::applyOnAllCells(const _Action& action)
326  throw (Error) {
327  try {
328 #ifdef GENOM_SERIALIZATION
329  restoreAllCells();
330 #endif //GENOM_SERIALIZATION
331  mCellSymTab.applyOnAll(action);
332  } catch(Error& e) {
333  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
334  throw;
335  }
336 }
337 
338 /**
339  * Get the pointer to the simulation info.
340  *
341  * @return Pointer to the simulation info
342  */
344  return mSimulationInfo;
345 }
346 
347 #ifdef GENOM_SERIALIZATION
348 void dump(const LibrarySharedPtr& inLibrary) throw (Error);
349 
350 void dump(const LibrarySharedPtr& inLibrary, const DumpRestoreData& inData) throw (Error);
351 
352 LibrarySharedPtr restore(const std::string& inName, const RootSharedPtr& inParent) throw (Error);
353 
354 LibrarySharedPtr restore(const std::string& inName, const RootSharedPtr& inParent,
355  const DumpRestoreData& inData) throw (Error);
356 #endif //GENOM_SERIALIZATION
357 } // namespace generic
358 } // namespace torc
359 
360 #endif // TORC_GENERIC_LIBRARY_HPP
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
const std::map< Unit, ScaleFactor > getScaleFactors() const
Definition: Library.hpp:314
void addCell(const CellSharedPtr &inCell)
Definition: Library.cpp:139
bool setScaleFactor(Unit inUnit, const ScaleFactor &inScale)
Definition: Library.cpp:128
An object that has a parent.
const EdifLevel getLevel() const
Definition: Library.hpp:305
An EDIF cell library.
Definition: Library.hpp:60
void setSimulationInfo(const SimulationInfoSharedPtr &inSource)
Definition: Library.cpp:239
virtual void accept(BaseVisitor &inoutVisitor)
Definition: Library.cpp:89
Represents all classes that can hold user comments.
Definition: Commentable.hpp:36
Represents class that can hold userData.
virtual void getCells(std::vector< CellSharedPtr > &outCells)
Definition: Library.cpp:227
std::string string
bool findScaleFactor(Unit inUnit, ScaleFactor &outResult) const
Definition: Library.cpp:117
void applyOnAllCells(const _Action &action)
Definition: Library.hpp:325
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
VisitorType< Library > Visitor
Definition: Library.hpp:73
boost::shared_ptr< Library > LibrarySharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
boost::shared_ptr< SimulationInfo > SimulationInfoSharedPtr
SymTab< std::string, CellSharedPtr > mCellSymTab
Definition: Library.hpp:293
SimulationInfoSharedPtr mSimulationInfo
Definition: Library.hpp:294
virtual CellSharedPtr findCell(const std::string &inName)
Definition: Library.cpp:173
void removeCell(const std::string &inName)
Definition: Library.cpp:197
void setLevel(const EdifLevel &inSource)
Definition: Library.cpp:105
SymTab< Unit, ScaleFactor > mScaleFactors
Definition: Library.hpp:291
virtual LibrarySharedPtr newLibraryPtr(const std::string &inName, const RootSharedPtr &inRootPtr, const EdifLevel &inEdifLevel=eEdifLevel0, const std::string &inOriginalName=std::string())
Definition: Library.cpp:71
boost::shared_ptr< Cell > CellSharedPtr
An object that has a name.
Definition: Nameable.hpp:34
Represents objects that can be renamed.
A symbol table.
Definition: SymTab.hpp:38
Represents objects that have status.
A placeholder for a factory method.
Definition: FactoryType.hpp:35
boost::shared_ptr< Root > RootSharedPtr
const SimulationInfoSharedPtr getSimulationInfo() const
Definition: Library.hpp:343
An object that receives an inoutVisitor.
Definition: Visitable.hpp:38
Used to implement external object referencing.
Definition: Extern.hpp:36
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73