torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NetBundle.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::NetBundle)
33 #endif //GENOM_SERIALIZATION
34 
35 namespace torc {
36 namespace generic {
37 
38 /**
39  * Create a net bundle.
40  *
41  * @param[in] inName Name of the net bundle to be created.
42  * @param[in] inViewPtr Pointer to parented(View) object.
43  * @param[in] inOriginalName Original name of the vector net [optional].
44  *
45  * @return Pointer to created net bundle.
46  **/
48  const ViewSharedPtr& inViewPtr, const NetBundleSharedPtr& inParentCollection,
49  const std::string& inOriginalName) throw (Error) {
50  try {
51  NetBundleSharedPtr newNetBundle;
52  create(newNetBundle);
53  newNetBundle->setName(inName);
54  newNetBundle->setOriginalName(inOriginalName);
55  if(inParentCollection) {
56  inParentCollection->addChild(newNetBundle);
57  } else {
58  inViewPtr->addNet(newNetBundle);
59  }
60  return newNetBundle;
61  } catch(Error& e) {
62  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
63  throw;
64  }
65 }
66 
67 void NetBundle::accept(BaseVisitor& inoutVisitor) throw (Error) {
68  runVisitor(*this, inoutVisitor);
69 }
70 
71 void NetBundle::setParent(const ViewSharedPtr& inParent) {
73  applyOnAllChildren(boost::bind(boost::mem_fn(&Net::setParent), _1, getParent()));
74 }
75 
76 //For net to net connection
78  if(!inNet) {
79  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
80  e.saveContextData("Pointer to Net", inNet);
81  throw e;
82  }
83  if(inNet->getSize() != getSize()) {
84  Error e(eMessageIdErrorItemSizeMismatch, __FUNCTION__, __FILE__, __LINE__);
85  e.saveContextData("Net Size", inNet->getSize());
86  e.saveContextData("NetBundle Size", getSize());
87  throw e;
88  }
89  Bundle<Net>::List children;
90  getChildren(children);
91  Bundle<Net>::List netChildren;
92  inNet->getChildren(netChildren);
93  Bundle<Net>::List::iterator childNet = children.begin();
94  Bundle<Net>::List::iterator childEnd = children.end();
95  Bundle<Net>::List::iterator net = netChildren.begin();
96  for(; childNet != childEnd; ++childNet, ++net) {
97  try {
98  (*childNet)->connect(*net);
99  } catch(Error& e) {
100  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
101  throw;
102  }
103  }
104  return Connectable::connect(inNet);
105 }
106 
107 void NetBundle::disconnect(const Connection& inConnection) throw (Error) {
108  NetSharedPtr connNet = *inConnection;
109  Bundle<Net>::List children;
110  getChildren(children);
111  Bundle<Net>::List netChildren;
112  connNet->getChildren(netChildren);
113  Bundle<Net>::List::iterator childNet = children.begin();
114  Bundle<Net>::List::iterator childEnd = children.end();
115  Bundle<Net>::List::iterator net = netChildren.begin();
116  //We find all bits from the connected net and remove them
117  //from the children nets. This disconnect is a little slow
118  //as lookup is performed for each net. Otherwise we
119  //would have to save the iterators (Connection objects)
120  //for each child connection
121  for(; childNet != childEnd; ++childNet, ++net) {
122  try {
123  (*childNet)->Connectable::disconnect(*net);
124  } catch(Error& e) {
125  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
126  throw;
127  }
128  }
129  Connectable::disconnect(inConnection);
130 }
131 
132 void NetBundle::disconnect() throw (Error) {
133  Bundle<Net>::List children;
134  getChildren(children);
135  Bundle<Net>::List::iterator childNet = children.begin();
136  Bundle<Net>::List::iterator childEnd = children.end();
137  for(; childNet != childEnd; ++childNet) {
138  try {
139  (*childNet)->disconnect();
140  } catch(Error& e) {
141  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
142  throw;
143  }
144  }
145  Net::disconnect();
146 }
147 
149 
151 
152 #ifdef GENOM_SERIALIZATION
153 template <class Archive> void NetBundle::serialize(Archive& ar, unsigned int) {
154  ar & boost::serialization::base_object< Net >(*this);
155  ar & boost::serialization::base_object< Bundle<Net> >(*this);
156 }
157 
158 //TO SATISFY THE LINKER
159 template void NetBundle::serialize<boost::archive::binary_iarchive>(
160  boost::archive::binary_iarchive& ar, const unsigned int);
161 
162 template void NetBundle::serialize<boost::archive::binary_oarchive>(
163  boost::archive::binary_oarchive& ar, const unsigned int);
164 
165 #endif //GENOM_SERIALIZATION
166 
167 } // namespace generic
168 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
virtual NetBundleSharedPtr newNetBundlePtr(const std::string &inName, const ViewSharedPtr &inViewPtr, const NetBundleSharedPtr &inParentCollection=NetBundleSharedPtr(), const std::string &inOriginalName=std::string())
Definition: NetBundle.cpp:47
Represents an EDIF Net.
Definition: generic/Net.hpp:58
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
virtual void setParent(const ViewSharedPtr &inParent)
Definition: NetBundle.cpp:71
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
boost::shared_ptr< Net > NetSharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
virtual void accept(BaseVisitor &inoutVisitor)
Definition: NetBundle.cpp:67
const boost::shared_ptr< View > getParent() const
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
void applyOnAllChildren(const _Action &action)
virtual Connection connect(const NetSharedPtr &inNet)
Definition: NetBundle.cpp:77
virtual void disconnect()
virtual void getChildren(List &outChildren) const
Definition: Bundle.hpp:156
Represents a bundle of nets.
Definition: NetBundle.hpp:43
boost::shared_ptr< View > ViewSharedPtr
virtual void setParent(const boost::shared_ptr< _ParentType > &inSource)
boost::shared_ptr< NetBundle > NetBundleSharedPtr
Represents a "bundle" in the EDIF sense.
Definition: Bundle.hpp:43
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73