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