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 #ifdef GENOM_SERIALIZATION
00023 #include <boost/archive/binary_iarchive.hpp>
00024 #include <boost/archive/binary_oarchive.hpp>
00025 #include <boost/serialization/base_object.hpp>
00026 #include <boost/serialization/export.hpp>
00027 #endif //GENOM_SERIALIZATION
00028
00029 #include "torc/generic/om/ConnectionHandler.hpp"
00030 #include "torc/generic/util/Log.hpp"
00031 #include "torc/generic/om/Net.hpp"
00032 #include "torc/generic/om/VectorPortBit.hpp"
00033 #include "torc/generic/om/VisitorType.hpp"
00034
00035 #ifdef GENOM_SERIALIZATION
00036 BOOST_CLASS_EXPORT( torc::generic::VectorPortBit )
00037 #endif //GENOM_SERIALIZATION
00038
00039 namespace torc {
00040
00041 namespace generic {
00042
00043 void
00044 VectorPortBit::accept(
00045 BaseVisitor & inoutVisitor) throw(Error) {
00046 try
00047 {
00048 runVisitor( *this, inoutVisitor );
00049 }
00050 catch( Error &e )
00051 {
00052 e.setCurrentLocation(
00053 __FUNCTION__, __FILE__, __LINE__ );
00054 throw;
00055 }
00056 }
00057
00058 Connectable::Connection
00059 VectorPortBit::connect(
00060 const NetSharedPtr &inNet) throw(Error) {
00061 if( !inNet )
00062 {
00063 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00064 __FUNCTION__, __FILE__, __LINE__ );
00065 e.saveContextData("Pointer to the Net object does not exist", inNet);
00066 throw e;
00067 }
00068 if( inNet->getSize() != getSize() )
00069 {
00070 Error e( eMessageIdErrorItemSizeMismatch,
00071 __FUNCTION__, __FILE__, __LINE__ );
00072 e.saveContextData("Net Size", inNet->getSize());
00073 e.saveContextData("Vector port bit Size", getSize() );
00074 throw e;
00075 }
00076 Connectable::Connection newConnection;
00077 try
00078 {
00079 ConnectionHandler handler( inNet );
00080 handler.connectPortToNet( getSharedThis() );
00081 newConnection = Connectable::connect( inNet );
00082 }
00083 catch( Error &e )
00084 {
00085 e.setCurrentLocation(
00086 __FUNCTION__, __FILE__, __LINE__ );
00087 throw;
00088 }
00089 return newConnection;
00090 }
00091
00092
00093 void
00094 VectorPortBit::disconnect(
00095 const Connection &inConnection) throw(Error) {
00096 NetSharedPtr net = *inConnection;
00097 if( !net )
00098 {
00099 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00100 __FUNCTION__, __FILE__, __LINE__ );
00101 e.saveContextData("Pointer to the Net object does not exist", net);
00102 throw e;
00103 }
00104 try
00105 {
00106 ConnectionHandler handler( net );
00107 handler.disconnectPortFromNet( getSharedThis() );
00108 Connectable::disconnect( inConnection );
00109 }
00110 catch( Error &e )
00111 {
00112 e.setCurrentLocation(
00113 __FUNCTION__, __FILE__, __LINE__ );
00114 throw;
00115 }
00116 }
00117
00118 void
00119 VectorPortBit::getConnectedNets(
00120 std::vector< NetSharedPtr > &outNets,
00121 bool inSkipChildConnections
00122 ) const throw(Error) {
00123
00124 Port::getConnectedNets( outNets );
00125
00126
00127
00128 if( !inSkipChildConnections )
00129 {
00130 VectorBit<Net>::List parentConnections;
00131 Composite<Port>::Pointer parent = getParentCollection();
00132 if( !parent )
00133 {
00134 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00135 __FUNCTION__, __FILE__, __LINE__ );
00136 e.saveContextData("Pointer to parent collection does not exist", parent);
00137 throw e;
00138 }
00139 if( eCompositionTypeVector
00140 != parent->getCompositionType() )
00141 {
00142 Error e( eMessageIdErrorCompositionTypeMismatch,
00143 __FUNCTION__, __FILE__, __LINE__ );
00144 e.saveContextData("Composition type mismatch", parent->getCompositionType());
00145 throw e;
00146 }
00147 parent->getConnectedNets( parentConnections, true );
00148 VectorBit<Net>::List::iterator connNet
00149 = parentConnections.begin();
00150 VectorBit<Net>::List::iterator connNetEnd
00151 = parentConnections.end();
00152 const std::vector<VectorBit<Net>::SizeType> &myIndex = getIndices();
00153 for(; connNet != connNetEnd; ++connNet )
00154 {
00155 Composite<Net>::Pointer cousin;
00156 if( eCompositionTypeVector
00157 == (*connNet)->getCompositionType() )
00158 {
00159 cousin = (*connNet)->get( myIndex );
00160
00161
00162 }
00163 else
00164 {
00165 VectorBit<Net>::List bChildren;
00166 (*connNet)->getChildren( bChildren );
00167 cousin = bChildren[ getAbsoluteIndex() ];
00168
00169 }
00170 if( !cousin )
00171 {
00172 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00173 __FUNCTION__, __FILE__, __LINE__ );
00174 e.saveContextData("Pointer to item does not exist", cousin);
00175 throw e;
00176 }
00177 outNets.push_back( cousin );
00178 }
00179 }
00180 return;
00181 }
00182
00183 VectorPortBit::VectorPortBit()
00184 :Port(),
00185 VectorBit<Port>() {
00186 }
00187
00188 VectorPortBit::~VectorPortBit() throw() {
00189 torc::generic::log("Vector Port bit destroyed\n");
00190 }
00191
00192 #ifdef GENOM_SERIALIZATION
00193 template<class Archive> void
00194 VectorPortBit::serialize( Archive &ar, unsigned int ) {
00195 ar & boost::serialization::base_object< Port >( *this );
00196 ar & boost::serialization::base_object< VectorBit<Port> >(*this);
00197 }
00198
00199 #endif //GENOM_SERIALIZATION
00200
00201 }
00202
00203 }