|
LUNCHBOX_API | DSO () |
| Construct a new dynamic shared object. More...
|
|
LUNCHBOX_API | DSO (const std::string &name) |
| Construct and initialize a dynamic shared object. More...
|
|
LUNCHBOX_API | ~DSO () |
| Destruct this DSO handle. More...
|
|
LUNCHBOX_API bool | open (const std::string &fileName) |
| Open a dynamic shared object. More...
|
|
LUNCHBOX_API void | close () |
| Close the DSO, invalidates retrieved function pointers. More...
|
|
LUNCHBOX_API void * | getFunctionPointer (const std::string &functionName) const |
|
template<class F > |
F | getFunctionPointer (const std::string &func) const |
|
LUNCHBOX_API bool | isOpen () const |
|
LUNCHBOX_API bool | operator== (const DSO &rhs) const |
|
bool | operator!= (const DSO &rhs) const |
|
Helper to access dynamic shared objects (DSO)
Example:
#include "test.h"
#include <lunchbox/dso.h>
#include <boost/filesystem.hpp>
#ifdef __linux__
# include <gnu/lib-names.h>
#endif
#ifdef _WIN32
# include <lunchbox/os.h>
# define fork CreateThread
const std::string forkFun( "CreateThread" );
#else
const std::string forkFun( "fork" );
#endif
namespace fs = boost::filesystem;
int main( int, char** )
{
#ifdef _WIN32
libraries.push_back( "Kernel32.dll" );
libraries.push_back( "Ws2_32.dll" );
#elif defined (Darwin)
libraries.push_back( "/usr/lib/libc.dylib" );
libraries.push_back( "/usr/lib/libtermcap.dylib" );
#else
libraries.push_back( LIBPTHREAD_SO );
libraries.push_back( LIBM_SO );
#endif
TEST( one.isOpen( ));
TEST( two.isOpen( ));
TEST( one != two );
TEST( one != three );
TEST( three.
open( libraries[0] ));
TEST( one == three );
TEST( !three.
open( libraries[0] ));
TEST( one == three );
TEST( one.getFunctionPointer( forkFun ));
TEST( one.getFunctionPointer( forkFun ) == &fork );
TEST( !one.getFunctionPointer( "fooBar" ));
one.close();
TEST( one != two );
TEST( one != three );
TEST( !one.getFunctionPointer( forkFun ));
two.close();
TEST( one == two );
TEST( one != three );
return EXIT_SUCCESS;
}
Definition at line 35 of file dso.h.