]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface.h
Bug smashed like a boss
[cpPlugins.git] / lib / cpPlugins / Interface.h
1 #ifndef __CPPLUGINS__INTERFACE__H__
2 #define __CPPLUGINS__INTERFACE__H__
3
4 #include <cpPlugins/Config.h>
5 #include <cpPlugins/ProcessObject.h>
6 #include <map>
7 #include <set>
8 #include <string>
9
10 namespace cpPlugins
11 {
12   /**
13    */
14   class cpPlugins_EXPORT Interface
15   {
16   public:
17     typedef Interface Self;
18
19     typedef void* ( *TCreator )( );
20     typedef std::pair< std::string, TCreator >               TDynFunc;
21     typedef std::map< std::string, TDynFunc >                TDynFilter;
22     typedef std::map< std::string, TDynFilter >              TDynFilters;
23     typedef std::map< std::string, std::set< std::string > > TFilters;
24     typedef std::pair< std::string, void* >                  TDynFileInfo;
25     typedef std::map< std::string, TDynFileInfo >            TDynLibraries;
26
27   public:
28     Interface( );
29     virtual ~Interface( );
30
31     const TFilters& GetFilters( );
32
33     void UpdatePaths( );
34     void GuessAccesiblePlugins( );
35     void LoadPlugin( const std::string& name );
36     void LoadPluginDir( const std::string& dirname );
37     void LoadPluginFile( const std::string& filename );
38     void UnloadAll( );
39
40     ProcessObject::Pointer Create(
41       const std::string& category, const std::string& name
42       );
43     std::string GetPluginName(
44       const std::string& category, const std::string& name
45       ) const;
46     std::string GetPluginName( const ProcessObject* obj ) const;
47     std::set< std::string > GetPlugins( ) const;
48
49   protected:
50     template< class _TList >
51       inline void _AddInstancesLib( _TList& libs, const std::string& path );
52     static void* _DLOpen( const std::string& fname, std::string& error );
53     static const char* _DLGetName( void* hnd );
54     static TFilters _DLGetFilters( void* hnd );
55     static TCreator _DLGetCreator(
56       void* hnd, const std::string& category, const std::string& name
57       );
58     static void _DLClose( void* hnd );
59
60   protected:
61     std::vector< std::string > m_Paths;
62     TDynLibraries m_DynLibraries;
63     TDynFilters   m_DynFilters;
64     TFilters      m_Filters;
65
66     static unsigned int InterfacesCount;
67   };
68
69 } // ecapseman
70
71 #endif // __CPPLUGINS__INTERFACE__H__
72
73 // eof - $RCSfile$