#include // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: Workspace( ) : m_LastLoadedPlugin( "" ) { } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: ~Workspace( ) { } // ------------------------------------------------------------------------- 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 ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: CreateFilter( const std::string& filter, const std::string& name ) { // Get or create new filter from name auto vIt = this->m_Vertices.find( name ); if( vIt == this->m_Vertices.end( ) ) { TFilter::Pointer o = this->m_Interface.CreateObject( filter ); if( o.IsNotNull( ) ) { o->SetName( name ); this->m_Vertices[ name ] = o; return( true ); } else return( false ); } else return( true ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: Connect( const std::string& orig_filter, const std::string& dest_filter, const std::string& output_name, const std::string& input_name ) { // Get filters auto oIt = this->m_Vertices.find( orig_filter ); if( oIt == this->m_Vertices.end( ) ) return( false ); auto dIt = this->m_Vertices.find( dest_filter ); if( dIt == this->m_Vertices.end( ) ) return( false ); TFilter* orig = dynamic_cast< TFilter* >( oIt->second.GetPointer( ) ); TFilter* dest = dynamic_cast< TFilter* >( dIt->second.GetPointer( ) ); if( orig == NULL || dest == NULL ) return( false ); // Real connection dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) ); this->m_AdjMatrix[ orig_filter ][ dest_filter ].push_back( TConnection( output_name, input_name ) ); return( false ); } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: TParameters* cpPlugins::Interface::Workspace:: GetParameters( const std::string& name ) { auto vIt = this->m_Vertices.find( name ); if( vIt != this->m_Vertices.end( ) ) { TFilter* f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ); if( f != NULL ) return( f->GetParameters( ) ); else return( NULL ); } else return( NULL ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: TParameters* cpPlugins::Interface::Workspace:: GetParameters( const std::string& name ) const { auto vIt = this->m_Vertices.find( name ); if( vIt != this->m_Vertices.end( ) ) { const TFilter* f = dynamic_cast< const TFilter* >( vIt->second.GetPointer( ) ); if( f != NULL ) return( f->GetParameters( ) ); else return( NULL ); } else return( NULL ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: Reduce( const std::string& name ) { } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: Execute( ) { // Find sinks std::set< std::string > sinks; auto vIt = this->m_Vertices.begin( ); for( ; vIt != this->m_Vertices.end( ); ++vIt ) sinks.insert( vIt->first ); auto mIt = this->m_AdjMatrix.begin( ); for( ; mIt != this->m_AdjMatrix.end( ); ++mIt ) sinks.erase( mIt->first ); // Update sinks std::string err = ""; for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt ) { std::string lerr = this->Execute( *sIt ); if( lerr != "" ) err += lerr + std::string( "\n" ); } // rof return( err ); } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: Execute( const std::string& name ) { // Get filter auto vIt = this->m_Vertices.find( name ); if( vIt == this->m_Vertices.end( ) ) return( std::string( "cpPlugins::Interface::Workspace: No filter \"" ) + name + std::string( "\"" ) ); TFilter* f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ); if( f == NULL ) return( std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) + name + std::string( "\" is not a filter." ) ); // Execute and return return( f->Update( ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: _UpdateLoadedPluginsInformation( ) { 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 } // eof - $RCSfile$