claw::dynamic_library_traits_unix Class Reference

Unix interface for using dynamic libraries. More...

#include <dynamic_library_traits_unix.hpp>

List of all members.

Public Types

typedef void * handle
 Type of the system handle to the library.

Static Public Member Functions

static handle open (const std::string &name)
 Open a library.
static handle auto_open (const std::string &name)
 Open the current program.
static void close (handle h)
 Close a library.
template<class T >
static T get_symbol (handle h, const std::string &name)
 Get a symbol from a library.
static bool have_symbol (handle h, const std::string &name)
 Tell if a symbol is in the library.
static bool valid_handle (handle h)
 Tell if an handle is a valid library handle.

Detailed Description

Unix interface for using dynamic libraries.

Author:
Julien Jorge

Definition at line 43 of file dynamic_library_traits_unix.hpp.


Member Typedef Documentation

Type of the system handle to the library.

Definition at line 47 of file dynamic_library_traits_unix.hpp.


Member Function Documentation

static handle claw::dynamic_library_traits_unix::auto_open ( const std::string &  name  )  [inline, static]

Open the current program.

Parameters:
name (not used) The name of the current program.
Returns:
The handle on the loaded library.

Definition at line 72 of file dynamic_library_traits_unix.hpp.

References valid_handle().

00073     {
00074       handle h = dlopen( NULL, RTLD_LAZY );
00075 
00076       if ( !valid_handle(h) )
00077         throw claw::exception( dlerror() );
00078 
00079       return h;
00080     } // dynamic_library_traits_unix::auto_open()

static void claw::dynamic_library_traits_unix::close ( handle  h  )  [inline, static]

Close a library.

Parameters:
h The handle of the library to close.

Definition at line 87 of file dynamic_library_traits_unix.hpp.

00088     {
00089       dlclose(h);
00090     } // dynamic_library_traits_unix::close()

template<class T >
static T claw::dynamic_library_traits_unix::get_symbol ( handle  h,
const std::string &  name 
) [inline, static]

Get a symbol from a library.

Parameters:
h Handle of the library.
name The name of the symbol to load.

Definition at line 99 of file dynamic_library_traits_unix.hpp.

00100     {
00101       /* HACK : ISO standard doesn't allow to cast from a pointer to an object
00102          to a pointer to a function. */
00103       T result;
00104       *(void**)(&result) = dlsym( h, name.c_str() );
00105 
00106       return result;
00107     } // dynamic_library_traits_unix::get_symbol()

static bool claw::dynamic_library_traits_unix::have_symbol ( handle  h,
const std::string &  name 
) [inline, static]

Tell if a symbol is in the library.

Parameters:
h Handle of the library.
name The name of the symbol to find.

Definition at line 115 of file dynamic_library_traits_unix.hpp.

00116     {
00117       return dlsym( h, name.c_str() ) != NULL;
00118     } // dynamic_library_traits_unix::have_symbol()

static handle claw::dynamic_library_traits_unix::open ( const std::string &  name  )  [inline, static]

Open a library.

Parameters:
name The name of the library to open.
Returns:
The handle on the loaded library.

Definition at line 56 of file dynamic_library_traits_unix.hpp.

References valid_handle().

00057     {
00058       handle h = dlopen( name.c_str(), RTLD_LAZY );
00059 
00060       if ( !valid_handle(h) )
00061         throw claw::exception( dlerror() );
00062 
00063       return h;
00064     } // dynamic_library_traits_unix::open()

static bool claw::dynamic_library_traits_unix::valid_handle ( handle  h  )  [inline, static]

Tell if an handle is a valid library handle.

Parameters:
h The handle to test.

Definition at line 125 of file dynamic_library_traits_unix.hpp.

Referenced by auto_open(), and open().

00126     {
00127       return h != NULL;
00128     } // dynamic_library_traits_unix::valid_handle()


The documentation for this class was generated from the following file:

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1