torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Cell.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_CELL_HPP
17 #define TORC_GENERIC_CELL_HPP
18 
19 //BOOST
20 #ifdef GENOM_SERIALIZATION
21 #include <boost/serialization/access.hpp>
22 #endif //GENOM_SERIALIZATION
25 #include "torc/generic/Error.hpp"
26 #include "torc/generic/Extern.hpp"
38 
39 namespace torc { namespace generic { class BaseVisitor; } }
40 namespace torc { namespace generic { class Library; } }
41 namespace torc { namespace generic { class View; } }
42 
43 namespace torc {
44 namespace generic {
45 
46 /**
47  * @brief Represents an EDIF cell
48  *
49  * The Cell class is used to implement an EDIF cell object. It contains the different views of a
50  * cell. A cell can be concrete or extern (black-box).
51  *
52  * @note Currently parser performs semantic checks for GENERIC type only. Programattic creation
53  * may be achieved. However, a warning may be emitted when cell type is set to TIE or RIPPER.
54  */
55 class Cell : public Commentable, public Extern, public Nameable, public ParentedObject<Library>,
56  public PropertyContainer, public Renamable, public Visitable, public SelfReferencing<Cell>,
57  public UserDataContainer, public StatusContainer {
58 #ifdef GENOM_SERIALIZATION
59  friend class boost::serialization::access;
60  friend class RestoredCellUpdater;
61 #endif
62 
63  friend class FactoryType<Cell> ;
64 
65 public:
66  /**
67  * @enum Type
68  *
69  * Type of cell.
70  */
71  enum Type {
73  };
74 
75  /**
76  * Convenience class to visit a Cell.
77  */
79 
80  /**
81  * Convenience class to create a cell.
82  */
83  class Factory : public FactoryType<Cell> {
84  public:
86  /**
87  * Create a cell
88  *
89  * @param[in] inName Name of the cell to be created.
90  * @param[in] inLibraryPtr Pointer to parented(Library) object.
91  * @param[in] inCellType Cell Type.
92  * @param[in] inOriginalName Original name of the cell [optional].
93  *
94  * @return Pointer to created cell.
95  **/
96  virtual CellSharedPtr newCellPtr(const std::string& inName,
97  const LibrarySharedPtr& inLibraryPtr, const Cell::Type& inCellType = Cell::eTypeGeneric,
98  const std::string& inOriginalName = std::string()) throw (Error);
99  };
100 
101  virtual void accept(BaseVisitor& inoutVisitor) throw (Error);
102 
103  /**
104  * Get the type of cell
105  *
106  * @return Type of cell
107  */
108  inline const Type getType() const;
109 
110  /**
111  * Set the type of cell
112  *
113  * @param[in] inSource Type of cell
114  */
115  void setType(const Type& inSource);
116 
117  /**
118  * Add a view to the list of views. An empty pointer will be ignored.
119  * If an view already exists in EDIF file in same cell, parser ignores the view.
120  *
121  * @param[in] inView Pointer to a view.
122  *
123  * @exception Error Empty View type
124  * <ul>
125  * <li>
126  * Id : eMessageIdErrorEmptyItemName
127  * </li>
128  * </ul>
129  *
130  * @exception Error View name already exists
131  * <ul>
132  * <li>
133  * Id : eMessageIdErrorItemAlreadyExists
134  * </li>
135  * </ul>
136  *
137  */
138 
139  void addView(const ViewSharedPtr& inView) throw (Error);
140 
141  /**
142  * Find a view by name.
143  *
144  * @param[in] inName Name of the cell to be found.
145  *
146  * @return Pointer to cell if found, empty pointer otherwise.
147  *
148  * @exception Error Empty Cell name
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  */
161  ViewSharedPtr findView(const std::string& inName);
162 
163  /**
164  * Remove the specified pointer from the view. Empty pointer is ignored.
165  *
166  * @param[in] inName name of the object to be removed
167  *
168  * @exception Error View is not a member of the views list.
169  */
170  void removeView(const std::string& inName) throw (Error);
171 
172  /**
173  * Get the views of this cell.
174  *
175  * @param[out] outViews List of views to be appended to
176  */
177  inline void getViews(std::vector<ViewSharedPtr>& outViews) const;
178 
179  /**
180  * Apply action on all Views.
181  * @param[in] action Action to be applied
182  *
183  */
184  template <typename _Action> inline void applyOnAllViews(const _Action& action) throw (Error);
185 
186  virtual ~Cell() throw ();
187 
188 protected:
189  Cell();
190 
191 private:
192 #ifdef GENOM_SERIALIZATION
193  template <class Archive> void serialize(Archive& ar, unsigned int);
194 
195  void restoreActions() throw (Error);
196 #endif //GENOM_SERIALIZATION
197  Cell(const Cell& rhs);
198 
199  Cell& operator =(const Cell& rhs);
200 
204 };
205 
206 /**
207  * Get the type of cell
208  *
209  * @return Type of cell
210  */
211 inline const Cell::Type Cell::getType() const {
212  return mType;
213 }
214 
215 /**
216  * Get the views of this cell.
217  *
218  * @return A list of views of this cell.
219  */
220 inline void Cell::getViews(std::vector<ViewSharedPtr>& outViews) const {
221  mViewSymTab.getValues(outViews);
222 }
223 
224 template <typename _Action> inline void Cell::applyOnAllViews(const _Action& action) throw (Error) {
225  try {
226  mViewSymTab.applyOnAll(action);
227  } catch(Error& e) {
228  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
229  throw;
230  }
231 }
232 
233 } // namespace generic
234 } // namespace torc
235 
236 #endif // TORC_GENERIC_CELL_HPP
void getValues(std::vector< ValueType > &outValues) const
Definition: SymTab.hpp:158
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
Represents an EDIF cell.
Definition: Cell.hpp:55
An object that has a parent.
void addView(const ViewSharedPtr &inView)
Definition: Cell.cpp:108
const Type getType() const
Definition: Cell.hpp:211
SymTab< std::string, ViewSharedPtr > mViewSymTab
Definition: Cell.hpp:201
void removeView(const std::string &inName)
Definition: Cell.cpp:151
Represents objects that have properties.
void applyOnAllViews(const _Action &action)
Definition: Cell.hpp:224
Represents all classes that can hold user comments.
Definition: Commentable.hpp:36
Represents class that can hold userData.
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
Cell & operator=(const Cell &rhs)
ParameterMapSharedPtr mParameters
Definition: Cell.hpp:203
boost::shared_ptr< Library > LibrarySharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
virtual ~Cell()
Definition: Cell.cpp:169
virtual CellSharedPtr newCellPtr(const std::string &inName, const LibrarySharedPtr &inLibraryPtr, const Cell::Type &inCellType=Cell::eTypeGeneric, const std::string &inOriginalName=std::string())
Definition: Cell.cpp:63
ViewSharedPtr findView(const std::string &inName)
Definition: Cell.cpp:133
void setType(const Type &inSource)
Definition: Cell.cpp:95
VisitorType< Cell > Visitor
Definition: Cell.hpp:78
void getViews(std::vector< ViewSharedPtr > &outViews) const
Definition: Cell.hpp:220
boost::shared_ptr< View > ViewSharedPtr
boost::shared_ptr< Cell > CellSharedPtr
An object that has a name.
Definition: Nameable.hpp:34
Represents objects that can be renamed.
Represents objects that have status.
A placeholder for a factory method.
Definition: FactoryType.hpp:35
boost::shared_ptr< ParameterMap > ParameterMapSharedPtr
virtual void accept(BaseVisitor &inoutVisitor)
Definition: Cell.cpp:81
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