torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstanceArray.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_INSTANCEARRAY_HPP
17 #define TORC_GENERIC_INSTANCEARRAY_HPP
18 
20 
21 #include <algorithm>
22 
23 #ifdef GENOM_SERIALIZATION
24 #include <boost/serialization/access.hpp>
25 #endif //GENOM_SERIALIZATION
27 #include "torc/generic/Vector.hpp"
31 #include <vector>
32 
33 #include "torc/generic/Error.hpp"
35 
36 namespace torc { namespace generic { class BaseVisitor; } }
37 
38 namespace torc {
39 namespace generic {
40 
41 /**
42  * @brief Represents an array of instances.
43  *
44  * The InstanceArray class represents an array of instances. They can be created using the
45  * (instance (array ...) ... ) syntax.
46  */
47 class InstanceArray : public Instance, public Vector<Instance, InstanceArrayMember,
48  InstanceArrayMember::Factory, false> {
49 #ifdef GENOM_SERIALIZATION
50  friend class boost::serialization::access;
51 #endif //GENOM_SERIALIZATION
52  friend class FactoryType<InstanceArray> ;
53 
54 public:
57 
58  /**
59  * Convenience class to create an instance array.
60  */
61  class Factory : public FactoryType<InstanceArray> {
62  public:
64  /**
65  * Create an instance array
66  *
67  * @param[in] inName Name of the instance array to be created.
68  * @param[in] inViewPtr Pointer to parented(view) object.
69  * @param[in] inMaster Pointer to master object.
70  * @param[in] inSize Size of the instance array.
71  * @param[in] inFactory Factory for the child.
72  * @param[in] inOriginalName Original name of the instance array [optional].
73  *
74  * @return Pointer to created instance array.
75  **/
77  const ViewSharedPtr& inViewPtr, const ViewSharedPtr& inMaster, const size_t& inSize,
78  const ChildFactorySharedPtr& inFactory
80  const std::string& inOriginalName = std::string()) throw (Error);
81 
82  /**
83  * Create an instance array
84  *
85  * @param[in] inName Name of the instance array to be created.
86  * @param[in] inViewPtr Pointer to parented(view) object.
87  * @param[in] inMaster Pointer to master object.
88  * @param[in] inLimits Dimensions of the vector.
89  * @param[in] inFactory Factory for the child.
90  * @param[in] inOriginalName Original name of the instance array [optional].
91  *
92  * @return Pointer to created instance array.
93  **/
95  const ViewSharedPtr& inViewPtr, const ViewSharedPtr& inMaster,
96  const std::vector<size_t>& inLimits, const ChildFactorySharedPtr& inFactory
98  const std::string& inOriginalName = std::string()) throw (Error);
99  };
100 
102 
103  virtual void accept(BaseVisitor& inoutVisitor) throw (Error);
104 
105  virtual void setParent(const ViewSharedPtr& inParent);
106 
107  virtual void bindToMasterView(const ViewSharedPtr& inMaster, bool inMapPortReferences = true)
108  throw (Error);
109  /**
110  * Add a port reference to this master.
111  *
112  * @param[in] inPortRef A port reference.
113  *
114  * @exception Error The method is unsupoorted for this class.
115  */
116  virtual void addPortReference(const PortReferenceSharedPtr& inPortRef) throw (Error);
117 
118  /**
119  * Find a port reference.
120  *
121  * @param[in] inName String containing the name of the port.
122  * @exception Error The method is unsupoorted for this class.
123  */
124  virtual PortReferenceSharedPtr findPortReference(const std::string& inPortRef) throw (Error);
125 
126  /**
127  * Remove a given port reference.
128  *
129  * @param inName Name of the object to be delete
130  *
131  * @exception Error The method is unsupoorted for this class.
132  */
133  virtual void removePortReference(const std::string& inName) throw (Error);
134 
135  /**
136  * Get list of all port references.
137  *
138  * @return List of port references
139 
140  */
141  virtual void getPortReferences(std::vector<PortReferenceSharedPtr>&) const;
142 
143  /**
144  * Set list of all port references.
145  *
146  * @param[in] inSource List of port references
147  * @exception Error The method is unsupoorted for this class.
148  */
149  virtual void setPortReferences(const std::vector<PortReferenceSharedPtr>& inSource)
150  throw (Error);
151 
152  /**
153  * Apply action on all bits of the array.
154  * @param[in] action Action to be applied
155  *
156  */
157  template <typename _Action> inline void applyOnAllBits(const _Action& action) throw (Error);
158 
159  virtual ~InstanceArray() throw ();
160 
161 protected:
162  virtual void onChildCreate(
163  const boost::shared_ptr<BaseVectorType::ChildType>& inCreatedChild) const throw (Error);
164 
165  InstanceArray();
166 
167 private:
168 #ifdef GENOM_SERIALIZATION
169  template <class Archive> void serialize(Archive& ar, unsigned int);
170 #endif //GENOM_SERIALIZATION
171 };
172 
173 /**
174  * Apply action on all bits.
175  * @param[in] action Action to be applied
176  *
177  */
178 template <typename _Action> inline void InstanceArray::applyOnAllBits(const _Action& action)
179  throw (Error) {
180  try {
181  std::vector<InstanceSharedPtr> children;
182  getChildren(children);
183  std::for_each(children.begin(), children.end(), action);
184  } catch(Error& e) {
185  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
186  throw;
187  }
188 }
189 
190 } // namespace generic
191 } // namespace torc
192 
193 #endif // TORC_GENERIC_INSTANCEARRAY_HPP
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
virtual void setPortReferences(const std::vector< PortReferenceSharedPtr > &inSource)
Represents an instantiation of a cell view in the view of another cell.
virtual InstanceArraySharedPtr newInstanceArrayPtr(const std::string &inName, const ViewSharedPtr &inViewPtr, const ViewSharedPtr &inMaster, const size_t &inSize, const ChildFactorySharedPtr &inFactory=BaseVectorType::ChildFactorySharedPtr(new BaseVectorType::ChildFactory()), const std::string &inOriginalName=std::string())
Represents a member of an instance array.
VisitorType< InstanceArray > Visitor
boost::shared_ptr< InstanceArray > InstanceArraySharedPtr
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
virtual void addPortReference(const PortReferenceSharedPtr &inPortRef)
Vector< Instance, InstanceArrayMember, InstanceArrayMember::Factory, false > BaseVectorType
A base class for Visitor.
Definition: VisitorType.hpp:31
virtual void accept(BaseVisitor &inoutVisitor)
boost::shared_ptr< PortReference > PortReferenceSharedPtr
Represents an array of instances.
virtual void onChildCreate(const boost::shared_ptr< BaseVectorType::ChildType > &inCreatedChild) const
void applyOnAllBits(const _Action &action)
An array of objects.
Definition: Vector.hpp:50
virtual void getPortReferences(std::vector< PortReferenceSharedPtr > &) const
virtual void removePortReference(const std::string &inName)
boost::shared_ptr< View > ViewSharedPtr
virtual PortReferenceSharedPtr findPortReference(const std::string &inPortRef)
virtual void setParent(const ViewSharedPtr &inParent)
A placeholder for a factory method.
Definition: FactoryType.hpp:35
virtual void bindToMasterView(const ViewSharedPtr &inMaster, bool inMapPortReferences=true)
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73