torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScalarPortReference.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"
31 
32 #ifdef GENOM_SERIALIZATION
33 BOOST_CLASS_EXPORT(torc::generic::ScalarPortReference)
34 #endif //GENOM_SERIALIZATION
35 namespace torc {
36 namespace generic {
37 
38 /**
39  * Create a scalar port ref.
40  *
41  * @param[in] inInstancePtr Pointer to parented(Instance) object.
42  * @param[in] inPortPtr Pointer to master(Port) object.
43  *
44  * @return Pointer to created scalar port ref.
45  **/
47  const InstanceSharedPtr& inInstancePtr, const PortSharedPtr& inPortPtr,
48  const PortBundleReferenceSharedPtr& inParentCollection) throw (Error) {
49  try {
50  ScalarPortReferenceSharedPtr newScalarPortReference;
51  create(newScalarPortReference);
52  newScalarPortReference->bindToMasterPort(inPortPtr);
53  if(inParentCollection) {
54  inParentCollection->addChild(newScalarPortReference);
55  } else {
56  inInstancePtr->addPortReference(newScalarPortReference);
57  }
58  return newScalarPortReference;
59  } catch(Error& e) {
60  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
61  throw;
62  }
63 }
64 
65 void ScalarPortReference::accept(BaseVisitor& inoutVisitor) throw (Error) {
66  try {
67  runVisitor(*this, inoutVisitor);
68  } catch(Error& e) {
69  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
70  throw;
71  }
72 }
73 
75  if(!inNet) {
76  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
77  e.saveContextData("Pointer to the Net object does not exist", inNet);
78  throw e;
79  }
80  if(inNet->getSize() != getSize()) {
81  Error e(eMessageIdErrorItemSizeMismatch, __FUNCTION__, __FILE__, __LINE__);
82  e.saveContextData("Net Size", inNet->getSize());
83  e.saveContextData("Scalar port reference Size", getSize());
84  throw e;
85  }
86  Connectable::Connection newConnection;
87  try {
88  ConnectionHandler handler(inNet);
89  handler.connectPortRefToNet(getSharedThis());
90  newConnection = Connectable::connect(inNet);
91  } catch(Error& e) {
92  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
93  throw;
94  }
95  return newConnection;
96 }
97 
98 void ScalarPortReference::disconnect(const Connection& inConnection) throw (Error) {
99  NetSharedPtr connNet = *inConnection;
100  if(!connNet) {
101  Error e(eMessageIdErrorConnectionInvalid, __FUNCTION__, __FILE__, __LINE__);
102  e.saveContextData("Net is invalid", connNet);
103  throw e;
104  }
105  try {
106  ConnectionHandler handler(connNet);
107  handler.disconnectPortRefFromNet(getSharedThis());
108  Connectable::disconnect(inConnection);
109  } catch(Error& e) {
110  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
111  throw;
112  }
113  return;
114 }
115 
117 
119 
120 #ifdef GENOM_SERIALIZATION
121 template <class Archive> void ScalarPortReference::serialize(Archive& ar, unsigned int) {
122  ar & boost::serialization::base_object< PortReference >(*this);
123  ar & boost::serialization::base_object<
124  Scalar<PortReference> >(*this);
125 }
126 
127 //TO SATISFY THE LINKER
128 template void ScalarPortReference::serialize<boost::archive::binary_iarchive>(
129  boost::archive::binary_iarchive& ar, const unsigned int);
130 
131 template void ScalarPortReference::serialize<boost::archive::binary_oarchive>(
132  boost::archive::binary_oarchive& ar, const unsigned int);
133 
134 #endif //GENOM_SERIALIZATION
135 }// namespace generic
136 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
virtual void accept(BaseVisitor &inoutVisitor)
boost::shared_ptr< Instance > InstanceSharedPtr
virtual Connection connect(const NetSharedPtr &inNet)
Represents areference to a standalone port.
A single object with no child objects.
Definition: Scalar.hpp:34
Represents the usable instance of a port of a cell in another cell.
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
boost::shared_ptr< ScalarPortReference > ScalarPortReferenceSharedPtr
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
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
void disconnectPortRefFromNet(const PortReferenceSharedPtr &inPort)
virtual ScalarPortReferenceSharedPtr newScalarPortReferencePtr(const InstanceSharedPtr &inInstancePtr, const PortSharedPtr &inPortPtr, const PortBundleReferenceSharedPtr &inParentCollection=PortBundleReferenceSharedPtr())
boost::shared_ptr< Port > PortSharedPtr
boost::shared_ptr< PortBundleReference > PortBundleReferenceSharedPtr
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73