torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstanceArray.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 
16 #ifndef HAVE_CONFIG_H
17 #include "torc/generic/config.h"
18 #endif
19 
20 //BOOST
21 #include <boost/bind.hpp>
22 #include <boost/mem_fn.hpp>
23 #ifdef GENOM_SERIALIZATION
24 #include <boost/archive/binary_iarchive.hpp>
25 #include <boost/archive/binary_oarchive.hpp>
26 #include <boost/serialization/base_object.hpp>
27 #include <boost/serialization/export.hpp>
28 #endif //GENOM_SERIALIZATION
30 
31 #ifdef GENOM_SERIALIZATION
32 BOOST_CLASS_EXPORT(torc::generic::InstanceArray)
33 #endif //GENOM_SERIALIZATION
34 
35 namespace torc {
36 namespace generic {
37 
38 /**
39  * Create an instance array
40  *
41  * @param[in] inName Name of the instance array to be created.
42  * @param[in] inViewPtr Pointer to parented(view) object.
43  * @param[in] inMaster Pointer to master object.
44  * @param[in] inSize Size of the instance array.
45  * @param[in] inFactory Factory for the child.
46  * @param[in] inOriginalName Original name of the instance array [optional].
47  *
48  * @return Pointer to created instance array.
49  **/
50 
52  const ViewSharedPtr& inViewPtr, const ViewSharedPtr& inMaster, const size_t& inSize,
53  const ChildFactorySharedPtr& inFactory, const std::string& inOriginalName) throw (Error) {
54  try {
55  std::vector < size_t > limits;
56  limits.push_back(inSize);
57  return newInstanceArrayPtr(inName, inViewPtr, inMaster, limits, inFactory, inOriginalName);
58  } catch(Error& e) {
59  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
60  throw;
61  }
62 }
63 
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] inLimits Dimensions of the vector.
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  **/
76 
78  const ViewSharedPtr& inViewPtr, const ViewSharedPtr& inMaster,
79  const std::vector<size_t>& inLimits, const ChildFactorySharedPtr& inFactory,
80  const std::string& inOriginalName) throw (Error) {
81  try {
82  InstanceArraySharedPtr newInstanceArray;
83  create(newInstanceArray);
84  newInstanceArray->setName(inName);
85  //newInstanceArray->setMaster(inMaster);
86  newInstanceArray->constructChildren(inFactory, inLimits);
87  newInstanceArray->bindToMasterView(inMaster);
88  newInstanceArray->setOriginalName(inOriginalName);
89  inViewPtr->addInstance(newInstanceArray);
90  return newInstanceArray;
91  } catch(Error& e) {
92  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
93  throw;
94  }
95 }
96 void InstanceArray::accept(BaseVisitor& inoutVisitor) throw (Error) {
97  try {
98  runVisitor(*this, inoutVisitor);
99  } catch(Error& e) {
100  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
101  throw;
102  }
103 }
104 
107  BaseVectorType::List children;
108  getCreatedChildren(children);
109  std::for_each(children.begin(), children.end(),
110  boost::bind(boost::mem_fn(&Instance::setParent), _1, getParent()));
111 }
112 
113 void InstanceArray::bindToMasterView(const ViewSharedPtr& inMaster, bool inMapPortReferences)
114  throw (Error) {
115  typedef std::vector<InstanceSharedPtr> Children;
116  Children children;
117  getChildren(children);
118  Children::iterator child = children.begin();
119  Children::iterator cEnd = children.end();
120  for(; child != cEnd; ++child) {
121  try {
122  (*child)->bindToMasterView(inMaster);
123  } catch(Error& e) {
124  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
125  throw;
126  }
127  }
128  Instance::bindToMasterView(inMaster, false);
129 }
130 
132  //TBD::ERROR UNSUPPORTED
133 }
134 
136  //TBD::ERROR UNSUPPORTED
137  return PortReferenceSharedPtr();
138 }
139 
141  //TBD::ERROR UNSUPPORTED
142 }
143 
144 void InstanceArray::getPortReferences(std::vector<PortReferenceSharedPtr>& outPortRefs) const {
145  return;
146 }
147 
148 void InstanceArray::setPortReferences(const std::vector<PortReferenceSharedPtr>& inSource)
149  throw (Error) {
150  //TBD::ERROR UNSUPPORTED
151 }
152 
153 void InstanceArray::onChildCreate(const boost::shared_ptr<BaseVectorType::ChildType>&
154  inCreatedChild) const throw (Error) {
155  inCreatedChild->setName(getName());
156 }
157 
159  InstanceArrayMember::Factory, false>() {}
160 
162 
163 #ifdef GENOM_SERIALIZATION
164 template <class Archive> void InstanceArray::serialize(Archive& ar, unsigned int) {
165  ar & boost::serialization::base_object<Instance>(*this);
166  ar & boost::serialization::base_object< BaseVectorType >(*this);
167 }
168 
169 //TO SATISFY THE LINKER
170 template void InstanceArray::serialize<boost::archive::binary_iarchive>(
171  boost::archive::binary_iarchive& ar, const unsigned int);
172 
173 template void InstanceArray::serialize<boost::archive::binary_oarchive>(
174  boost::archive::binary_oarchive& ar, const unsigned int);
175 
176 #endif //GENOM_SERIALIZATION
177 
178 }// namespace generic
179 } // namespace torc
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())
virtual void bindToMasterView(const ViewSharedPtr &inMaster, bool inMapPortReferences=true)
Represents a member of an instance array.
boost::shared_ptr< InstanceArray > InstanceArraySharedPtr
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
virtual void addPortReference(const PortReferenceSharedPtr &inPortRef)
A base class for Visitor.
Definition: VisitorType.hpp:31
virtual void accept(BaseVisitor &inoutVisitor)
boost::shared_ptr< PortReference > PortReferenceSharedPtr
Represents an array of instances.
const boost::shared_ptr< View > getParent() const
virtual void onChildCreate(const boost::shared_ptr< BaseVectorType::ChildType > &inCreatedChild) const
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 boost::shared_ptr< _ParentType > &inSource)
virtual void setParent(const ViewSharedPtr &inParent)
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