00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_INTERNALUTILITYFUNCTIONS_HPP
00017 #define TORC_GENERIC_OM_INTERNALUTILITYFUNCTIONS_HPP
00018
00019 namespace torc {
00020 namespace generic {
00021
00022 template<typename _Connectable>
00023 void
00024 findLeafConnectable( std::vector< std::string > &nestedNames,
00025 boost::shared_ptr<_Connectable> &conn ) throw(Error)
00026 {
00027 std::vector< std::string >::reverse_iterator name
00028 = nestedNames.rbegin();
00029 std::vector< std::string >::reverse_iterator end
00030 = nestedNames.rend();
00031 ++name;
00032 if( !conn )
00033 {
00034 Error e( eMessageIdErrorNullPointer,
00035 __FUNCTION__, __FILE__, __LINE__ );
00036 throw e;
00037 }
00038 for( ;name != end; ++name )
00039 {
00040 if( eCompositionTypeBundle
00041 != conn->getCompositionType() )
00042 {
00043 Error e( eMessageIdErrorUnsupoortedOperation,
00044 __FUNCTION__, __FILE__, __LINE__ );
00045 e.saveContextData("Name", *name );
00046 e.saveContextData("Operation",
00047 std::string( "Find child" ) );
00048 throw e;
00049 }
00050 std::vector< boost::shared_ptr<_Connectable> > children;
00051 conn->getChildren( children );
00052 bool found = false;
00053 for( typename
00054 std::vector< boost::shared_ptr<_Connectable> >::iterator
00055 it = children.begin(); it != children.end(); ++it )
00056 {
00057 if( (*it)->getName() == *name )
00058 {
00059 conn = (*it);
00060 found = true;
00061 break;
00062 }
00063 }
00064 if( !found )
00065 {
00066 Error e( eMessageIdErrorItemNotFound,
00067 __FUNCTION__, __FILE__, __LINE__ );
00068 e.saveContextData("Name", (*name));
00069 throw;
00070 }
00071 }
00072 }
00073
00074 template<typename _Connectable>
00075 void
00076 connectNetToElement( const std::vector<size_t> &inIndices,
00077 const boost::shared_ptr<_Connectable> &inConn,
00078 const NetSharedPtr &inNet ) throw(Error)
00079 {
00080 try
00081 {
00082 if( inIndices.empty() )
00083 {
00084
00085 inConn->connect( inNet );
00086 }
00087 else
00088 {
00089 boost::shared_ptr<_Connectable> bit
00090 = inConn->get( inIndices);
00091 bit->connect( inNet );
00092 }
00093 }
00094 catch( Error &e )
00095 {
00096 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00097 throw;
00098 }
00099 }
00100
00101 template<typename _Base, typename _Derived>
00102 struct IndexFinder
00103 : _Derived::Visitor {
00104 std::vector<size_t>
00105 operator()( const boost::shared_ptr<_Base> &inPtr )
00106 {
00107 inPtr->accept( *this );
00108 return mIndices;
00109 }
00110
00111 void
00112 visit( _Derived &inObj) throw(Error)
00113 {
00114 try
00115 {
00116 mIndices = inObj.getIndices();
00117 }
00118 catch( Error &e )
00119 {
00120 e.setCurrentLocation(
00121 __FUNCTION__, __FILE__, __LINE__ );
00122 throw;
00123 }
00124 }
00125
00126 IndexFinder()
00127 : _Derived::Visitor(),
00128 mIndices() {
00129 }
00130 ~IndexFinder() throw() {
00131 }
00132
00133 std::vector<size_t> mIndices;
00134 };
00135
00136 }
00137 }
00138 #endif // TORC_GENERIC_OM_INTERNALUTILITYFUNCTIONS_HPP