5 // class DLLManager is the simple ELF C++ Library manager.
7 // It tries to dynamically load the specified shared library
8 // when it is construted.
10 // You should call LastError() before doing anything. If it
11 // returns NULL there is no error.
18 DLLManager( const char *fname );
19 virtual ~DLLManager();
22 bool GetSymbol( void **, const char *sym_name );
24 const char *LastError()
36 // class DLLFactoryBase is the base class used for the DLLFactory
39 // It inherits from the DLLManager class and must be constructed with
40 // the file name of the shared library and the function name within that
41 // library which will create the desired C++ factory class.
42 // If you do not provide func_name to the constructor, it defaults to
43 // the undecorated "C" symbol "factory0"
45 // factory_func will be set to a pointer to the requested factory creator
46 // function. If there was an error linking to the shared library,
47 // factory_func will be 0.
49 // You can call 'LastError()' to find the error message that occurred.
53 class DLLFactoryBase : public DLLManager
56 DLLFactoryBase(const char *fname, const char *func_name = 0);
57 virtual ~DLLFactoryBase();
58 void * (*factory_func)(void);
63 // The DLLFactory template class inherits from DLLFactoryBase.
64 // The constructor takes the file name of the shared library
65 // and the undecorated "C" symbol name of the factory creator
66 // function. The factory creator function in your shared library
67 // MUST either return a pointer to an object that is a subclass
68 // of 'T' or it must return 0.
70 // If everything is cool, then 'factory' will point to the
71 // requested factory class. If not, it will be 0.
73 // Since the DLLFactory template ultimately inherits DLLManager,
74 // you can call LastError() to get any error code information
76 // The created factory is OWNED by the DLLFactory class.
77 // The created factory will get deleted when the DLLFactory class
78 // is deleted, because the DLL will get unloaded as well.
81 template <class T> class DLLFactory : public DLLFactoryBase
84 DLLFactory(const char *fname, const char *func_name=0) : DLLFactoryBase(fname,func_name)
87 factory = (T*)factory_func();