torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorPortBitReference.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
28 #include "torc/generic/Net.hpp"
30 
31 #ifdef GENOM_SERIALIZATION
32 BOOST_CLASS_EXPORT(torc::generic::VectorPortBitReference)
33 #endif //GENOM_SERIALIZATION
34 
35 namespace torc {
36 namespace generic {
37 
38 void VectorPortBitReference::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("Vector Net Size", getSize());
57  throw e;
58  }
59  Connectable::Connection newConnection;
60  try {
61  ConnectionHandler handler(inNet);
62  handler.connectPortRefToNet(getSharedThis());
63  newConnection = Connectable::connect(inNet);
64  } catch(Error& e) {
65  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
66  throw;
67  }
68  return newConnection;
69 }
70 
71 void VectorPortBitReference::disconnect(const Connection& inConnection) throw (Error) {
72  NetSharedPtr connNet = *inConnection;
73  if(!connNet) {
74  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
75  e.saveContextData("Pointer to the Net object does not exist", connNet);
76  throw e;
77  }
78  try {
79  ConnectionHandler handler(connNet);
80  handler.disconnectPortRefFromNet(getSharedThis());
81  Connectable::disconnect(inConnection);
82  } catch(Error& e) {
83  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
84  throw;
85  }
86  return;
87 }
88 
89 void VectorPortBitReference::getConnectedNets(std::vector<NetSharedPtr>& outNets,
90  bool inSkipChildConnections) const throw (Error) {
91  //First get connections exclusive to me
93 
94  if(!inSkipChildConnections) {
95  //Append cousins from nets that have been connected to my
96  //parent
97  Composite<PortReference>::Pointer parent = getParentCollection();
98  if(!parent) {
99  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
100  e.saveContextData("Pointer to parent collection does not exist", parent);
101  throw e;
102  }
103  if(eCompositionTypeVector != parent->getCompositionType()) {
104  Error e(eMessageIdErrorCompositionTypeMismatch, __FUNCTION__, __FILE__, __LINE__);
105  e.saveContextData("Composition type mismatch", parent->getCompositionType());
106  throw e;
107  }
108  VectorBit<Net>::List parentConnections;
109  parent->getConnectedNets(parentConnections, true);
110  VectorBit<Net>::List::iterator connNet = parentConnections.begin();
111  VectorBit<Net>::List::iterator connNetEnd = parentConnections.end();
112  const std::vector<VectorBit<Net>::SizeType>& myIndex = getIndices();
113  for(; connNet != connNetEnd; ++connNet) {
115  if(eCompositionTypeVector == (*connNet)->getCompositionType()) {
116  cousin = (*connNet)->get(myIndex);
117  } else {
118  VectorBit<Net>::List bChildren;
119  (*connNet)->getChildren(bChildren);
120  cousin = bChildren[getAbsoluteIndex()];
121  }
122  if(!cousin) {
123  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
124  e.saveContextData("Pointer to item does not exist", cousin);
125  throw e;
126  }
127  outNets.push_back(cousin);
128  }
129  }
130  return;
131 }
132 
135 
137 
138 #ifdef GENOM_SERIALIZATION
139 template <class Archive> void VectorPortBitReference::serialize(Archive& ar, unsigned int) {
140  ar & boost::serialization::base_object<PortReference>(*this);
141  ar & boost::serialization::base_object<VectorBit<PortReference> >(*this);
142 }
143 
144 //TO SATISFY THE LINKER
145 template void VectorPortBitReference::serialize<boost::archive::binary_iarchive>(
146  boost::archive::binary_iarchive& ar, const unsigned int);
147 
148 template void VectorPortBitReference::serialize<boost::archive::binary_oarchive>(
149  boost::archive::binary_oarchive& ar, const unsigned int);
150 
151 #endif //GENOM_SERIALIZATION
152 
153 } // namespace generic
154 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
virtual void getChildren(List &outChildren) const
Definition: VectorBit.hpp:140
virtual CompositionType getCompositionType() const =0
Represents the usable instance of a port of a cell in another cell.
Interface for objects that can be composed within each other.
Definition: Composite.hpp:45
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
void connectPortRefToNet(const PortReferenceSharedPtr &inPort)
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
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
A base class for Visitor.
Definition: VisitorType.hpp:31
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
virtual Connection connect(const NetSharedPtr &inNet)
void disconnectPortRefFromNet(const PortReferenceSharedPtr &inPort)
Represents a reference to a bit of a port.
virtual const Pointer get(const std::vector< SizeType > &inIndices) const =0
virtual void accept(BaseVisitor &inoutVisitor)
virtual void getConnectedNets(std::vector< NetSharedPtr > &outNets, bool inSkipChildConnections=false) const
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