00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_CLONING_HPP
00017 #define TORC_GENERIC_OM_CLONING_HPP
00018
00019 #include <cstdio>
00020 #include <iostream>
00021 #include <algorithm>
00022 #include <vector>
00023 #include <boost/bind.hpp>
00024 #include <boost/shared_ptr.hpp>
00025
00026 #include "torc/generic/om/PointerTypes.hpp"
00027 #include "torc/generic/util/Error.hpp"
00028
00029 #include "torc/generic/om/Root.hpp"
00030 #include "torc/generic/om/Library.hpp"
00031 #include "torc/generic/om/Cell.hpp"
00032 #include "torc/generic/om/View.hpp"
00033 #include "torc/generic/om/ScalarPort.hpp"
00034 #include "torc/generic/om/VectorPort.hpp"
00035 #include "torc/generic/om/PortBundle.hpp"
00036 #include "torc/generic/om/ScalarNet.hpp"
00037 #include "torc/generic/om/VectorNet.hpp"
00038 #include "torc/generic/om/NetBundle.hpp"
00039 #include "torc/generic/om/SingleInstance.hpp"
00040 #include "torc/generic/om/InstanceArray.hpp"
00041 #include "torc/generic/om/SingleParameter.hpp"
00042 #include "torc/generic/om/ParameterArray.hpp"
00043 #include "torc/generic/om/Property.hpp"
00044 #include "torc/generic/om/ScalarPortReference.hpp"
00045 #include "torc/generic/om/VectorPortReference.hpp"
00046 #include "torc/generic/om/PortBundleReference.hpp"
00047 #include "torc/generic/om/ObjectFactory.hpp"
00048 #include "torc/generic/om/InternalUtilityFunctions.hpp"
00049
00050 namespace torc {
00051
00052 namespace generic {
00053
00054 namespace _impl { template<typename _Tp> class Copier; }
00055
00056 extern void
00057 copyParams( const Instance &inOriginal,
00058 const InstanceSharedPtr &outCloned,
00059 const ObjectFactorySharedPtr &inFactory );
00060
00061 template<typename _Tp>
00062 boost::shared_ptr<_Tp>
00063 clone( const boost::shared_ptr<_Tp> &inPointer,
00064 const ObjectFactorySharedPtr &inFactory ) throw(Error)
00065 {
00066 try
00067 {
00068 return _impl::Copier<_Tp>()( inPointer, inFactory );
00069 }
00070 catch( Error &e )
00071 {
00072 e.setCurrentLocation(
00073 __FUNCTION__, __FILE__, __LINE__ );
00074 throw;
00075 }
00076 }
00077
00078 namespace _impl {
00079
00080 template<typename _Tp>
00081 class Copier {
00082 public:
00083 typedef _Tp Type;
00084 typedef boost::shared_ptr<Type> Pointer;
00085
00086 public:
00087
00088 Pointer
00089 operator()( const Pointer &inSource,
00090 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00091 mFactory = inFactory;
00092 throw Error( eMessageIdErrorUnsupoortedOperation,
00093 __FUNCTION__, __FILE__, __LINE__ );
00094 return mReturnVal;
00095 }
00096
00097 Copier()
00098 :mFactory(),
00099 mReturnVal() {
00100 }
00101
00102 ~Copier() throw() {
00103 }
00104
00105 private:
00106 ObjectFactorySharedPtr mFactory;
00107 Pointer mReturnVal;
00108 };
00109
00110 #if 0
00111
00112
00113 template<>
00114 class Copier<class Root>
00115 : public Root::Visitor {
00116 public:
00117 typedef Root Type;
00118 typedef boost::shared_ptr<Type> Pointer;
00119
00120 Pointer
00121 operator()( const Pointer &inSource,
00122 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00123 mFactory = inFactory;
00124 inSource->accept( *this );
00125 return mReturnVal;
00126 }
00127
00128 void
00129 visit( Root &inRoot ) throw(Error)
00130 {
00131 try
00132 {
00133 RootSharedPtr rootPtr;
00134 mFactory->create( rootPtr );
00135
00136 rootPtr->setComments( inRoot.getComments() );
00137 rootPtr->setName( inRoot.getName() );
00138 rootPtr->setLevel( inRoot.getLevel() );
00139 rootPtr->setVersion( inRoot.getVersion() );
00140
00141 std::vector< LibrarySharedPtr > libraries;
00142 inRoot.getLibraries( libraries );
00143 std::vector< LibrarySharedPtr >::iterator libIt
00144 = libraries.begin();
00145 for(; libIt != libraries.end(); ++libIt )
00146 {
00147 LibrarySharedPtr newLib = clone( *libIt, mFactory );
00148 rootPtr->addLibrary( newLib );
00149 }
00150 mReturnVal = rootPtr;
00151 }
00152 catch( Error &e )
00153 {
00154 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00155 throw;
00156 }
00157 }
00158
00159 Copier()
00160 : Type::Visitor(),
00161 mFactory(),
00162 mReturnVal() {
00163 }
00164
00165 ~Copier() throw() {
00166 }
00167
00168 private:
00169 ObjectFactorySharedPtr mFactory;
00170 Pointer mReturnVal;
00171 };
00172
00173
00174 template<>
00175 class Copier<class Library>
00176 : public Library::Visitor {
00177 public:
00178 typedef Library Type;
00179 typedef boost::shared_ptr<Type> Pointer;
00180
00181 Pointer
00182 operator()( const Pointer &inSource,
00183 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00184 mFactory = inFactory;
00185 inSource->accept( *this );
00186 return mReturnVal;
00187 }
00188
00189 void
00190 visit( Library &inLibrary ) throw(Error)
00191 try
00192 {
00193 LibrarySharedPtr libPtr;
00194 mFactory->create( libPtr );
00195
00196 libPtr->setComments ( inLibrary.getComments() );
00197 libPtr->setIsExtern ( inLibrary.getIsExtern() );
00198 libPtr->setName( inLibrary.getName() );
00199 libPtr->setParent ( inLibrary.getParent() );
00200 std::map<Unit,ScaleFactor> outScaleFactors;
00201 outScaleFactors = inLibrary.getScaleFactors();
00202 std::map<Unit,ScaleFactor>::iterator it = outScaleFactors.begin();
00203 for(; it != outScaleFactors.end(); ++it )
00204 {
00205 libPtr->setScaleFactor( (*it).first, (*it).second );
00206 }
00207 libPtr->setLevel( inLibrary.getLevel() );
00208 libPtr->setOriginalName( inLibrary.getOriginalName() );
00209 std::vector< CellSharedPtr > outCells;
00210 inLibrary.getCells( outCells );
00211 std::vector< CellSharedPtr >::iterator cellIt = outCells.begin();
00212 for(; cellIt != outCells.end(); ++cellIt )
00213 {
00214 CellSharedPtr newCell = clone( *cellIt, mFactory );
00215 libPtr->addCell( newCell );
00216 }
00217 mReturnVal = libPtr;
00218 }
00219 catch( Error &e )
00220 {
00221 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00222 throw;
00223 }
00224
00225 Copier()
00226 : Type::Visitor(),
00227 mFactory(),
00228 mReturnVal() {
00229 }
00230
00231 ~Copier() throw() {
00232 }
00233
00234 private:
00235 ObjectFactorySharedPtr mFactory;
00236 Pointer mReturnVal;
00237 };
00238
00239 #endif
00240
00241
00242 template<>
00243 class Copier<class Cell>
00244 : public Cell::Visitor {
00245 public:
00246 typedef Cell Type;
00247 typedef boost::shared_ptr<Type> Pointer;
00248
00249 Pointer
00250 operator()( const Pointer &inSource,
00251 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00252 mFactory = inFactory;
00253 inSource->accept( *this );
00254 return mReturnVal;
00255 }
00256
00257 void
00258 visit( Cell &inCell ) throw(Error)
00259 {
00260 try
00261 {
00262 CellSharedPtr cellPtr;
00263 mFactory->create( cellPtr );
00264 cellPtr->setComments ( inCell.getComments() );
00265
00266 std::list< std::string > userData;
00267 inCell.getUserData( userData );
00268 cellPtr->setUserData ( userData );
00269
00270 std::vector< StatusSharedPtr > outStatus;
00271 inCell.getStatuses( outStatus );
00272 cellPtr->setStatuses ( outStatus );
00273
00274 cellPtr->setIsExtern ( inCell.getIsExtern() );
00275 cellPtr->setName( inCell.getName() );
00276 cellPtr->setParent ( inCell.getParent() );
00277
00278 std::map< std::string, PropertySharedPtr > outProperties;
00279 inCell.getProperties( outProperties );
00280 cellPtr->setProperties( outProperties );
00281
00282 cellPtr->setType( inCell.getType() );
00283 cellPtr->setOriginalName( inCell.getOriginalName() );
00284 std::vector< ViewSharedPtr > outViews;
00285 inCell.getViews( outViews );
00286 std::vector< ViewSharedPtr >::iterator viewIt
00287 = outViews.begin();
00288 for(; viewIt != outViews.end(); ++viewIt )
00289 {
00290 ViewSharedPtr newView = clone( *viewIt, mFactory );
00291 cellPtr->addView( newView );
00292 }
00293 mReturnVal = cellPtr;
00294 }
00295 catch( Error &e )
00296 {
00297 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00298 throw;
00299 }
00300 }
00301
00302 Copier()
00303 : Type::Visitor(),
00304 mFactory(),
00305 mReturnVal() {
00306 }
00307
00308 ~Copier() throw() {
00309 }
00310
00311 private:
00312 ObjectFactorySharedPtr mFactory;
00313 Pointer mReturnVal;
00314 };
00315
00316
00317 template<>
00318 class Copier<class View>
00319 : public View::Visitor {
00320 public:
00321 typedef View Type;
00322 typedef boost::shared_ptr<Type> Pointer;
00323
00324 Pointer
00325 operator()( const Pointer &inSource,
00326 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00327 mFactory = inFactory;
00328 inSource->accept( *this );
00329 return mReturnVal;
00330 }
00331
00332 void
00333 visit( View &inView ) throw(Error)
00334 {
00335 try
00336 {
00337 ViewSharedPtr viewPtr;
00338 mFactory->create( viewPtr );
00339 viewPtr->setComments ( inView.getComments() );
00340
00341 std::list< std::string > userData;
00342 inView.getUserData( userData );
00343 viewPtr->setUserData ( userData );
00344
00345 std::vector< StatusSharedPtr > outStatus;
00346 inView.getStatuses( outStatus );
00347 viewPtr->setStatuses ( outStatus );
00348
00349 viewPtr->setIsExtern ( inView.getIsExtern() );
00350 viewPtr->setName( inView.getName() );
00351 viewPtr->setParent ( inView.getParent() );
00352 viewPtr->setType( inView.getType() );
00353
00354 std::map< std::string, PropertySharedPtr > outProperties;
00355 inView.getProperties( outProperties );
00356 viewPtr->setProperties( outProperties );
00357 viewPtr->setOriginalName( inView.getOriginalName() );
00358
00359 ParameterMapSharedPtr oldParams = inView.getParameters();
00360 ParameterMapSharedPtr newParams = viewPtr->getParameters();
00361 ParameterContext oldCtx = inView.getParameterContext();
00362 ParameterContext newCtx = viewPtr->getParameterContext();
00363 std::map< std::string,ParameterSharedPtr > params;
00364 oldParams->getAllParameters( oldCtx, params );
00365 for( std::map< std::string,ParameterSharedPtr >::iterator it
00366 = params.begin(); it != params.end(); ++it )
00367 {
00368 ParameterSharedPtr clonedParam
00369 = clone( (*it).second, mFactory );
00370 newParams->set( newCtx, (*it).first, clonedParam );
00371 }
00372
00373 std::vector< InstanceSharedPtr > outInstances;
00374 inView.getInstances( outInstances );
00375 std::vector< InstanceSharedPtr >::iterator instIt
00376 = outInstances.begin();
00377 for(; instIt != outInstances.end(); ++instIt )
00378 {
00379 InstanceSharedPtr newInst = clone( *instIt, mFactory );
00380 viewPtr->addInstance( newInst );
00381 }
00382
00383 std::vector< PortSharedPtr > outPorts;
00384 inView.getPorts( outPorts );
00385 std::vector< PortSharedPtr >::iterator portIt
00386 = outPorts.begin();
00387 for(; portIt != outPorts.end(); ++portIt )
00388 {
00389 PortSharedPtr newPort = clone( *portIt, mFactory );
00390 viewPtr->addPort( newPort );
00391 }
00392
00393 std::vector< PermutableSharedPtr > outPermutables;
00394 inView.getPermutables( outPermutables );
00395 viewPtr->setPermutables( outPermutables );
00396
00397 std::vector< InterfaceJoinedInfoSharedPtr > outJoinedInfos;
00398 inView.getInterfaceJoinedInfos( outJoinedInfos );
00399 viewPtr->setInterfaceJoinedInfos( outJoinedInfos );
00400
00401 std::vector< NetSharedPtr > outNets;
00402 inView.getNets( outNets );
00403 std::vector< NetSharedPtr >::iterator netIt
00404 = outNets.begin();
00405 for(; netIt != outNets.end(); ++netIt )
00406 {
00407 NetSharedPtr netPtr = clone( *netIt, mFactory );
00408 viewPtr->addNet( netPtr );
00409 connectNets( *netIt, netPtr, viewPtr );
00410 }
00411
00412 mReturnVal = viewPtr;
00413 }
00414 catch( Error &e )
00415 {
00416 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00417 throw;
00418 }
00419 }
00420
00421 void
00422 connectNets( const NetSharedPtr &inNet,
00423 const NetSharedPtr &outNet,
00424 const ViewSharedPtr &inView )
00425 {
00426 if( eCompositionTypeBundle
00427 == inNet->getCompositionType() )
00428 {
00429 std::vector< NetSharedPtr > inChildren;
00430 std::vector< NetSharedPtr > outChildren;
00431 inNet->getChildren( inChildren );
00432 outNet->getChildren( outChildren );
00433 std::vector< NetSharedPtr >::iterator inIt
00434 = inChildren.begin();
00435 std::vector< NetSharedPtr >::iterator outIt
00436 = outChildren.begin();
00437 for( ; inIt != inChildren.end(); ++inIt, ++outIt )
00438 {
00439 connectNets( *inIt, *outIt, inView );
00440 }
00441 }
00442 cloneConnection( inNet, outNet, inView );
00443 }
00444
00445 void
00446 cloneConnection( const NetSharedPtr &inNet,
00447 const NetSharedPtr &outNet,
00448 const ViewSharedPtr &inView )
00449 {
00450 try
00451 {
00452 std::vector< PortSharedPtr > connectedPorts;
00453 inNet->getConnectedPorts( connectedPorts, true );
00454 for( std::vector< PortSharedPtr >::iterator it
00455 = connectedPorts.begin(); it != connectedPorts.end();
00456 ++it )
00457 {
00458 std::vector<std::string> nestedNames;
00459 PortSharedPtr actualPort = *it;
00460 PortSharedPtr port = actualPort;
00461 while( port )
00462 {
00463 if( eCompositionTypeVectorBit
00464 != port->getCompositionType())
00465 nestedNames.push_back( port->getName() );
00466 port = port->getParentCollection();
00467 }
00468 std::string portName = *nestedNames.rbegin();
00469 PortSharedPtr targetPort = inView->findPort( portName );
00470 if( !targetPort )
00471 {
00472
00473 }
00474 if( nestedNames.size() > 1 )
00475 {
00476 findLeafConnectable( nestedNames, targetPort );
00477 }
00478 std::vector<size_t> indices;
00479 if( eCompositionTypeVectorBit
00480 == actualPort->getCompositionType() )
00481 {
00482 indices = IndexFinder<Port, VectorPortBit>()(
00483 actualPort);
00484 }
00485 connectNetToElement( indices, targetPort, outNet );
00486 }
00487 std::vector< PortReferenceSharedPtr > connectedPortRefs;
00488 inNet->getConnectedPortRefs(
00489 connectedPortRefs, true );
00490 for( std::vector< PortReferenceSharedPtr >::iterator it
00491 = connectedPortRefs.begin();
00492 it != connectedPortRefs.end(); ++it )
00493 {
00494 std::vector<std::string> nestedNames;
00495 PortReferenceSharedPtr actualPort = *it;
00496 PortReferenceSharedPtr port = *it;
00497 InstanceSharedPtr instance;
00498 while( port )
00499 {
00500 if( eCompositionTypeVectorBit
00501 != port->getCompositionType())
00502 {
00503 nestedNames.push_back( port->getName() );
00504 instance = port->getParent();
00505 }
00506 port = port->getParentCollection();
00507 }
00508 std::vector<size_t> indices;
00509 if( eCompositionTypeVectorBit
00510 == instance->getCompositionType() )
00511 {
00512 indices
00513 = IndexFinder<Instance, InstanceArrayMember>()(
00514 instance );
00515 instance = instance->getParentCollection();
00516 }
00517 InstanceSharedPtr targetInst = inView->findInstance(
00518 instance->getName() );
00519 if( !indices.empty() )
00520 {
00521 targetInst = targetInst->get( indices );
00522 }
00523 std::string portName = *nestedNames.rbegin();
00524 PortReferenceSharedPtr targetPort
00525 = targetInst->findPortReference( portName );
00526 if( !targetPort )
00527 {
00528
00529 }
00530 if( nestedNames.size() > 1 )
00531 {
00532 findLeafConnectable( nestedNames, targetPort );
00533 }
00534 std::vector<size_t> portIndices;
00535 if( eCompositionTypeVectorBit
00536 == actualPort->getCompositionType() )
00537 {
00538 portIndices = IndexFinder<PortReference,
00539 VectorPortBitReference>()( actualPort );
00540 }
00541 connectNetToElement( portIndices, targetPort, outNet );
00542 }
00543 std::vector< PortListSharedPtr > connectedPortLists;
00544 inNet->getConnectedPortLists( connectedPortLists );
00545 for( std::vector< PortListSharedPtr >::iterator it
00546 = connectedPortLists.begin();
00547 it != connectedPortLists.end(); ++it )
00548 {
00549 PortListSharedPtr cloned
00550 = clone( *it, mFactory );
00551 std::list< PortList::PortListElement > elements;
00552 (*it)->getChildren( elements );
00553 for( std::list< PortList::PortListElement >::iterator element
00554 = elements.begin(); element != elements.end();
00555 ++element )
00556 {
00557 switch( (*element).getType() )
00558 {
00559 case PortList::PortListElement::eElementTypePort:
00560 {
00561 std::vector<std::string> nestedNames;
00562 PortSharedPtr actualPort = (*element).getPort();
00563 PortSharedPtr port = actualPort;
00564 while( port )
00565 {
00566 if( eCompositionTypeVectorBit
00567 != port->getCompositionType())
00568 nestedNames.push_back( port->getName() );
00569 port = port->getParentCollection();
00570 }
00571 std::vector<std::string>::reverse_iterator name
00572 = nestedNames.rbegin();
00573 std::string portName = *name;
00574 PortSharedPtr targetPort = inView->findPort( portName );
00575 if( nestedNames.size() > 1 )
00576 {
00577 findLeafConnectable( nestedNames, targetPort );
00578 }
00579 if( eCompositionTypeVectorBit
00580 == actualPort->getCompositionType() )
00581 {
00582 targetPort = targetPort->get(
00583 IndexFinder<Port, VectorPortBit>()(
00584 actualPort ) );
00585 }
00586 cloned->addChildPort( targetPort );
00587 break;
00588 }
00589 case PortList::PortListElement::eElementTypePortReference:
00590 {
00591 std::vector<std::string> nestedNames;
00592 PortReferenceSharedPtr actualPort = (*element).getPortReference();
00593 PortReferenceSharedPtr port = actualPort;
00594 InstanceSharedPtr instance;
00595 while( port )
00596 {
00597 if( eCompositionTypeVectorBit
00598 != port->getCompositionType())
00599 {
00600 nestedNames.push_back( port->getName() );
00601 instance = port->getParent();
00602 }
00603 port = port->getParentCollection();
00604 }
00605 std::vector<size_t> indices;
00606 if( eCompositionTypeVectorBit
00607 == instance->getCompositionType() )
00608 {
00609 indices
00610 = IndexFinder<Instance, InstanceArrayMember>()(
00611 instance );
00612 instance = instance->getParentCollection();
00613 }
00614 InstanceSharedPtr targetInst = inView->findInstance(
00615 instance->getName() );
00616 if( !indices.empty() )
00617 {
00618 targetInst = targetInst->get( indices );
00619 }
00620 std::string portName = *nestedNames.rbegin();
00621 PortReferenceSharedPtr targetPort
00622 = targetInst->findPortReference( portName );
00623 if( !targetPort )
00624 {
00625
00626 }
00627 if( nestedNames.size() > 1 )
00628 {
00629 findLeafConnectable( nestedNames, targetPort );
00630 }
00631 if( eCompositionTypeVectorBit
00632 == actualPort->getCompositionType() )
00633 {
00634 targetPort = targetPort->get(
00635 IndexFinder<PortReference, VectorPortBitReference>()(
00636 actualPort ) );
00637 }
00638 cloned->addChildPortReference( targetPort );
00639 break;
00640 }
00641 }
00642 }
00643 cloned->connect( outNet );
00644 }
00645 }
00646 catch( Error &e )
00647 {
00648 e.setCurrentLocation(
00649 __FUNCTION__, __FILE__, __LINE__ );
00650 throw;
00651 }
00652 }
00653
00654 Copier()
00655 : Type::Visitor(),
00656 mFactory(),
00657 mReturnVal() {
00658 }
00659
00660 ~Copier() throw() {
00661 }
00662
00663 private:
00664 ObjectFactorySharedPtr mFactory;
00665 Pointer mReturnVal;
00666 };
00667
00668
00669 template<typename _PointerType>
00670 void
00671 copyObject( ScalarPort &inPort,
00672 ObjectFactorySharedPtr &inFactory,
00673 _PointerType &outPointer ) throw(Error)
00674 {
00675 try
00676 {
00677 ScalarPortSharedPtr scalarPort;
00678 inFactory->create( scalarPort );
00679 scalarPort->setComments( inPort.getComments() );
00680 scalarPort->setName( inPort.getName() );
00681 scalarPort->setDirection( inPort.getDirection() );
00682 scalarPort->setOriginalName( inPort.getOriginalName() );
00683 scalarPort->setAttributes( inPort.getAttributes() );
00684 scalarPort->setIsExtern( inPort.getIsExtern() );
00685 scalarPort->setParent( inPort.getParent() );
00686 scalarPort->setParentCollection( inPort.getParentCollection() );
00687
00688 std::list< std::string > userData;
00689 inPort.getUserData( userData );
00690 scalarPort->setUserData ( userData );
00691
00692 std::map< std::string, PropertySharedPtr > outProperties;
00693 inPort.getProperties( outProperties );
00694 scalarPort->setProperties( outProperties );
00695 outPointer = scalarPort;
00696 }
00697 catch( Error &e )
00698 {
00699 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00700 throw;
00701 }
00702 }
00703
00704 template<>
00705 class Copier<class ScalarPort>
00706 : public ScalarPort::Visitor {
00707 public:
00708 typedef ScalarPort Type;
00709 typedef boost::shared_ptr<Type> Pointer;
00710
00711 Pointer
00712 operator()( const Pointer &inSource,
00713 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00714 mFactory = inFactory;
00715 inSource->accept( *this );
00716 return mReturnVal;
00717 }
00718
00719 void
00720 visit( ScalarPort &inPort ) throw(Error)
00721 {
00722 try
00723 {
00724 copyObject( inPort, mFactory, mReturnVal );
00725 }
00726 catch( Error &e )
00727 {
00728 e.setCurrentLocation(
00729 __FUNCTION__, __FILE__, __LINE__ );
00730 throw;
00731 }
00732 }
00733
00734 Copier()
00735 : Type::Visitor(),
00736 mFactory(),
00737 mReturnVal() {
00738 }
00739
00740 ~Copier() throw() {
00741 }
00742
00743 private:
00744 ObjectFactorySharedPtr mFactory;
00745 Pointer mReturnVal;
00746 };
00747
00748
00749 template<typename _PointerType>
00750 void
00751 copyObject( ScalarPortReference &inPortRef,
00752 ObjectFactorySharedPtr &inFactory,
00753 _PointerType &outPointer ) throw(Error)
00754 {
00755 try
00756 {
00757 ScalarPortReferenceSharedPtr portRefPtr;
00758 inFactory->create( portRefPtr );
00759 portRefPtr->setParent ( inPortRef.getParent() );
00760 portRefPtr->setParentCollection(
00761 inPortRef.getParentCollection() );
00762 portRefPtr->setParent ( inPortRef.getParent() );
00763 portRefPtr->bindToMasterPort( inPortRef.getMaster() );
00764 outPointer = portRefPtr;
00765 }
00766 catch( Error &e )
00767 {
00768 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00769 throw;
00770 }
00771 }
00772
00773 template<>
00774 class Copier<class ScalarPortReference>
00775 : public ScalarPortReference::Visitor {
00776 public:
00777 typedef ScalarPortReference Type;
00778 typedef boost::shared_ptr<Type> Pointer;
00779
00780 Pointer
00781 operator()( const Pointer &inSource,
00782 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00783 mFactory = inFactory;
00784 inSource->accept( *this );
00785 return mReturnVal;
00786 }
00787
00788 void
00789 visit( ScalarPortReference &inPort ) throw(Error)
00790 {
00791 try
00792 {
00793 copyObject( inPort, mFactory, mReturnVal );
00794 }
00795 catch( Error &e )
00796 {
00797 e.setCurrentLocation(
00798 __FUNCTION__, __FILE__, __LINE__ );
00799 throw;
00800 }
00801 }
00802
00803 Copier()
00804 : Type::Visitor(),
00805 mFactory(),
00806 mReturnVal() {
00807 }
00808
00809 ~Copier() throw() {
00810 }
00811
00812 private:
00813 ObjectFactorySharedPtr mFactory;
00814 Pointer mReturnVal;
00815 };
00816
00817
00818 template<typename _PointerType>
00819 void
00820 copyObject( VectorPort &inPort,
00821 ObjectFactorySharedPtr &inFactory,
00822 _PointerType &outPointer ) throw(Error)
00823 {
00824 try
00825 {
00826 VectorPortSharedPtr vectorPortPtr;
00827 inFactory->create( vectorPortPtr );
00828 vectorPortPtr->setComments ( inPort.getComments() );
00829 vectorPortPtr->setName( inPort.getName() );
00830 vectorPortPtr->setDirection( inPort.getDirection() );
00831 vectorPortPtr->setOriginalName( inPort.getOriginalName() );
00832 vectorPortPtr->setAttributes( inPort.getAttributes() );
00833 vectorPortPtr->setIsExtern ( inPort.getIsExtern() );
00834 vectorPortPtr->setParent ( inPort.getParent() );
00835 vectorPortPtr->setParentCollection(inPort.getParentCollection());
00836
00837 std::list< std::string > userData;
00838 inPort.getUserData( userData );
00839 vectorPortPtr->setUserData ( userData );
00840
00841 std::map< std::string, PropertySharedPtr > outProperties;
00842 inPort.getProperties( outProperties );
00843 vectorPortPtr->setProperties( outProperties );
00844
00845
00846 std::vector< size_t > outLimits;
00847 inPort.getLimits( outLimits );
00848 vectorPortPtr->constructChildren( inFactory, outLimits );
00849 VectorPort::BaseType::List children;
00850 inPort.getCreatedChildren( children );
00851 for( VectorPort::BaseType::List::iterator it = children.begin();
00852 it != children.end(); ++it )
00853 {
00854 PortSharedPtr child = *it;
00855 PortSharedPtr clonedChild
00856 = vectorPortPtr->get(
00857 IndexFinder<Port, VectorPortBit>()( child ) );
00858 clonedChild->setComments( child->getComments() );
00859 clonedChild->setName( child->getName() );
00860 clonedChild->setDirection( child->getDirection() );
00861 clonedChild->setOriginalName( child->getOriginalName() );
00862 clonedChild->setAttributes( child->getAttributes() );
00863 clonedChild->setIsExtern ( child->getIsExtern() );
00864 clonedChild->setParent ( child->getParent() );
00865
00866 std::map< std::string, PropertySharedPtr > outProperties;
00867 child->getProperties( outProperties );
00868 clonedChild->setProperties( outProperties );
00869 }
00870
00871 outPointer = vectorPortPtr;
00872 }
00873 catch( Error &e )
00874 {
00875 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00876 throw;
00877 }
00878 }
00879
00880 template<>
00881 class Copier<class VectorPort>
00882 : public VectorPort::Visitor {
00883 public:
00884 typedef VectorPort Type;
00885 typedef boost::shared_ptr<Type> Pointer;
00886
00887 Pointer
00888 operator()( const Pointer &inSource,
00889 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00890 mFactory = inFactory;
00891 inSource->accept( *this );
00892 return mReturnVal;
00893 }
00894
00895 void
00896 visit( VectorPort &inPort ) throw(Error)
00897 {
00898 try
00899 {
00900 copyObject( inPort, mFactory, mReturnVal );
00901 }
00902 catch( Error &e )
00903 {
00904 e.setCurrentLocation(
00905 __FUNCTION__, __FILE__, __LINE__ );
00906 throw;
00907 }
00908 }
00909
00910 Copier()
00911 : Type::Visitor(),
00912 mFactory(),
00913 mReturnVal() {
00914 }
00915
00916 ~Copier() throw() {
00917 }
00918
00919 private:
00920 ObjectFactorySharedPtr mFactory;
00921 Pointer mReturnVal;
00922 };
00923
00924
00925 template<typename _PointerType>
00926 void
00927 copyObject( VectorPortReference &inPortRef,
00928 ObjectFactorySharedPtr &inFactory,
00929 _PointerType &outPointer ) throw(Error)
00930 {
00931 try
00932 {
00933 VectorPortReferenceSharedPtr vectorPortRefPtr;
00934 inFactory->create( vectorPortRefPtr );
00935
00936 std::vector< size_t > outLimits;
00937 inPortRef.getLimits( outLimits );
00938 vectorPortRefPtr->constructChildren( inFactory, outLimits );
00939 vectorPortRefPtr->setParent ( inPortRef.getParent() );
00940 vectorPortRefPtr->setParentCollection(
00941 inPortRef.getParentCollection() );
00942 vectorPortRefPtr->bindToMasterPort( inPortRef.getMaster() );
00943 VectorPortReference::BaseType::List children;
00944 inPortRef.getCreatedChildren( children );
00945 for( VectorPortReference::BaseType::List::iterator it = children.begin();
00946 it != children.end(); ++it )
00947 {
00948 PortReferenceSharedPtr child = *it;
00949 PortReferenceSharedPtr clonedChild
00950 = vectorPortRefPtr->get(
00951 IndexFinder<PortReference,
00952 VectorPortBitReference>()( child ) );
00953 clonedChild->setParent ( child->getParent() );
00954
00955 }
00956
00957 outPointer = vectorPortRefPtr;
00958 }
00959 catch( Error &e )
00960 {
00961 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00962 throw;
00963 }
00964 }
00965
00966 template<>
00967 class Copier<class VectorPortReference>
00968 : public VectorPortReference::Visitor {
00969 public:
00970 typedef VectorPortReference Type;
00971 typedef boost::shared_ptr<Type> Pointer;
00972
00973 Pointer
00974 operator()( const Pointer &inSource,
00975 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
00976 mFactory = inFactory;
00977 inSource->accept( *this );
00978 return mReturnVal;
00979 }
00980
00981 void
00982 visit( VectorPortReference &inPort ) throw(Error)
00983 {
00984 try
00985 {
00986 copyObject( inPort, mFactory, mReturnVal );
00987 }
00988 catch( Error &e )
00989 {
00990 e.setCurrentLocation(
00991 __FUNCTION__, __FILE__, __LINE__ );
00992 throw;
00993 }
00994 }
00995
00996 Copier()
00997 : Type::Visitor(),
00998 mFactory(),
00999 mReturnVal() {
01000 }
01001
01002 ~Copier() throw() {
01003 }
01004
01005 private:
01006 ObjectFactorySharedPtr mFactory;
01007 Pointer mReturnVal;
01008 };
01009
01010
01011 template<typename _PointerType>
01012 void
01013 copyObject( PortBundle &inPort,
01014 ObjectFactorySharedPtr &inFactory,
01015 _PointerType &outPointer ) throw(Error)
01016 {
01017 try
01018 {
01019 PortBundleSharedPtr portBundlePtr;
01020 inFactory->create( portBundlePtr );
01021 portBundlePtr->setComments ( inPort.getComments() );
01022 portBundlePtr->setName( inPort.getName() );
01023 portBundlePtr->setIsExtern( inPort.getIsExtern() );
01024 portBundlePtr->setParent ( inPort.getParent() );
01025 portBundlePtr->setParentCollection( inPort.getParentCollection() );
01026
01027 std::list< std::string > userData;
01028 inPort.getUserData( userData );
01029 portBundlePtr->setUserData ( userData );
01030
01031 std::map< std::string, PropertySharedPtr > outProperties;
01032 inPort.getProperties( outProperties );
01033 portBundlePtr->setProperties( outProperties );
01034
01035 portBundlePtr->setDirection( inPort.getDirection() );
01036 portBundlePtr->setAttributes( inPort.getAttributes() );
01037 portBundlePtr->setOriginalName( inPort.getOriginalName() );
01038 std::vector<PortSharedPtr> children;
01039 inPort.getChildren( children );
01040 for( std::vector<PortSharedPtr>::iterator it = children.begin();
01041 it != children.end(); ++it )
01042 {
01043 PortSharedPtr clonedPort = clone( *it, inFactory );
01044 portBundlePtr->addChild( clonedPort );
01045 }
01046
01047 outPointer = portBundlePtr;
01048 }
01049 catch( Error &e )
01050 {
01051 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01052 throw;
01053 }
01054 }
01055
01056 template<>
01057 class Copier<class PortBundle>
01058 : public PortBundle::Visitor {
01059 public:
01060 typedef PortBundle Type;
01061 typedef boost::shared_ptr<Type> Pointer;
01062
01063 Pointer
01064 operator()( const Pointer &inSource,
01065 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01066 mFactory = inFactory;
01067 inSource->accept( *this );
01068 return mReturnVal;
01069 }
01070
01071 void
01072 visit( PortBundle &inPort ) throw(Error)
01073 {
01074 try
01075 {
01076 copyObject( inPort, mFactory, mReturnVal );
01077 }
01078 catch( Error &e )
01079 {
01080 e.setCurrentLocation(
01081 __FUNCTION__, __FILE__, __LINE__ );
01082 throw;
01083 }
01084 }
01085
01086 Copier()
01087 : Type::Visitor(),
01088 mFactory(),
01089 mReturnVal() {
01090 }
01091
01092 ~Copier() throw() {
01093 }
01094
01095 private:
01096 ObjectFactorySharedPtr mFactory;
01097 Pointer mReturnVal;
01098 };
01099
01100
01101 template<typename _PointerType>
01102 void
01103 copyObject( PortBundleReference &inPortRef,
01104 ObjectFactorySharedPtr &inFactory,
01105 _PointerType &outPointer ) throw(Error)
01106 {
01107 try
01108 {
01109 PortBundleReferenceSharedPtr portBundleRefPtr;
01110 inFactory->create( portBundleRefPtr );
01111 portBundleRefPtr->setParent ( inPortRef.getParent() );
01112 portBundleRefPtr->setParentCollection(
01113 inPortRef.getParentCollection() );
01114 std::vector<PortReferenceSharedPtr> children;
01115 inPortRef.getChildren( children );
01116 for( std::vector<PortReferenceSharedPtr>::iterator it = children.begin();
01117 it != children.end(); ++it )
01118 {
01119 PortReferenceSharedPtr clonedPortRef = clone( *it, inFactory );
01120 portBundleRefPtr->addChild( clonedPortRef );
01121 }
01122 portBundleRefPtr->bindToMasterPort( inPortRef.getMaster() );
01123
01124
01125 outPointer = portBundleRefPtr;
01126 }
01127 catch( Error &e )
01128 {
01129 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01130 throw;
01131 }
01132 }
01133
01134 template<>
01135 class Copier<class PortBundleReference>
01136 : public PortBundleReference::Visitor {
01137 public:
01138 typedef PortBundleReference Type;
01139 typedef boost::shared_ptr<Type> Pointer;
01140
01141 Pointer
01142 operator()( const Pointer &inSource,
01143 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01144 mFactory = inFactory;
01145 inSource->accept( *this );
01146 return mReturnVal;
01147 }
01148
01149 void
01150 visit( PortBundleReference &inPort ) throw(Error)
01151 {
01152 try
01153 {
01154 copyObject( inPort, mFactory, mReturnVal );
01155 }
01156 catch( Error &e )
01157 {
01158 e.setCurrentLocation(
01159 __FUNCTION__, __FILE__, __LINE__ );
01160 throw;
01161 }
01162 }
01163
01164 Copier()
01165 : Type::Visitor(),
01166 mFactory(),
01167 mReturnVal() {
01168 }
01169
01170 ~Copier() throw() {
01171 }
01172
01173 private:
01174 ObjectFactorySharedPtr mFactory;
01175 Pointer mReturnVal;
01176 };
01177
01178
01179 template<typename _PointerType>
01180 void
01181 copyObject( SingleInstance &inInstance,
01182 ObjectFactorySharedPtr &inFactory,
01183 _PointerType &outPointer ) throw(Error)
01184 {
01185 try
01186 {
01187 SingleInstanceSharedPtr instPtr;
01188 inFactory->create( instPtr );
01189 instPtr->setComments( inInstance.getComments() );
01190 instPtr->setName( inInstance.getName() );
01191 instPtr->setOriginalName( inInstance.getOriginalName() );
01192 instPtr->setParent ( inInstance.getParent() );
01193
01194 std::vector< PortReferenceSharedPtr > outPortRefs;
01195 inInstance.getPortReferences( outPortRefs );
01196 for( std::vector< PortReferenceSharedPtr >::iterator it
01197 = outPortRefs.begin(); it != outPortRefs.end(); ++it )
01198 {
01199 PortReferenceSharedPtr clonedRef = clone( *it, inFactory );
01200 instPtr->addPortReference( clonedRef );
01201 }
01202 instPtr->bindToMasterView( inInstance.getMaster() );
01203
01204 copyParams( inInstance, instPtr, inFactory );
01205
01206 std::list< std::string > userData;
01207 inInstance.getUserData( userData );
01208 instPtr->setUserData ( userData );
01209
01210 std::map< std::string, PropertySharedPtr > outProperties;
01211 inInstance.getProperties( outProperties );
01212 instPtr->setProperties( outProperties );
01213
01214 outPointer = instPtr;
01215 }
01216 catch( Error &e )
01217 {
01218 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01219 throw;
01220 }
01221 }
01222
01223 template<>
01224 class Copier<class SingleInstance>
01225 : public SingleInstance::Visitor {
01226 public:
01227 typedef SingleInstance Type;
01228 typedef boost::shared_ptr<Type> Pointer;
01229
01230 Pointer
01231 operator()( const Pointer &inSource,
01232 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01233 mFactory = inFactory;
01234 inSource->accept( *this );
01235 return mReturnVal;
01236 }
01237
01238 void
01239 visit( SingleInstance &inPort ) throw(Error)
01240 {
01241 try
01242 {
01243 copyObject( inPort, mFactory, mReturnVal );
01244 }
01245 catch( Error &e )
01246 {
01247 e.setCurrentLocation(
01248 __FUNCTION__, __FILE__, __LINE__ );
01249 throw;
01250 }
01251 }
01252
01253 Copier()
01254 : Type::Visitor(),
01255 mFactory(),
01256 mReturnVal() {
01257 }
01258
01259 ~Copier() throw() {
01260 }
01261
01262 private:
01263 ObjectFactorySharedPtr mFactory;
01264 Pointer mReturnVal;
01265 };
01266
01267
01268 template<typename _PointerType>
01269 void
01270 copyObject( ScalarNet &inNet,
01271 ObjectFactorySharedPtr &inFactory,
01272 _PointerType &outPointer ) throw(Error)
01273 {
01274 try
01275 {
01276 ScalarNetSharedPtr netPtr;
01277 inFactory->create( netPtr );
01278 netPtr->setComments ( inNet.getComments() );
01279 netPtr->setName( inNet.getName() );
01280 netPtr->setParent ( inNet.getParent() );
01281 netPtr->setOriginalName( inNet.getOriginalName() );
01282
01283 std::list< std::string > userData;
01284 inNet.getUserData( userData );
01285 netPtr->setUserData ( userData );
01286
01287 std::map< std::string, PropertySharedPtr > outProperties;
01288 inNet.getProperties( outProperties );
01289 netPtr->setProperties( outProperties );
01290
01291 std::vector< NetSharedPtr > outNets;
01292 inNet.getSubnets( outNets );
01293 std::vector< NetSharedPtr >::iterator netIt = outNets.begin();
01294 for(; netIt != outNets.end(); ++netIt )
01295 {
01296 NetSharedPtr childNet = clone( *netIt, inFactory );
01297 netPtr->addSubnet( childNet );
01298 }
01299
01300 outPointer = netPtr;
01301 }
01302 catch( Error &e )
01303 {
01304 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01305 throw;
01306 }
01307 }
01308
01309 template<>
01310 class Copier<class ScalarNet>
01311 : public ScalarNet::Visitor {
01312 public:
01313 typedef ScalarNet Type;
01314 typedef boost::shared_ptr<Type> Pointer;
01315
01316 Pointer
01317 operator()( const Pointer &inSource,
01318 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01319 mFactory = inFactory;
01320 inSource->accept( *this );
01321 return mReturnVal;
01322 }
01323
01324 void
01325 visit( ScalarNet &inPort ) throw(Error)
01326 {
01327 try
01328 {
01329 copyObject( inPort, mFactory, mReturnVal );
01330 }
01331 catch( Error &e )
01332 {
01333 e.setCurrentLocation(
01334 __FUNCTION__, __FILE__, __LINE__ );
01335 throw;
01336 }
01337 }
01338
01339 Copier()
01340 : Type::Visitor(),
01341 mFactory(),
01342 mReturnVal() {
01343 }
01344
01345 ~Copier() throw() {
01346 }
01347
01348 private:
01349 ObjectFactorySharedPtr mFactory;
01350 Pointer mReturnVal;
01351 };
01352
01353
01354
01355 template<typename _PointerType>
01356 void
01357 copyObject( NetBundle &inNet,
01358 ObjectFactorySharedPtr &inFactory,
01359 _PointerType &outPointer ) throw(Error)
01360 {
01361 try
01362 {
01363 NetBundleSharedPtr netBundlePtr;
01364 inFactory->create( netBundlePtr );
01365 netBundlePtr->setComments ( inNet.getComments() );
01366 netBundlePtr->setName( inNet.getName() );
01367 netBundlePtr->setParent ( inNet.getParent() );
01368 netBundlePtr->setOriginalName( inNet.getOriginalName() );
01369
01370 std::list< std::string > userData;
01371 inNet.getUserData( userData );
01372 netBundlePtr->setUserData ( userData );
01373
01374 std::map< std::string, PropertySharedPtr > outProperties;
01375 inNet.getProperties( outProperties );
01376 netBundlePtr->setProperties( outProperties );
01377
01378 std::vector<NetSharedPtr> outChildren;
01379 inNet.getChildren( outChildren );
01380 std::vector<NetSharedPtr>::iterator it = outChildren.begin();
01381 for(; it != outChildren.end(); ++it )
01382 {
01383 NetSharedPtr clonedChild = clone( *it, inFactory );
01384 netBundlePtr->addChild( clonedChild );
01385 }
01386 std::vector< NetSharedPtr > outNets;
01387 inNet.getSubnets( outNets );
01388 std::vector< NetSharedPtr >::iterator netIt = outNets.begin();
01389 for(; netIt != outNets.end(); ++netIt )
01390 {
01391 NetSharedPtr childNet = clone( *netIt, inFactory );
01392 netBundlePtr->addSubnet( childNet );
01393 }
01394 outPointer = netBundlePtr;
01395 }
01396 catch( Error &e )
01397 {
01398 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01399 throw;
01400 }
01401 }
01402
01403 template<>
01404 class Copier<class NetBundle>
01405 : public NetBundle::Visitor {
01406 public:
01407 typedef NetBundle Type;
01408 typedef boost::shared_ptr<Type> Pointer;
01409
01410 Pointer
01411 operator()( const Pointer &inSource,
01412 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01413 mFactory = inFactory;
01414 inSource->accept( *this );
01415 return mReturnVal;
01416 }
01417
01418 void
01419 visit( NetBundle &inPort ) throw(Error)
01420 {
01421 try
01422 {
01423 copyObject( inPort, mFactory, mReturnVal );
01424 }
01425 catch( Error &e )
01426 {
01427 e.setCurrentLocation(
01428 __FUNCTION__, __FILE__, __LINE__ );
01429 throw;
01430 }
01431 }
01432
01433 Copier()
01434 : Type::Visitor(),
01435 mFactory(),
01436 mReturnVal() {
01437 }
01438
01439 ~Copier() throw() {
01440 }
01441
01442 private:
01443 ObjectFactorySharedPtr mFactory;
01444 Pointer mReturnVal;
01445 };
01446
01447
01448 template<typename _PointerType>
01449 void
01450 copyObject( VectorNet &inNet,
01451 ObjectFactorySharedPtr &inFactory,
01452 _PointerType &outPointer ) throw(Error)
01453 {
01454 try
01455 {
01456 VectorNetSharedPtr vectorNetPtr;
01457 inFactory->create( vectorNetPtr );
01458 vectorNetPtr->setComments ( inNet.getComments() );
01459 vectorNetPtr->setName( inNet.getName() );
01460 vectorNetPtr->setParent ( inNet.getParent() );
01461 vectorNetPtr->setOriginalName( inNet.getOriginalName() );
01462
01463 std::list< std::string > userData;
01464 inNet.getUserData( userData );
01465 vectorNetPtr->setUserData ( userData );
01466
01467 std::map< std::string, PropertySharedPtr > outProperties;
01468 inNet.getProperties( outProperties );
01469 vectorNetPtr->setProperties( outProperties );
01470
01471 std::vector< size_t > outLimits;
01472 inNet.getLimits( outLimits );
01473 vectorNetPtr->constructChildren( inFactory, outLimits );
01474 VectorNet::BaseType::List children;
01475 inNet.getCreatedChildren( children );
01476 for( VectorNet::BaseType::List::iterator it = children.begin();
01477 it != children.end(); ++it )
01478 {
01479 NetSharedPtr child = *it;
01480 NetSharedPtr clonedChild
01481 = vectorNetPtr->get(
01482 IndexFinder<Net, VectorNetBit>()( child ) );
01483 clonedChild->setComments ( child->getComments() );
01484 clonedChild->setName( child->getName() );
01485 clonedChild->setParent ( child->getParent() );
01486 clonedChild->setOriginalName( child->getOriginalName() );
01487
01488 std::map< std::string, PropertySharedPtr > outProperties;
01489 child->getProperties( outProperties );
01490 clonedChild->setProperties( outProperties );
01491 std::vector< NetSharedPtr > outNets;
01492 child->getSubnets( outNets );
01493 std::vector< NetSharedPtr >::iterator netIt
01494 = outNets.begin();
01495 for(; netIt != outNets.end(); ++netIt )
01496 {
01497 NetSharedPtr clonedChildNet = clone( *netIt, inFactory );
01498 clonedChild->addSubnet( clonedChildNet );
01499 }
01500 }
01501
01502 std::vector< NetSharedPtr > outNets;
01503 inNet.getSubnets( outNets );
01504 std::vector< NetSharedPtr >::iterator netIt = outNets.begin();
01505 for(; netIt != outNets.end(); ++netIt )
01506 {
01507 NetSharedPtr childNet = clone( *netIt, inFactory );
01508 vectorNetPtr->addSubnet( childNet );
01509 }
01510
01511 outPointer = vectorNetPtr;
01512 }
01513 catch( Error &e )
01514 {
01515 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01516 throw;
01517 }
01518 }
01519
01520 template<>
01521 class Copier<class VectorNet>
01522 : public VectorNet::Visitor {
01523 public:
01524 typedef VectorNet Type;
01525 typedef boost::shared_ptr<Type> Pointer;
01526
01527 Pointer
01528 operator()( const Pointer &inSource,
01529 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01530 mFactory = inFactory;
01531 inSource->accept( *this );
01532 return mReturnVal;
01533 }
01534
01535 void
01536 visit( VectorNet &inPort ) throw(Error)
01537 {
01538 try
01539 {
01540 copyObject( inPort, mFactory, mReturnVal );
01541 }
01542 catch( Error &e )
01543 {
01544 e.setCurrentLocation(
01545 __FUNCTION__, __FILE__, __LINE__ );
01546 throw;
01547 }
01548 }
01549
01550 Copier()
01551 : Type::Visitor(),
01552 mFactory(),
01553 mReturnVal() {
01554 }
01555
01556 ~Copier() throw() {
01557 }
01558
01559 private:
01560 ObjectFactorySharedPtr mFactory;
01561 Pointer mReturnVal;
01562 };
01563
01564
01565 template<typename _PointerType>
01566 void
01567 copyObject( InstanceArray &inInstanceArray,
01568 ObjectFactorySharedPtr &inFactory,
01569 _PointerType &outPointer ) throw(Error)
01570 {
01571 try
01572 {
01573 InstanceArraySharedPtr instArrayPtr;
01574 inFactory->create( instArrayPtr );
01575 instArrayPtr->setComments( inInstanceArray.getComments() );
01576 instArrayPtr->setName( inInstanceArray.getName() );
01577 instArrayPtr->setParent ( inInstanceArray.getParent() );
01578 instArrayPtr->setOriginalName(
01579 inInstanceArray.getOriginalName() );
01580
01581 std::list< std::string > userData;
01582 inInstanceArray.getUserData( userData );
01583 instArrayPtr->setUserData ( userData );
01584
01585 std::map< std::string, PropertySharedPtr > outProperties;
01586 inInstanceArray.getProperties( outProperties );
01587 instArrayPtr->setProperties( outProperties );
01588
01589
01590
01591
01592 instArrayPtr->bindToMasterView( inInstanceArray.getMaster() );
01593 copyParams( inInstanceArray, instArrayPtr, inFactory );
01594
01595
01596 std::vector< size_t > outLimits;
01597 inInstanceArray.getLimits( outLimits );
01598 instArrayPtr->constructChildren( inFactory, outLimits );
01599 InstanceArray::BaseVectorType::List children;
01600 inInstanceArray.getChildren( children );
01601 for( InstanceArray::BaseVectorType::List::iterator it
01602 = children.begin(); it != children.end(); ++it )
01603 {
01604 InstanceSharedPtr orig = *it;
01605 InstanceSharedPtr cloned
01606 = instArrayPtr->get(
01607 IndexFinder<Instance,
01608 InstanceArrayMember>()( orig ) );
01609 cloned->setComments( orig->getComments() );
01610 cloned->setName( orig->getName() );
01611 cloned->setOriginalName( orig->getOriginalName() );
01612 cloned->setParent ( orig->getParent() );
01613
01614 std::list< std::string > userData;
01615 orig->getUserData( userData );
01616 cloned->setUserData ( userData );
01617
01618 std::map< std::string, PropertySharedPtr > outProperties;
01619 orig->getProperties( outProperties );
01620 cloned->setProperties( outProperties );
01621
01622 std::vector< PortReferenceSharedPtr > outPortRefs;
01623 orig->getPortReferences( outPortRefs );
01624 for( std::vector< PortReferenceSharedPtr >::iterator pit
01625 = outPortRefs.begin(); pit != outPortRefs.end(); ++pit )
01626 {
01627 PortReferenceSharedPtr clonedRef = clone( *pit, inFactory );
01628 cloned->addPortReference( clonedRef );
01629 }
01630 cloned->bindToMasterView( orig->getMaster() );
01631 copyParams( *orig, cloned, inFactory );
01632 }
01633 outPointer = instArrayPtr;
01634 }
01635 catch( Error &e )
01636 {
01637 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
01638 throw;
01639 }
01640 }
01641
01642 template<>
01643 class Copier<class InstanceArray>
01644 : public InstanceArray::Visitor {
01645 public:
01646 typedef InstanceArray Type;
01647 typedef boost::shared_ptr<Type> Pointer;
01648
01649 Pointer
01650 operator()( const Pointer &inSource,
01651 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01652 mFactory = inFactory;
01653 inSource->accept( *this );
01654 return mReturnVal;
01655 }
01656
01657 void
01658 visit( InstanceArray &inPort ) throw(Error)
01659 {
01660 try
01661 {
01662 copyObject( inPort, mFactory, mReturnVal );
01663 }
01664 catch( Error &e )
01665 {
01666 e.setCurrentLocation(
01667 __FUNCTION__, __FILE__, __LINE__ );
01668 throw;
01669 }
01670 }
01671
01672 Copier()
01673 : Type::Visitor(),
01674 mFactory(),
01675 mReturnVal() {
01676 }
01677
01678 ~Copier() throw() {
01679 }
01680
01681 private:
01682 ObjectFactorySharedPtr mFactory;
01683 Pointer mReturnVal;
01684 };
01685
01686
01687 template<typename _PointerType>
01688 void
01689 copyObject(SingleParameter &inSingleParameter,
01690 ObjectFactorySharedPtr &inFactory,
01691 _PointerType &outPointer ) throw(Error)
01692 {
01693 try
01694 {
01695 SingleParameterSharedPtr singleParameterPtr;
01696 inFactory->create( singleParameterPtr );
01697 singleParameterPtr->setName( inSingleParameter.getName() );
01698 singleParameterPtr->setUnit( inSingleParameter.getUnit() );
01699 singleParameterPtr->setValue( inSingleParameter.getValue() );
01700 singleParameterPtr->setOriginalName( inSingleParameter.getOriginalName() );
01701 outPointer = singleParameterPtr;
01702 }
01703 catch( Error &e )
01704 {
01705 e.setCurrentLocation(
01706 __FUNCTION__, __FILE__, __LINE__ );
01707 throw;
01708 }
01709 }
01710
01711 template<>
01712 class Copier<class SingleParameter>
01713 : public SingleParameter::Visitor {
01714 public:
01715 typedef SingleParameter Type;
01716 typedef boost::shared_ptr<Type> Pointer;
01717
01718 Pointer
01719 operator()( const Pointer &inSource,
01720 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01721 mFactory = inFactory;
01722 inSource->accept( *this );
01723 return mReturnVal;
01724 }
01725
01726 void
01727 visit( SingleParameter &inPort ) throw(Error)
01728 {
01729 try
01730 {
01731 copyObject( inPort, mFactory, mReturnVal );
01732 }
01733 catch( Error &e )
01734 {
01735 e.setCurrentLocation(
01736 __FUNCTION__, __FILE__, __LINE__ );
01737 throw;
01738 }
01739 }
01740
01741 Copier()
01742 : Type::Visitor(),
01743 mFactory(),
01744 mReturnVal() {
01745 }
01746
01747 ~Copier() throw() {
01748 }
01749
01750 private:
01751 ObjectFactorySharedPtr mFactory;
01752 Pointer mReturnVal;
01753 };
01754
01755
01756
01757 template<typename _PointerType>
01758 void
01759 copyObject(ParameterArray &inParamArray,
01760 ObjectFactorySharedPtr &inFactory,
01761 _PointerType &outPointer ) throw(Error)
01762 {
01763 try
01764 {
01765 ParameterArraySharedPtr paramArrayPtr;
01766 inFactory->create( paramArrayPtr );
01767 paramArrayPtr->setName( inParamArray.getName() );
01768 paramArrayPtr->setOriginalName( inParamArray.getOriginalName() );
01769
01770 std::vector< size_t > outLimits;
01771 inParamArray.getLimits( outLimits );
01772 paramArrayPtr->constructChildren( inFactory, outLimits );
01773 ParameterArray::BaseVectorType::List children;
01774 inParamArray.getChildren( children );
01775 ParameterArray::BaseVectorType::List::iterator it
01776 = children.begin();
01777 for(; it != children.end(); ++it )
01778 {
01779 ParameterSharedPtr orig = *it;
01780 ParameterSharedPtr cloned
01781 = paramArrayPtr->get(
01782 IndexFinder<Parameter, ParameterArrayElement>()( orig ) );
01783 cloned->setName( orig->getName() );
01784 cloned->setUnit( orig->getUnit() );
01785 cloned->setValue( orig->getValue() );
01786 }
01787 outPointer = paramArrayPtr;
01788 }
01789 catch( Error &e )
01790 {
01791 e.setCurrentLocation(
01792 __FUNCTION__, __FILE__, __LINE__ );
01793 throw;
01794 }
01795 }
01796
01797 template<>
01798 class Copier<class ParameterArray>
01799 : public ParameterArray::Visitor {
01800 public:
01801 typedef ParameterArray Type;
01802 typedef boost::shared_ptr<Type> Pointer;
01803
01804 Pointer
01805 operator()( const Pointer &inSource,
01806 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01807 mFactory = inFactory;
01808 inSource->accept( *this );
01809 return mReturnVal;
01810 }
01811
01812 void
01813 visit( ParameterArray &inPort ) throw(Error)
01814 {
01815 try
01816 {
01817 copyObject( inPort, mFactory, mReturnVal );
01818 }
01819 catch( Error &e )
01820 {
01821 e.setCurrentLocation(
01822 __FUNCTION__, __FILE__, __LINE__ );
01823 throw;
01824 }
01825 }
01826
01827 Copier()
01828 : Type::Visitor(),
01829 mFactory(),
01830 mReturnVal() {
01831 }
01832
01833 ~Copier() throw() {
01834 }
01835
01836 private:
01837 ObjectFactorySharedPtr mFactory;
01838 Pointer mReturnVal;
01839 };
01840
01841
01842 template<>
01843 class Copier<class Property>
01844 : public Property::Visitor {
01845 public:
01846 typedef Property Type;
01847 typedef boost::shared_ptr<Type> Pointer;
01848
01849 Pointer
01850 operator()( const Pointer &inSource,
01851 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01852 mFactory = inFactory;
01853 inSource->accept( *this );
01854 return mReturnVal;
01855 }
01856
01857 void
01858 visit( Property &inProperty ) throw(Error)
01859 {
01860 try
01861 {
01862 PropertySharedPtr propertyPtr;
01863 mFactory->create( propertyPtr );
01864 propertyPtr->setComments ( inProperty.getComments() );
01865 propertyPtr->setName( inProperty.getName() );
01866 propertyPtr->setOriginalName( inProperty.getOriginalName() );
01867 propertyPtr->setOwner( inProperty.getOwner() );
01868 propertyPtr->setUnit( inProperty.getUnit() );
01869 propertyPtr->setValue( inProperty.getValue() );
01870
01871 std::map< std::string, PropertySharedPtr > outValues;
01872 inProperty.getChildren( outValues );
01873 for( std::map< std::string, PropertySharedPtr >::iterator it
01874 = outValues.begin(); it != outValues.end(); ++it )
01875 {
01876 PropertySharedPtr childProperty
01877 = clone( (*it).second, mFactory );
01878 propertyPtr->addChildProperty( (*it).first, childProperty );
01879 }
01880 mReturnVal = propertyPtr;
01881 }
01882 catch( Error &e )
01883 {
01884 e.setCurrentLocation(
01885 __FUNCTION__, __FILE__, __LINE__ );
01886 throw;
01887 }
01888 }
01889
01890 Copier()
01891 : Type::Visitor(),
01892 mFactory(),
01893 mReturnVal() {
01894 }
01895
01896 ~Copier() throw() {
01897 }
01898
01899 private:
01900 ObjectFactorySharedPtr mFactory;
01901 Pointer mReturnVal;
01902 };
01903
01904 template<>
01905 class Copier<class Port>
01906 : public ScalarPort::Visitor,
01907 public VectorPort::Visitor,
01908 public PortBundle::Visitor {
01909 public:
01910 typedef Port Type;
01911 typedef boost::shared_ptr<Type> Pointer;
01912
01913 Pointer
01914 operator()( const Pointer &inSource,
01915 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01916 mFactory = inFactory;
01917 inSource->accept( *this );
01918 return mReturnVal;
01919 }
01920
01921 void
01922 visit( ScalarPort &inPort ) throw(Error)
01923 {
01924 try
01925 {
01926 copyObject( inPort, mFactory, mReturnVal );
01927 }
01928 catch( Error &e )
01929 {
01930 e.setCurrentLocation(
01931 __FUNCTION__, __FILE__, __LINE__ );
01932 throw;
01933 }
01934 }
01935
01936 void
01937 visit( VectorPort &inPort ) throw(Error)
01938 {
01939 try
01940 {
01941 copyObject( inPort, mFactory, mReturnVal );
01942 }
01943 catch( Error &e )
01944 {
01945 e.setCurrentLocation(
01946 __FUNCTION__, __FILE__, __LINE__ );
01947 throw;
01948 }
01949 }
01950
01951 void
01952 visit( PortBundle &inPort ) throw(Error)
01953 {
01954 try
01955 {
01956 copyObject( inPort, mFactory, mReturnVal );
01957 }
01958 catch( Error &e )
01959 {
01960 e.setCurrentLocation(
01961 __FUNCTION__, __FILE__, __LINE__ );
01962 throw;
01963 }
01964 }
01965
01966 Copier()
01967 : ScalarPort::Visitor(),
01968 VectorPort::Visitor(),
01969 PortBundle::Visitor(),
01970 mFactory(),
01971 mReturnVal() {
01972 }
01973
01974 ~Copier() throw() {
01975 }
01976
01977 private:
01978 ObjectFactorySharedPtr mFactory;
01979 Pointer mReturnVal;
01980 };
01981
01982 template<>
01983 class Copier<class PortReference>
01984 : public ScalarPortReference::Visitor,
01985 public VectorPortReference::Visitor,
01986 public PortBundleReference::Visitor {
01987 public:
01988 typedef PortReference Type;
01989 typedef boost::shared_ptr<Type> Pointer;
01990
01991 Pointer
01992 operator()( const Pointer &inSource,
01993 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
01994 mFactory = inFactory;
01995 inSource->accept( *this );
01996 return mReturnVal;
01997 }
01998
01999 void
02000 visit( ScalarPortReference &inPortReference ) throw(Error)
02001 {
02002 try
02003 {
02004 copyObject( inPortReference, mFactory, mReturnVal );
02005 }
02006 catch( Error &e )
02007 {
02008 e.setCurrentLocation(
02009 __FUNCTION__, __FILE__, __LINE__ );
02010 throw;
02011 }
02012 }
02013
02014 void
02015 visit( VectorPortReference &inPortReference ) throw(Error)
02016 {
02017 try
02018 {
02019 copyObject( inPortReference, mFactory, mReturnVal );
02020 }
02021 catch( Error &e )
02022 {
02023 e.setCurrentLocation(
02024 __FUNCTION__, __FILE__, __LINE__ );
02025 throw;
02026 }
02027 }
02028
02029 void
02030 visit( PortBundleReference &inPortReference ) throw(Error)
02031 {
02032 try
02033 {
02034 copyObject( inPortReference, mFactory, mReturnVal );
02035 }
02036 catch( Error &e )
02037 {
02038 e.setCurrentLocation(
02039 __FUNCTION__, __FILE__, __LINE__ );
02040 throw;
02041 }
02042 }
02043
02044 Copier()
02045 : ScalarPortReference::Visitor(),
02046 VectorPortReference::Visitor(),
02047 PortBundleReference::Visitor(),
02048 mFactory(),
02049 mReturnVal() {
02050 }
02051
02052 ~Copier() throw() {
02053 }
02054
02055 private:
02056 ObjectFactorySharedPtr mFactory;
02057 Pointer mReturnVal;
02058 };
02059
02060 template<>
02061 class Copier<class Net>
02062 : public ScalarNet::Visitor,
02063 public VectorNet::Visitor,
02064 public NetBundle::Visitor {
02065 public:
02066 typedef Net Type;
02067 typedef boost::shared_ptr<Type> Pointer;
02068
02069 Pointer
02070 operator()( const Pointer &inSource,
02071 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
02072 mFactory = inFactory;
02073 inSource->accept( *this );
02074 return mReturnVal;
02075 }
02076
02077 void
02078 visit( ScalarNet &inNet ) throw(Error)
02079 {
02080 try
02081 {
02082 copyObject( inNet, mFactory, mReturnVal );
02083 }
02084 catch( Error &e )
02085 {
02086 e.setCurrentLocation(
02087 __FUNCTION__, __FILE__, __LINE__ );
02088 throw;
02089 }
02090 }
02091
02092 void
02093 visit( VectorNet &inNet ) throw(Error)
02094 {
02095 try
02096 {
02097 copyObject( inNet, mFactory, mReturnVal );
02098 }
02099 catch( Error &e )
02100 {
02101 e.setCurrentLocation(
02102 __FUNCTION__, __FILE__, __LINE__ );
02103 throw;
02104 }
02105 }
02106
02107 void
02108 visit( NetBundle &inNet ) throw(Error)
02109 {
02110 try
02111 {
02112 copyObject( inNet, mFactory, mReturnVal );
02113 }
02114 catch( Error &e )
02115 {
02116 e.setCurrentLocation(
02117 __FUNCTION__, __FILE__, __LINE__ );
02118 throw;
02119 }
02120 }
02121
02122 Copier()
02123 : ScalarNet::Visitor(),
02124 VectorNet::Visitor(),
02125 NetBundle::Visitor(),
02126 mFactory(),
02127 mReturnVal() {
02128 }
02129
02130 ~Copier() throw() {
02131 }
02132
02133 private:
02134 ObjectFactorySharedPtr mFactory;
02135 Pointer mReturnVal;
02136 };
02137
02138 template<>
02139 class Copier<class Instance>
02140 : public SingleInstance::Visitor,
02141 public InstanceArray::Visitor {
02142 public:
02143 typedef Instance Type;
02144 typedef boost::shared_ptr<Type> Pointer;
02145
02146 Pointer
02147 operator()( const Pointer &inSource,
02148 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
02149 mFactory = inFactory;
02150 inSource->accept( *this );
02151 return mReturnVal;
02152 }
02153
02154 void
02155 visit( SingleInstance &inInstance ) throw(Error)
02156 {
02157 try
02158 {
02159 copyObject( inInstance, mFactory, mReturnVal );
02160 }
02161 catch( Error &e )
02162 {
02163 e.setCurrentLocation(
02164 __FUNCTION__, __FILE__, __LINE__ );
02165 throw;
02166 }
02167 }
02168
02169 void
02170 visit( InstanceArray &inInstance ) throw(Error)
02171 {
02172 try
02173 {
02174 copyObject( inInstance, mFactory, mReturnVal );
02175 }
02176 catch( Error &e )
02177 {
02178 e.setCurrentLocation(
02179 __FUNCTION__, __FILE__, __LINE__ );
02180 throw;
02181 }
02182 }
02183
02184 Copier()
02185 : SingleInstance::Visitor(),
02186 InstanceArray::Visitor(),
02187 mFactory(),
02188 mReturnVal() {
02189 }
02190
02191 ~Copier() throw() {
02192 }
02193
02194 private:
02195 ObjectFactorySharedPtr mFactory;
02196 Pointer mReturnVal;
02197 };
02198
02199 template<>
02200 class Copier<class Parameter>
02201 : public SingleParameter::Visitor,
02202 public ParameterArray::Visitor {
02203 public:
02204 typedef Parameter Type;
02205 typedef boost::shared_ptr<Type> Pointer;
02206
02207 Pointer
02208 operator()( const Pointer &inSource,
02209 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
02210 mFactory = inFactory;
02211 inSource->accept( *this );
02212 return mReturnVal;
02213 }
02214
02215 void
02216 visit( SingleParameter &inParameter ) throw(Error)
02217 {
02218 try
02219 {
02220 copyObject( inParameter, mFactory, mReturnVal );
02221 }
02222 catch( Error &e )
02223 {
02224 e.setCurrentLocation(
02225 __FUNCTION__, __FILE__, __LINE__ );
02226 throw;
02227 }
02228 }
02229
02230 void
02231 visit( ParameterArray &inParameter ) throw(Error)
02232 {
02233 try
02234 {
02235 copyObject( inParameter, mFactory, mReturnVal );
02236 }
02237 catch( Error &e )
02238 {
02239 e.setCurrentLocation(
02240 __FUNCTION__, __FILE__, __LINE__ );
02241 throw;
02242 }
02243 }
02244
02245 Copier()
02246 : SingleParameter::Visitor(),
02247 ParameterArray::Visitor(),
02248 mFactory(),
02249 mReturnVal() {
02250 }
02251
02252 ~Copier() throw() {
02253 }
02254
02255 private:
02256 ObjectFactorySharedPtr mFactory;
02257 Pointer mReturnVal;
02258 };
02259
02260 template<>
02261 class Copier<class PortList>
02262 : public PortList::Visitor {
02263 public:
02264 typedef PortList Type;
02265 typedef boost::shared_ptr<Type> Pointer;
02266
02267 Pointer
02268 operator()( const Pointer &inSource,
02269 const ObjectFactorySharedPtr &inFactory ) throw(Error) {
02270 mFactory = inFactory;
02271 inSource->accept( *this );
02272 return mReturnVal;
02273 }
02274
02275 void
02276 visit( PortList &inPort ) throw(Error)
02277 {
02278 try
02279 {
02280 PortListSharedPtr portList;
02281 mFactory->create( portList );
02282 #if 0
02283 std::list< PortList::PortListElement > elements;
02284 portList->getChildren( elements );
02285 for( std::list< PortList::PortListElement >::iterator it
02286 = elements.begin(); it != elements.end();
02287 ++it )
02288 {
02289 switch( (*it).getType() )
02290 {
02291 case PortList::PortListElement::eElementTypePort:
02292 {
02293 portList->addChildPort( (*it).getPort() );
02294 break;
02295 }
02296 case PortList::PortListElement::eElementTypePortReference:
02297 {
02298 portList->addChildPortReference(
02299 (*it).getPortReference() );
02300 break;
02301 }
02302 }
02303 }
02304 #endif
02305 mReturnVal = portList;
02306 }
02307 catch( Error &e )
02308 {
02309 e.setCurrentLocation(
02310 __FUNCTION__, __FILE__, __LINE__ );
02311 throw;
02312 }
02313 }
02314
02315 Copier()
02316 : Type::Visitor(),
02317 mFactory(),
02318 mReturnVal() {
02319 }
02320
02321 ~Copier() throw() {
02322 }
02323
02324 private:
02325 ObjectFactorySharedPtr mFactory;
02326 Pointer mReturnVal;
02327 };
02328
02329 }
02330
02331 }
02332
02333 }
02334 #endif // TORC_GENERIC_OM_CLONING_HPP