torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorNetBit.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 #ifdef GENOM_SERIALIZATION
22 #include <boost/archive/binary_iarchive.hpp>
23 #include <boost/archive/binary_oarchive.hpp>
24 #include <boost/serialization/base_object.hpp>
25 #include <boost/serialization/export.hpp>
26 #endif //GENOM_SERIALIZATION
27 #include "torc/generic/Port.hpp"
30 
31 #ifdef GENOM_SERIALIZATION
32 BOOST_CLASS_EXPORT(torc::generic::VectorNetBit)
33 #endif //GENOM_SERIALIZATION
34 
35 namespace torc {
36 namespace generic {
37 
38 void VectorNetBit::accept(BaseVisitor& inoutVisitor) throw (Error) {
39  try {
40  runVisitor(*this, inoutVisitor);
41  } catch(Error& e) {
42  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
43  throw;
44  }
45 }
46 
48  if(!inNet) {
49  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
50  e.saveContextData("Pointer to the Net object does not exist", inNet);
51  throw e;
52  }
53  if(inNet->getSize() != getSize()) {
54  Error e(eMessageIdErrorItemSizeMismatch, __FUNCTION__, __FILE__, __LINE__);
55  e.saveContextData("Net Size", inNet->getSize());
56  e.saveContextData("VectorNetBit Size", getSize());
57  throw e;
58  }
59  return Connectable::connect(inNet);
60 }
61 
62 void VectorNetBit::disconnect(const Connection& inConnection) throw (Error) {
63  Connectable::disconnect(inConnection);
64 }
65 
66 void VectorNetBit::getConnectedNets(std::vector<NetSharedPtr>& outNets,
67  bool inSkipChildConnections) const throw (Error) {
68  Composite<Net>::Pointer parent = getParentCollection();
69  if(!parent) {
70  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
71  e.saveContextData("Pointer to parent collection does not exist", parent);
72  throw e;
73  }
75  Error e(eMessageIdErrorCompositionTypeMismatch, __FUNCTION__, __FILE__, __LINE__);
76  e.saveContextData("Composition type mismatch", parent->getCompositionType());
77  throw e;
78  }
79  //First get connections exclusive to me
80  Net::getConnectedNets(outNets);
81 
82  if(!inSkipChildConnections) {
83  //Append cousins from nets that have been connected to my
84  //parent
85  VectorBit<Net>::List parentConnections;
86  parent->getConnectedNets(parentConnections, true);
87  VectorBit<Net>::List::iterator connNet = parentConnections.begin();
88  VectorBit<Net>::List::iterator connNetEnd = parentConnections.end();
89  const std::vector<VectorBit<Net>::SizeType>& myIndex = getIndices();
90  for(; connNet != connNetEnd; ++connNet) {
92  if(eCompositionTypeVector == (*connNet)->getCompositionType()) {
93  cousin = (*connNet)->get(myIndex);
94  //We don't want to mess up preservation
95  //by calling getChildren
96  } else //Must be a bundle
97  {
98  VectorBit<Net>::List bChildren;
99  (*connNet)->getChildren(bChildren);
100  cousin = bChildren[getAbsoluteIndex()];
101  //We assume List is a vector
102  }
103  if(!cousin) {
104  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
105  e.saveContextData("Pointer to item does not exist", cousin);
106  throw e;
107  }
108  outNets.push_back(cousin);
109  }
110  //MAINTAINER_NOTE::Also check getConnectedPorts
111  // getConnectedPortReferences as they follow the same logic
112  }
113  return;
114 }
115 
116 void VectorNetBit::getConnectedPorts(std::vector<PortSharedPtr>& outPorts,
117  bool inSkipChildConnections) const {
119  if(!parent) {
120  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
121  e.saveContextData("Pointer to parent collection does not exist", parent);
122  throw e;
123  }
124  if(eCompositionTypeVector != parent->getCompositionType()) {
125  Error e(eMessageIdErrorCompositionTypeMismatch, __FUNCTION__, __FILE__, __LINE__);
126  e.saveContextData("Composition type mismatch", parent->getCompositionType());
127  throw e;
128  }
129  //First get connections exclusive to me
130  Net::getConnectedPorts(outPorts);
131 
132  if(!inSkipChildConnections) {
133  //Append cousins from nets that have been connected to my
134  //parent
135  VectorBit<Port>::List parentConnections;
136  parent->getConnectedPorts(parentConnections, true);
137  VectorBit<Port>::List::iterator connPort = parentConnections.begin();
138  VectorBit<Port>::List::iterator connPortEnd = parentConnections.end();
139  const std::vector<VectorBit<Net>::SizeType>& myIndex = getIndices();
140  for(; connPort != connPortEnd; ++connPort) {
142  //Maintainer Note:: Check comments in getConnectedNets
143  if(eCompositionTypeVector == (*connPort)->getCompositionType()) {
144  cousin = (*connPort)->get(myIndex);
145  } else {
146  VectorBit<Port>::List bChildren;
147  (*connPort)->getChildren(bChildren);
148  cousin = bChildren[getAbsoluteIndex()];
149  }
150  if(!cousin) {
151  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
152  e.saveContextData("Pointer to item does not exist", cousin);
153  throw e;
154  }
155  outPorts.push_back(cousin);
156  }
157  //MAINTAINER_NOTE::Also check getConnectedNets
158  // getConnectedPortReferences as they follow the same logic
159  }
160  return;
161 }
162 
163 void VectorNetBit::getConnectedPortRefs(std::vector<PortReferenceSharedPtr>& outPortRefs,
164  bool inSkipChildConnections) const {
166  if(!parent) {
167  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
168  e.saveContextData("Pointer to parent collection does not exist", parent);
169  throw e;
170  }
171  //Maintainer Note:: Check comments in getConnectedNets
172  if(eCompositionTypeVector != parent->getCompositionType()) {
173  Error e(eMessageIdErrorCompositionTypeMismatch, __FUNCTION__, __FILE__, __LINE__);
174  e.saveContextData("Composition type mismatch", parent->getCompositionType());
175  throw e;
176  }
177  //First get connections exclusive to me
178  Net::getConnectedPortRefs(outPortRefs);
179 
180  if(!inSkipChildConnections) {
181  //Append cousins from nets that have been connected to my
182  //parent
183  VectorBit<PortReference>::List parentConnections;
184  parent->getConnectedPortRefs(parentConnections, true);
185  VectorBit<PortReference>::List::iterator connPortRef = parentConnections.begin();
186  VectorBit<PortReference>::List::iterator connPortRefEnd = parentConnections.end();
187  const std::vector<VectorBit<Net>::SizeType>& myIndex = getIndices();
188  for(; connPortRef != connPortRefEnd; ++connPortRef) {
190  //Maintainer note:: Check comments in getConnectedNets
191  if(eCompositionTypeVector == (*connPortRef)->getCompositionType()) {
192  cousin = (*connPortRef)->get(myIndex);
193  } else {
195  (*connPortRef)->getChildren(bChildren);
196  cousin = bChildren[getAbsoluteIndex()];
197  }
198  if(!cousin) {
199  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
200  e.saveContextData("Pointer to item does not exist", cousin);
201  throw e;
202  }
203  outPortRefs.push_back(cousin);
204  }
205  //MAINTAINER_NOTE::Also check getConnectedPorts
206  // getConnectedNets as they follow the same logic
207  }
208  return;
209 }
210 
212 
214 
215 #ifdef GENOM_SERIALIZATION
216 template <class Archive> void VectorNetBit::serialize(Archive& ar, unsigned int) {
217  ar & boost::serialization::base_object<Net>(*this);
218  ar & boost::serialization::base_object<VectorBit<Net> >(*this);
219 }
220 
221 //TO SATISFY THE LINKER
222 template void VectorNetBit::serialize<boost::archive::binary_iarchive>(
223  boost::archive::binary_iarchive& ar, const unsigned int);
224 
225 template void VectorNetBit::serialize<boost::archive::binary_oarchive>(
226  boost::archive::binary_oarchive& ar, const unsigned int);
227 
228 #endif //GENOM_SERIALIZATION
229 
230 } // namespace generic
231 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
Represents a bit of a net array.
virtual void getChildren(List &outChildren) const
Definition: VectorBit.hpp:140
virtual CompositionType getCompositionType() const =0
virtual void getConnectedPortRefs(std::vector< PortReferenceSharedPtr > &outPortRefs, bool inSkipChildConnections=false) const
SizeType getAbsoluteIndex() const
Interface for objects that can be composed within each other.
Definition: Composite.hpp:45
Represents an EDIF Net.
Definition: generic/Net.hpp:58
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
virtual void getConnectedPorts(std::vector< PortSharedPtr > &outPorts, bool inSkipChildConnections=false) const
virtual void getConnectedPorts(std::vector< PortSharedPtr > &outPort, bool inSkipChildConnections=false) const
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
virtual void getConnectedPortRefs(std::vector< PortReferenceSharedPtr > &outPortRefs, bool inSkipChildConnections=false) const
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
Definition: Connectable.cpp:45
boost::shared_ptr< Net > NetSharedPtr
virtual Pointer getParentCollection() const
A base class for Visitor.
Definition: VisitorType.hpp:31
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
virtual void disconnect()
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
virtual const Pointer get(const std::vector< SizeType > &inIndices) const =0
const std::vector< SizeType > & getIndices() const
virtual void accept(BaseVisitor &inoutVisitor)
virtual Connection connect(const NetSharedPtr &inNet)
Represents a single element of a vector composition.
Definition: VectorBit.hpp:41
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73