torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorNet.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
31 
32 #ifdef GENOM_SERIALIZATION
33 BOOST_CLASS_EXPORT(torc::generic::VectorNet)
34 #endif //GENOM_SERIALIZATION
35 namespace torc {
36 namespace generic {
37 
38 /**
39  * Create a vector net.
40  *
41  * @param[in] inName Name of the vector net to be created.
42  * @param[in] inViewPtr Pointer to parented(View) object.
43  * @param[in] inSize Size of the net array.
44  * @param[in] inFactory Factory for the child.
45  * @param[in] inOriginalName Original name of the vector net [optional].
46  *
47  * @return Pointer to created vector net.
48  **/
50  const ViewSharedPtr& inViewPtr, const size_t& inSize,
51  const NetBundleSharedPtr& inParentCollection, const ChildFactorySharedPtr& inFactory,
52  const std::string& inOriginalName) throw (Error) {
53  try {
54  std::vector < size_t > limits;
55  limits.push_back(inSize);
56  return newVectorNetPtr(inName, inViewPtr, limits, inParentCollection, inFactory,
57  inOriginalName);
58  } catch(Error& e) {
59  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
60  throw;
61  }
62 }
63 
64 /**
65  * Create a vector net.
66  *
67  * @param[in] inName Name of the vector net to be created.
68  * @param[in] inViewPtr Pointer to parented(View) object.
69  * @param[in] inLimits Dimensions of the vector.
70  * @param[in] inFactory Factory for the child.
71  * @param[in] inOriginalName Original name of the vector net [optional].
72  *
73  * @return Pointer to created vector net.
74  **/
76  const ViewSharedPtr& inViewPtr, const std::vector<size_t>& inLimits,
77  const NetBundleSharedPtr& inParentCollection, const ChildFactorySharedPtr& inFactory,
78  const std::string& inOriginalName) throw (Error) {
79  try {
80  VectorNetSharedPtr newVectorNet;
81  create(newVectorNet);
82  newVectorNet->setName(inName);
83  newVectorNet->constructChildren(inFactory, inLimits);
84  newVectorNet->setOriginalName(inOriginalName);
85  if(inParentCollection) {
86  inParentCollection->addChild(newVectorNet);
87  } else {
88  inViewPtr->addNet(newVectorNet);
89  }
90  return newVectorNet;
91  } catch(Error& e) {
92  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
93  throw;
94  }
95 }
96 void VectorNet::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 
105 void VectorNet::setParent(const ViewSharedPtr& inParent) {
107  BaseType::List children;
108  getCreatedChildren(children);
109  std::for_each(children.begin(), children.end(),
110  boost::bind(boost::mem_fn(&Net::setParent), _1, getParent()));
111 }
112 
113 /**
114  * Connect a Net to this object.
115  *
116  * @note This metod can be overridden by derived classes. However, the method must call the
117  * on_connected() method after this. The sigConnected_ signal must also be invoked in the
118  * overriding method.
119  *
120  * @param[in] inNet A pointer to the Net object that eeds to be connected
121  * @return A connection that has been established. This can be used later for disconnection.
122  */
124  if(!inNet) {
125  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
126  e.saveContextData("Pointer to the Net object does not exist", inNet);
127  throw e;
128  }
129  if(inNet->getSize() != getSize()) {
130  Error e(eMessageIdErrorItemSizeMismatch, __FUNCTION__, __FILE__, __LINE__);
131  e.saveContextData("Net Size", inNet->getSize());
132  e.saveContextData("Vector Net Size", getSize());
133  throw e;
134  }
135  return Connectable::connect(inNet);
136 }
137 
138 /**
139  * Disconnect a Net from this object.
140  * @note This metod can be overridden by derived classes. However, the method must call the
141  * on_connected() method after this. The sigConnected_ signal must also be invoked in the
142  * overriding method.
143 
144  * @param[in] inConnection A connection as returned by the connect() method
145  * @exception Error Provided connection is invalid
146  */
147 void VectorNet::disconnect(const Connectable::Connection& inConnection) throw (Error) {
148  Connectable::disconnect(inConnection);
149 }
150 
151 void VectorNet::disconnect() throw (Error) {
152  Net::disconnect();
153  BaseVectorType::List children;
154  getCreatedChildren(children); //We need only the
155  // bits that have been created
156  BaseVectorType::List::iterator net = children.begin();
157  BaseVectorType::List::iterator nEnd = children.end();
158  for(; net != nEnd; ++net) {
159  try {
160  (*net)->disconnect();
161  } catch(Error& e) {
162  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
163  throw;
164  }
165  }
166 }
167 
168 void VectorNet::getConnectedNets(std::vector<NetSharedPtr>& outNets,
169  bool inSkipChildConnections) const throw (Error) {
170  Net::getConnectedNets(outNets);
171  if(!inSkipChildConnections) {
172  BaseVectorType::List children;
173  getCreatedChildren(children); //We need only the
174  // bits that have been created
175  BaseVectorType::List::iterator net = children.begin();
176  BaseVectorType::List::iterator nEnd = children.end();
177  for(; net != nEnd; ++net) {
178  (*net)->getConnectedNets(outNets, true);
179  }
180  }
181  return;
182 }
183 
184 void VectorNet::getConnectedPorts(std::vector<PortSharedPtr>& outPorts,
185  bool inSkipChildConnections) const {
186  Net::getConnectedPorts(outPorts);
187  if(!inSkipChildConnections) {
188  BaseVectorType::List children;
189  getCreatedChildren(children); //We need only the
190  // bits that have been created
191  BaseVectorType::List::iterator net = children.begin();
192  BaseVectorType::List::iterator nEnd = children.end();
193  for(; net != nEnd; ++net) {
194  (*net)->getConnectedPorts(outPorts, true);
195  }
196  }
197  return;
198 }
199 void VectorNet::getConnectedPortRefs(std::vector<PortReferenceSharedPtr>& outPortRefs,
200  bool inSkipChildConnections) const {
201  Net::getConnectedPortRefs(outPortRefs);
202  if(!inSkipChildConnections) {
203  BaseVectorType::List children;
204  getCreatedChildren(children); //We need only the
205  // bits that have been created
206  BaseVectorType::List::iterator net = children.begin();
207  BaseVectorType::List::iterator nEnd = children.end();
208  for(; net != nEnd; ++net) {
209  (*net)->getConnectedPortRefs(outPortRefs, true);
210  }
211  }
212  return;
213 }
214 
216  const boost::shared_ptr<BaseVectorType::ChildType>& inCreatedChild) const throw (Error) {
217  inCreatedChild->setName(getName());
218 }
219 
221 
223 
224 #ifdef GENOM_SERIALIZATION
225 template <class Archive> void VectorNet::serialize(Archive& ar, unsigned int) {
226  ar & boost::serialization::base_object<Net>(*this);
227  ar & boost::serialization::base_object<BaseVectorType>(*this);
228 }
229 
230 //TO SATISFY THE LINKER
231 template void VectorNet::serialize<boost::archive::binary_iarchive>(
232  boost::archive::binary_iarchive& ar, const unsigned int);
233 
234 template void VectorNet::serialize<boost::archive::binary_oarchive>(
235  boost::archive::binary_oarchive& ar, const unsigned int);
236 
237 #endif //GENOM_SERIALIZATION
238 
239 } // namespace generic
240 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
Represents a bit of a net array.
virtual void setParent(const ViewSharedPtr &inParent)
Definition: VectorNet.cpp:105
virtual void onChildCreate(const boost::shared_ptr< BaseVectorType::ChildType > &inCreatedChild) const
Definition: VectorNet.cpp:215
Represents an EDIF Net.
Definition: generic/Net.hpp:58
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
virtual void getConnectedPorts(std::vector< PortSharedPtr > &outPort, bool inSkipChildConnections=false) const
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
virtual void getConnectedPortRefs(std::vector< PortReferenceSharedPtr > &outPortRefs, bool inSkipChildConnections=false) const
virtual void getConnectedPorts(std::vector< PortSharedPtr > &outPorts, bool inSkipChildConnections=false) const
Definition: VectorNet.cpp:184
boost::shared_ptr< VectorNet > VectorNetSharedPtr
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
virtual void accept(BaseVisitor &inoutVisitor)
Definition: VectorNet.cpp:96
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
Definition: Connectable.cpp:45
boost::shared_ptr< Net > NetSharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
Represents a net array.
Definition: VectorNet.hpp:42
const boost::shared_ptr< View > getParent() const
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
virtual Connectable::Connection connect(const NetSharedPtr &inNet)
Definition: VectorNet.cpp:123
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
Definition: VectorNet.cpp:168
virtual void disconnect()
An array of objects.
Definition: Vector.hpp:50
boost::shared_ptr< VectorNetBit::Factory > ChildFactorySharedPtr
Definition: Vector.hpp:63
boost::shared_ptr< View > ViewSharedPtr
virtual void setParent(const boost::shared_ptr< _ParentType > &inSource)
virtual void getConnectedPortRefs(std::vector< PortReferenceSharedPtr > &outPortRefs, bool inSkipChildConnections=false) const
Definition: VectorNet.cpp:199
boost::shared_ptr< NetBundle > NetBundleSharedPtr
virtual VectorNetSharedPtr newVectorNetPtr(const std::string &inName, const ViewSharedPtr &inViewPtr, const size_t &inSize, const NetBundleSharedPtr &inParentCollection=NetBundleSharedPtr(), const ChildFactorySharedPtr &inFactory=BaseVectorType::ChildFactorySharedPtr(new BaseVectorType::ChildFactory()), const std::string &inOriginalName=std::string())
Definition: VectorNet.cpp:49
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73
std::vector< Pointer > List
Definition: Composite.hpp:61