torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScalarPort.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 #include <iostream>
17 #ifndef HAVE_CONFIG_H
18 #include "torc/generic/config.h"
19 #endif
20 
21 //BOOST
22 #ifdef GENOM_SERIALIZATION
23 #include <boost/archive/binary_iarchive.hpp>
24 #include <boost/archive/binary_oarchive.hpp>
25 #include <boost/serialization/base_object.hpp>
26 #include <boost/serialization/export.hpp>
27 #endif //GENOM_SERIALIZATION
29 #include "torc/generic/Net.hpp"
33 
34 #ifdef GENOM_SERIALIZATION
35 BOOST_CLASS_EXPORT(torc::generic::ScalarPort)
36 #endif //GENOM_SERIALIZATION
37 namespace torc {
38 namespace generic {
39 
40 /**
41  * Create a scalar port.
42  *
43  * @param[in] inName Name of the scalar port to be created.
44  * @param[in] inDirection Direction of port.
45  * @param[in] inViewPtr Pointer to parented(View) object.
46  * @param[in] inOriginalName Original name of the scalar port [optional].
47  *
48  * @return Pointer to created scalar port.
49  **/
51  const EPortDirection& inDirection, const ViewSharedPtr& inViewPtr,
52  const PortBundleSharedPtr& inParentCollection, const std::string& inOriginalName)
53  throw (Error) {
54  try {
55  ScalarPortSharedPtr newScalarPort;
56  create(newScalarPort);
57  newScalarPort->setName(inName);
58  newScalarPort->setDirection(inDirection);
59  newScalarPort->setOriginalName(inOriginalName);
60  if(inParentCollection) {
61  inParentCollection->addChild(newScalarPort);
62  } else {
63  inViewPtr->addPort(newScalarPort);
64  }
65  return newScalarPort;
66  } catch(Error& e) {
67  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
68  throw;
69  }
70 }
71 
72 void ScalarPort::accept(BaseVisitor& inoutVisitor) throw (Error) {
73  try {
74  runVisitor(*this, inoutVisitor);
75  } catch(Error& e) {
76  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
77  throw;
78  }
79 }
80 
82  if(!inNet) {
83  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
84  e.saveContextData("Pointer to the Net object does not exist", inNet);
85  throw e;
86  }
87  if(inNet->getSize() != getSize()) {
88  Error e(eMessageIdErrorItemSizeMismatch, __FUNCTION__, __FILE__, __LINE__);
89  e.saveContextData("Net Size", inNet->getSize());
90  e.saveContextData("Scalar port Size", getSize());
91  throw e;
92  }
93  Connectable::Connection newConnection;
94  try {
95  ConnectionHandler handler(inNet);
96  handler.connectPortToNet(getSharedThis());
97  newConnection = Connectable::connect(inNet);
98  } catch(Error& e) {
99  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
100  throw;
101  }
102  return newConnection;
103 }
104 
105 void ScalarPort::disconnect(const Connection& inConnection) throw (Error) {
106  NetSharedPtr net = *inConnection;
107  if(!net) {
108  Error e(eMessageIdErrorConnectionInvalid, __FUNCTION__, __FILE__, __LINE__);
109  e.saveContextData("Net is invalid", net);
110  throw e;
111  }
112  try {
113  ConnectionHandler handler(net);
114  handler.disconnectPortFromNet(getSharedThis());
115  Connectable::disconnect(inConnection);
116  } catch(Error& e) {
117  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
118  throw;
119  }
120  return;
121 }
122 
124 
126 
127 #ifdef GENOM_SERIALIZATION
128 template <class Archive> void ScalarPort::serialize(Archive& ar, unsigned int) {
129  ar & boost::serialization::base_object<Port>(*this);
130  ar & boost::serialization::base_object<
131  Scalar<Port> >(*this);
132 }
133 
134 //TO SATISFY THE LINKER
135 template void ScalarPort::serialize<boost::archive::binary_iarchive>(
136  boost::archive::binary_iarchive& ar, const unsigned int);
137 
138 template void ScalarPort::serialize<boost::archive::binary_oarchive>(
139  boost::archive::binary_oarchive& ar, const unsigned int);
140 
141 #endif //GENOM_SERIALIZATION
142 
143 }// namespace generic
144 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
virtual ScalarPortSharedPtr newScalarPortPtr(const std::string &inName, const EPortDirection &inDirection, const ViewSharedPtr &inViewPtr, const PortBundleSharedPtr &inParentCollection=PortBundleSharedPtr(), const std::string &inOriginalName=std::string())
Definition: ScalarPort.cpp:50
A single object with no child objects.
Definition: Scalar.hpp:34
boost::shared_ptr< ScalarPort > ScalarPortSharedPtr
void disconnectPortFromNet(const PortSharedPtr &inPort)
boost::shared_ptr< PortBundle > PortBundleSharedPtr
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
virtual Connection connect(const NetSharedPtr &inNet)
Definition: ScalarPort.cpp:81
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
void connectPortToNet(const PortSharedPtr &inPort)
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
Represents a standalone port.
Definition: ScalarPort.hpp:42
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
Interface for an EDIF port object.
boost::shared_ptr< View > ViewSharedPtr
virtual void accept(BaseVisitor &inoutVisitor)
Definition: ScalarPort.cpp:72
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73