00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/om/DumpRestoreConfig.hpp"
00017
00018 #ifndef HAVE_CONFIG_H
00019 #include "torc/generic/config.h"
00020 #endif
00021
00022 #include <algorithm>
00023
00024 #include <boost/bind.hpp>
00025 #include <boost/mem_fn.hpp>
00026 #ifdef GENOM_SERIALIZATION
00027 #include <boost/archive/binary_iarchive.hpp>
00028 #include <boost/archive/binary_oarchive.hpp>
00029 #include <boost/serialization/base_object.hpp>
00030 #include <boost/serialization/export.hpp>
00031 #endif //GENOM_SERIALIZATION
00032
00033 #include "torc/generic/om/ConnectionHandler.hpp"
00034 #include "torc/generic/util/Log.hpp"
00035 #include "torc/generic/om/Net.hpp"
00036 #include "torc/generic/om/VectorPort.hpp"
00037 #include "torc/generic/om/PortBundle.hpp"
00038
00039 #ifdef GENOM_SERIALIZATION
00040 BOOST_CLASS_EXPORT( torc::generic::VectorPort )
00041 #endif //GENOM_SERIALIZATION
00042
00043 namespace torc {
00044
00045 namespace generic {
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 VectorPortSharedPtr
00060 VectorPort::Factory::newVectorPortPtr( const std::string &inName,
00061 const PortDirection &inDirection,
00062 const ViewSharedPtr &inViewPtr,
00063 const size_t &inSize,
00064 const PortBundleSharedPtr &inParentCollection,
00065 const ChildFactorySharedPtr &inFactory,
00066 const std::string &inOriginalName ) throw(Error) {
00067 try
00068 {
00069 std::vector<size_t> limits;
00070 limits.push_back( inSize );
00071 return newVectorPortPtr(inName, inDirection,
00072 inViewPtr, limits, inParentCollection, inFactory, inOriginalName);
00073 }
00074 catch( Error &e )
00075 {
00076 e.setCurrentLocation(
00077 __FUNCTION__, __FILE__, __LINE__ );
00078 throw;
00079 }
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 VectorPortSharedPtr
00095 VectorPort::Factory::newVectorPortPtr( const std::string &inName,
00096 const PortDirection &inDirection,
00097 const ViewSharedPtr &inViewPtr,
00098 const std::vector<size_t> &inLimits,
00099 const PortBundleSharedPtr &inParentCollection,
00100 const ChildFactorySharedPtr &inFactory,
00101 const std::string &inOriginalName ) throw(Error) {
00102 try
00103 {
00104 VectorPortSharedPtr newVectorPort;
00105 create( newVectorPort );
00106 newVectorPort->setName(inName);
00107 newVectorPort->setDirection( inDirection ),
00108 newVectorPort->constructChildren( inFactory, inLimits);
00109 newVectorPort->setOriginalName( inOriginalName );
00110 if( inParentCollection )
00111 {
00112 inParentCollection->addChild( newVectorPort );
00113 }
00114 else
00115 {
00116 inViewPtr->addPort( newVectorPort );
00117 }
00118 return newVectorPort;
00119 }
00120 catch( Error &e )
00121 {
00122 e.setCurrentLocation(
00123 __FUNCTION__, __FILE__, __LINE__ );
00124 throw;
00125 }
00126 }
00127 void
00128 VectorPort::accept(BaseVisitor & inoutVisitor) throw(Error) {
00129 try {
00130 runVisitor( *this, inoutVisitor );
00131 }
00132 catch( Error &e )
00133 {
00134 e.setCurrentLocation(
00135 __FUNCTION__, __FILE__, __LINE__ );
00136 throw;
00137 }
00138 }
00139
00140 void
00141 VectorPort::setParent(
00142 const ViewSharedPtr &inParent ) throw() {
00143 ParentedObject<View>::setParent( inParent );
00144 BaseVectorType::List children;
00145 getCreatedChildren( children );
00146 std::for_each( children.begin(), children.end(),
00147 boost::bind( boost::mem_fn(
00148 &Port::setParent), _1, getParent() ));
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 Connectable::Connection
00160 VectorPort::connect(const NetSharedPtr &inNet) throw(Error) {
00161 if( !inNet )
00162 {
00163 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00164 __FUNCTION__, __FILE__, __LINE__ );
00165 e.saveContextData("Pointer to the Net object does not exist", inNet);
00166 throw e;
00167 }
00168 if( inNet->getSize() != getSize() )
00169 {
00170 Error e( eMessageIdErrorItemSizeMismatch,
00171 __FUNCTION__, __FILE__, __LINE__ );
00172 e.saveContextData("Net Size", inNet->getSize());
00173 e.saveContextData("Vector Net Size", getSize() );
00174 throw e;
00175 }
00176 Connectable::Connection newConnection;
00177 try
00178 {
00179 ConnectionHandler handler( inNet );
00180 handler.connectPortToNet( getSharedThis() );
00181 newConnection = Connectable::connect( inNet );
00182 }
00183 catch( Error &e )
00184 {
00185 e.setCurrentLocation(
00186 __FUNCTION__, __FILE__, __LINE__ );
00187 throw;
00188 }
00189 return newConnection;
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 void
00202 VectorPort::disconnect(
00203 const Connectable::Connection &inConnection) throw(Error) {
00204 NetSharedPtr net = *inConnection;
00205 if( !net )
00206 {
00207 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00208 __FUNCTION__, __FILE__, __LINE__ );
00209 e.saveContextData("Pointer to the Net object does not exist", net);
00210 throw e;
00211 }
00212 try
00213 {
00214 ConnectionHandler handler( net );
00215 handler.disconnectPortFromNet( getSharedThis() );
00216 Connectable::disconnect( inConnection );
00217 }
00218 catch( Error &e )
00219 {
00220 e.setCurrentLocation(
00221 __FUNCTION__, __FILE__, __LINE__ );
00222 throw;
00223 }
00224 }
00225
00226 void
00227 VectorPort::getConnectedNets(
00228 std::vector< NetSharedPtr > &outNets,
00229 bool inSkipChildConnections
00230 ) const throw(Error) {
00231 Port::getConnectedNets( outNets );
00232 if( !inSkipChildConnections )
00233 {
00234 BaseVectorType::List children;
00235 getCreatedChildren( children );
00236
00237 BaseVectorType::List::iterator port = children.begin();
00238 BaseVectorType::List::iterator pEnd = children.end();
00239 for(; port != pEnd; ++port )
00240 {
00241 (*port)->getConnectedNets ( outNets, true );
00242 }
00243 }
00244 return;
00245 }
00246
00247 void
00248 VectorPort::onChildCreate( const boost::shared_ptr<BaseVectorType::ChildType> &inCreatedChild
00249 ) const throw(Error) {
00250 inCreatedChild->setName( getName() );
00251 }
00252
00253 VectorPort::VectorPort()
00254 : Port(),
00255 BaseVectorType() {
00256 }
00257
00258 VectorPort::~VectorPort() throw() {
00259 torc::generic::log("Vector Port destroyed\n");
00260 }
00261
00262 #ifdef GENOM_SERIALIZATION
00263 template<class Archive> void
00264 VectorPort::serialize( Archive &ar, unsigned int ) {
00265 ar & boost::serialization::base_object< Port >( *this );
00266 ar & boost::serialization::base_object< BaseVectorType >( *this );
00267 }
00268
00269
00270 template void
00271 VectorPort::serialize<boost::archive::binary_iarchive>(
00272 boost::archive::binary_iarchive & ar, const unsigned int);
00273
00274 template void
00275 VectorPort::serialize<boost::archive::binary_oarchive>(
00276 boost::archive::binary_oarchive & ar, const unsigned int);
00277
00278 #endif //GENOM_SERIALIZATION
00279
00280
00281 }
00282
00283 }