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/NetBundle.hpp"
00033
00034 #ifdef GENOM_SERIALIZATION
00035 BOOST_CLASS_EXPORT( torc::generic::NetBundle )
00036 #endif //GENOM_SERIALIZATION
00037
00038 namespace torc {
00039
00040 namespace generic {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 NetBundleSharedPtr
00052 NetBundle::Factory::newNetBundlePtr( const std::string &inName,
00053 const ViewSharedPtr &inViewPtr,
00054 const NetBundleSharedPtr &inParentCollection,
00055 const std::string &inOriginalName ) throw(Error) {
00056 try
00057 {
00058 NetBundleSharedPtr newNetBundle;
00059 create( newNetBundle );
00060 newNetBundle->setName(inName);
00061 newNetBundle->setOriginalName( inOriginalName );
00062 if( inParentCollection )
00063 {
00064 inParentCollection->addChild( newNetBundle );
00065 }
00066 else
00067 {
00068 inViewPtr->addNet( newNetBundle );
00069 }
00070 return newNetBundle;
00071 }
00072 catch( Error &e )
00073 {
00074 e.setCurrentLocation(
00075 __FUNCTION__, __FILE__, __LINE__ );
00076 throw;
00077 }
00078 }
00079
00080 void
00081 NetBundle::accept(BaseVisitor & inoutVisitor) throw(Error) {
00082 runVisitor( *this, inoutVisitor );
00083 }
00084
00085 void
00086 NetBundle::setParent(
00087 const ViewSharedPtr &inParent ) throw() {
00088 ParentedObject<View>::setParent( inParent );
00089 applyOnAllChildren(
00090 boost::bind( boost::mem_fn(
00091 &Net::setParent), _1, getParent() ));
00092 }
00093
00094
00095 Connectable::Connection
00096 NetBundle::connect(
00097 const NetSharedPtr & inNet) throw(Error) {
00098 if( !inNet )
00099 {
00100 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00101 __FUNCTION__, __FILE__, __LINE__ );
00102 e.saveContextData("Pointer to Net", inNet);
00103 throw e;
00104 }
00105 if( inNet->getSize() != getSize() )
00106 {
00107 Error e( eMessageIdErrorItemSizeMismatch,
00108 __FUNCTION__, __FILE__, __LINE__ );
00109 e.saveContextData("Net Size", inNet->getSize());
00110 e.saveContextData("NetBundle Size", getSize() );
00111 throw e;
00112 }
00113 Bundle<Net>::List children;
00114 getChildren( children );
00115 Bundle<Net>::List netChildren;
00116 inNet->getChildren( netChildren );
00117 Bundle<Net>::List::iterator childNet = children.begin();
00118 Bundle<Net>::List::iterator childEnd = children.end();
00119 Bundle<Net>::List::iterator net = netChildren.begin();
00120 for(; childNet != childEnd; ++childNet, ++net )
00121 {
00122 try
00123 {
00124 (*childNet)->connect( *net );
00125 }
00126 catch( Error &e )
00127 {
00128 e.setCurrentLocation(
00129 __FUNCTION__, __FILE__, __LINE__ );
00130 throw;
00131 }
00132 }
00133 return Connectable::connect( inNet );
00134 }
00135
00136 void
00137 NetBundle::disconnect(
00138 const Connection & inConnection) throw(Error)
00139 {
00140 NetSharedPtr connNet = *inConnection;
00141 Bundle<Net>::List children;
00142 getChildren( children );
00143 Bundle<Net>::List netChildren;
00144 connNet->getChildren( netChildren );
00145 Bundle<Net>::List::iterator childNet = children.begin();
00146 Bundle<Net>::List::iterator childEnd = children.end();
00147 Bundle<Net>::List::iterator net = netChildren.begin();
00148
00149
00150
00151
00152
00153 for(; childNet != childEnd; ++childNet, ++net )
00154 {
00155 try
00156 {
00157 (*childNet)->Connectable::disconnect( *net );
00158 }
00159 catch( Error &e )
00160 {
00161 e.setCurrentLocation(
00162 __FUNCTION__, __FILE__, __LINE__ );
00163 throw;
00164 }
00165 }
00166 Connectable::disconnect( inConnection );
00167 }
00168
00169 void
00170 NetBundle::disconnect() throw(Error) {
00171 Bundle<Net>::List children;
00172 getChildren( children );
00173 Bundle<Net>::List::iterator childNet = children.begin();
00174 Bundle<Net>::List::iterator childEnd = children.end();
00175 for(; childNet != childEnd; ++childNet )
00176 {
00177 try
00178 {
00179 (*childNet)->disconnect();
00180 }
00181 catch( Error &e )
00182 {
00183 e.setCurrentLocation(
00184 __FUNCTION__, __FILE__, __LINE__ );
00185 throw;
00186 }
00187 }
00188 Net::disconnect();
00189 }
00190
00191 NetBundle::NetBundle()
00192 :Net(),
00193 Bundle<Net>() {
00194 }
00195
00196 NetBundle::~NetBundle() throw() {
00197 }
00198
00199 #ifdef GENOM_SERIALIZATION
00200 template<class Archive> void
00201 NetBundle::serialize( Archive &ar, unsigned int ) {
00202 ar & boost::serialization::base_object< Net >( *this );
00203 ar & boost::serialization::base_object< Bundle<Net> >(*this);
00204 }
00205
00206
00207 template void
00208 NetBundle::serialize<boost::archive::binary_iarchive>(
00209 boost::archive::binary_iarchive & ar, const unsigned int);
00210
00211 template void
00212 NetBundle::serialize<boost::archive::binary_oarchive>(
00213 boost::archive::binary_oarchive & ar, const unsigned int);
00214
00215 #endif //GENOM_SERIALIZATION
00216
00217 }
00218
00219 }