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