00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <iostream>
00017 #include "torc/generic/om/DumpRestoreConfig.hpp"
00018
00019 #ifndef HAVE_CONFIG_H
00020 #include "torc/generic/config.h"
00021 #endif
00022
00023
00024 #ifdef GENOM_SERIALIZATION
00025 #include <boost/archive/binary_iarchive.hpp>
00026 #include <boost/archive/binary_oarchive.hpp>
00027 #include <boost/serialization/base_object.hpp>
00028 #include <boost/serialization/export.hpp>
00029 #endif //GENOM_SERIALIZATION
00030
00031 #include "torc/generic/om/ConnectionHandler.hpp"
00032 #include "torc/generic/om/Net.hpp"
00033 #include "torc/generic/om/ScalarPort.hpp"
00034 #include "torc/generic/om/PortBundle.hpp"
00035 #include "torc/generic/om/VisitorType.hpp"
00036
00037 #ifdef GENOM_SERIALIZATION
00038 BOOST_CLASS_EXPORT( torc::generic::ScalarPort )
00039 #endif //GENOM_SERIALIZATION
00040
00041 namespace torc {
00042
00043 namespace generic {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 ScalarPortSharedPtr
00056 ScalarPort::Factory::newScalarPortPtr( const std::string &inName,
00057 const PortDirection &inDirection,
00058 const ViewSharedPtr &inViewPtr,
00059 const PortBundleSharedPtr &inParentCollection,
00060 const std::string &inOriginalName ) throw(Error) {
00061 try
00062 {
00063 ScalarPortSharedPtr newScalarPort;
00064 create( newScalarPort );
00065 newScalarPort->setName(inName);
00066 newScalarPort->setDirection( inDirection ),
00067 newScalarPort->setOriginalName( inOriginalName );
00068 if( inParentCollection )
00069 {
00070 inParentCollection->addChild( newScalarPort );
00071 }
00072 else
00073 {
00074 inViewPtr->addPort( newScalarPort );
00075 }
00076 return newScalarPort;
00077 }
00078 catch( Error &e )
00079 {
00080 e.setCurrentLocation(
00081 __FUNCTION__, __FILE__, __LINE__ );
00082 throw;
00083 }
00084 }
00085
00086 void
00087 ScalarPort::accept(BaseVisitor & inoutVisitor) throw(Error) {
00088 try
00089 {
00090 runVisitor( *this, inoutVisitor );
00091 }
00092 catch( Error &e )
00093 {
00094 e.setCurrentLocation(
00095 __FUNCTION__, __FILE__, __LINE__ );
00096 throw;
00097 }
00098 }
00099
00100 Connectable::Connection
00101 ScalarPort::connect(
00102 const NetSharedPtr &inNet) throw(Error) {
00103 if( !inNet )
00104 {
00105 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00106 __FUNCTION__, __FILE__, __LINE__ );
00107 e.saveContextData("Pointer to the Net object does not exist", inNet);
00108 throw e;
00109 }
00110 if( inNet->getSize() != getSize() )
00111 {
00112 Error e( eMessageIdErrorItemSizeMismatch,
00113 __FUNCTION__, __FILE__, __LINE__ );
00114 e.saveContextData("Net Size", inNet->getSize());
00115 e.saveContextData("Scalar port Size", getSize() );
00116 throw e;
00117 }
00118 Connectable::Connection newConnection;
00119 try
00120 {
00121 ConnectionHandler handler( inNet );
00122 handler.connectPortToNet( getSharedThis() );
00123 newConnection = Connectable::connect( inNet );
00124 }
00125 catch( Error &e )
00126 {
00127 e.setCurrentLocation(
00128 __FUNCTION__, __FILE__, __LINE__ );
00129 throw;
00130 }
00131 return newConnection;
00132 }
00133
00134 void
00135 ScalarPort::disconnect(
00136 const Connection & inConnection) throw(Error) {
00137 NetSharedPtr net = *inConnection;
00138 if( !net )
00139 {
00140 Error e( eMessageIdErrorConnectionInvalid,
00141 __FUNCTION__, __FILE__, __LINE__ );
00142 e.saveContextData("Net is invalid", net);
00143 throw e;
00144 }
00145 try
00146 {
00147 ConnectionHandler handler( net );
00148 handler.disconnectPortFromNet( getSharedThis() );
00149 Connectable::disconnect( inConnection );
00150 }
00151 catch( Error &e )
00152 {
00153 e.setCurrentLocation(
00154 __FUNCTION__, __FILE__, __LINE__ );
00155 throw;
00156 }
00157 return;
00158 }
00159
00160 ScalarPort::ScalarPort()
00161 :Port(),
00162 Scalar<Port>() {
00163 }
00164
00165 ScalarPort::~ScalarPort() throw() {
00166 }
00167
00168 #ifdef GENOM_SERIALIZATION
00169 template<class Archive> void
00170 ScalarPort::serialize( Archive &ar, unsigned int ) {
00171 ar & boost::serialization::base_object<Port>( *this );
00172 ar & boost::serialization::base_object<
00173 Scalar<Port> >( *this );
00174 }
00175
00176
00177 template void
00178 ScalarPort::serialize<boost::archive::binary_iarchive>(
00179 boost::archive::binary_iarchive & ar, const unsigned int);
00180
00181 template void
00182 ScalarPort::serialize<boost::archive::binary_oarchive>(
00183 boost::archive::binary_oarchive & ar, const unsigned int);
00184
00185 #endif //GENOM_SERIALIZATION
00186
00187 }
00188
00189 }