void cpExtensions::DataStructures::Graph< V, C, I >::
RemoveVertex( const I& index )
{
-#error REMOVE
+ auto i = this->m_Vertices.find( index );
+ if( i != this->m_Vertices.end( ) )
+ {
+ // Delete vertex
+ this->m_Vertices.erase( i );
+
+ // Delete edges starting from given vertex
+ auto mIt = this->m_Matrix.find( index );
+ if( mIt != this->m_Matrix.end( ) )
+ this->m_Matrix.erase( mIt );
+
+ // Delete edges arriving to given vertex
+ mIt = this->m_Matrix.begin( );
+ for( ; mIt != this->m_Matrix.end( ); ++mIt )
+ {
+ auto rIt = mIt->second.begin( );
+ while( rIt != mIt->second.end( ) )
+ {
+ if( rIt->first == index )
+ {
+ mIt->second.erase( rIt );
+ rIt = mIt->second.begin( );
+ }
+ else
+ ++rIt;
+
+ } // elihw
+
+ } // rof
+ return( true );
+ }
+ else
+ return( false );
}
// -------------------------------------------------------------------------
void cpExtensions::DataStructures::Graph< V, C, I >::
RemoveConnection( const I& orig, const I& dest, const C& cost )
{
-#error remove connection
+ auto m = this->m_Matrix.find( orig );
+ if( m != this->m_Matrix.end( ) )
+ {
+ auto r = m->second.find( dest );
+ if( r != m->second.end( ) )
+ {
+ auto e = std::find( r->second.begin( ), r->second.end( ), cost );
+ if( e != r->second.end( ) )
+ {
+ r->second.erase( e );
+ if( r->second.size( ) == 0 )
+ {
+ m->second.erase( r );
+ if( m->second.size( ) == 0 )
+ this->m_Matrix.erase( m );
+
+ } // fi
+
+ } // fi
+
+ } // fi
+
+ } // fi
}
// -------------------------------------------------------------------------
this->m_Interface = i;
}
-/* TODO
- bool cpPlugins::Interface::Workspace::
- LoadPluginsPath( const std::string& path, bool r )
- {
- // Load all plugins from given folder
- std::list< std::string > files =
- this->m_Interface.LoadFromFolder( path, r );
-
- // Update a simple track
- bool ret = false;
- if( files.size( ) > 0 )
- {
- for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
- {
- this->m_LoadedPlugins.insert( *fIt );
- this->m_LastLoadedPlugin = *fIt;
-
- } // rof
- this->_UpdateLoadedPluginsInformation( );
- ret = true;
-
- } // fi
- return( ret );
- }
-
- // -------------------------------------------------------------------------
- bool cpPlugins::Interface::Workspace::
- LoadPlugins( const std::string& fname )
- {
- // Is it already loaded?
- bool ret = true;
- if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
- {
- // Was it succesfully loaded?
- ret = this->m_Interface.Load( fname );
-
- // Update a simple track
- if( ret )
- {
- this->m_LoadedPlugins.insert( fname );
- this->m_LastLoadedPlugin = fname;
- this->_UpdateLoadedPluginsInformation( );
-
- } // fi
-
- } // fi
- return( ret );
- }
-
- // -------------------------------------------------------------------------
- const cpPlugins::Interface::Workspace::
- TStringContainer& cpPlugins::Interface::Workspace::
- GetLoadedPlugins( ) const
- {
- return( this->m_LoadedPlugins );
- }
-
- // -------------------------------------------------------------------------
- void cpPlugins::Interface::Workspace::
- GetLoadedPluginCategories( TStringContainer& categories ) const
- {
- categories.clear( );
- auto fIt = this->m_LoadedFilters.begin( );
- for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
- categories.insert( fIt->first );
- }
-
- // -------------------------------------------------------------------------
- void cpPlugins::Interface::Workspace::
- GetLoadedPluginFilters( TStringContainer& filters ) const
- {
- filters.clear( );
- auto pIt = this->m_LoadedFilters.begin( );
- for( ; pIt != this->m_LoadedFilters.end( ); ++pIt )
- for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt )
- filters.insert( *fIt );
- }
-
- // -------------------------------------------------------------------------
- const cpPlugins::Interface::Workspace::
- TStringContainer& cpPlugins::Interface::Workspace::
- GetLoadedPluginFilters( const std::string& category ) const
- {
- static const TStringContainer EMPTY;
- auto pIt = this->m_LoadedFilters.find( category );
- if( pIt != this->m_LoadedFilters.end( ) )
- return( pIt->second );
- else
- return( EMPTY );
- }
-*/
-
// -------------------------------------------------------------------------
void cpPlugins::Interface::Workspace::
Clear( )
)
{
// Get filters
- TFilter* orig =
- dynamic_cast< TFilter* >(
- this->m_Graph->GetVertex( orig_filter ).GetPointer( )
- );
- TFilter* dest =
- dynamic_cast< TFilter* >(
- this->m_Graph->GetVertex( dest_filter ).GetPointer( )
- );
+ TFilter* orig = this->GetFilter( orig_filter );
+ TFilter* dest = this->GetFilter( dest_filter );
if( orig == NULL || dest == NULL )
return( false );
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Workspace::
-Connect( const std::string& i, const std::string& o )
+Connect( TData* input_object, const std::string& input_name )
{
- auto ii = this->m_InputPorts.find( i );
- auto oi = this->m_OutputPorts.find( o );
- if( ii != this->m_InputPorts.end( ) && oi != this->m_OutputPorts.end( ) )
- return(
- this->Connect(
- oi->second.first,
- ii->second.first,
- oi->second.second,
- ii->second.second
- )
- );
+ auto port = this->m_InputPorts.find( input_name );
+ if( port != this->m_InputPorts.end( ) )
+ {
+ TFilter* filter = this->GetFilter( port->second.first );
+ if( filter != NULL )
+ {
+ filter->SetInput( port->second.second, input_object );
+ return( true );
+ }
+ else
+ return( false );
+ }
else
return( false );
}
TParameters* cpPlugins::Interface::Workspace::
GetParameters( const std::string& name )
{
- TFilter* f =
- dynamic_cast< TFilter* >(
- this->m_Graph->GetVertex( name ).GetPointer( )
- );
+ TFilter* f = this->GetFilter( name );
if( f != NULL )
return( f->GetParameters( ) );
else
TParameters* cpPlugins::Interface::Workspace::
GetParameters( const std::string& name ) const
{
- const TFilter* f =
- dynamic_cast< const TFilter* >(
- this->m_Graph->GetVertex( name ).GetPointer( )
- );
+ const TFilter* f = this->GetFilter( name );
if( f != NULL )
return( f->GetParameters( ) );
else
this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output );
}
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Workspace::
+TData* cpPlugins::Interface::Workspace::
+GetOutput( const std::string& name )
+{
+ auto port = this->m_OutputPorts.find( name );
+ if( port != this->m_OutputPorts.end( ) )
+ {
+ TFilter* f = this->GetFilter( port->second.first );
+ if( f != NULL )
+ return( f->GetOutput< TData >( port->second.second ) );
+ else
+ return( NULL );
+ }
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TData* cpPlugins::Interface::Workspace::
+GetOutput( const std::string& name ) const
+{
+ auto port = this->m_OutputPorts.find( name );
+ if( port != this->m_OutputPorts.end( ) )
+ {
+ const TFilter* f = this->GetFilter( port->second.first );
+ if( f != NULL )
+ return( f->GetOutput< TData >( port->second.second ) );
+ else
+ return( NULL );
+ }
+ else
+ return( NULL );
+}
+
// -------------------------------------------------------------------------
void cpPlugins::Interface::Workspace::
ClearInputPorts( )
Execute( const std::string& name, QWidget* p )
{
// Get filter
- TFilter* f =
- dynamic_cast< TFilter* >(
- this->m_Graph->GetVertex( name ).GetPointer( )
- );
+ TFilter* f = this->GetFilter( name );
if( f == NULL )
return(
std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
return( f->Update( ) );
}
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Workspace::
-_UpdateLoadedPluginsInformation( )
-{
- /* TODO
- if( this->m_Interface != NULL )
- {
- this->m_LoadedFilters.clear( );
- const TInterface::TClasses& cls = this->m_Interface->GetClasses( );
- for( auto i = cls.begin( ); i != cls.end( ); ++i )
- {
- TFilter::Pointer o = this->m_Interface->CreateObject( i->first );
- std::string name = o->GetClassName( );
- std::string category = o->GetClassCategory( );
- this->m_LoadedFilters[ category ].insert( name );
-
- } // rof
-
- } // fi
- */
-}
-
// eof - $RCSfile$