libcommonc++  0.7
LoadableModule Class Reference

An encapsulation of a dynamically loadable module, such as a shared library or object file on UNIX systems or a DLL on Windows. More...

#include <LoadableModule.h++>

Public Member Functions

 LoadableModule (const String &path=String::null)
 Construct a LoadableModule for the loadable object specified by the given path. More...
 
 ~LoadableModule ()
 Destructor. More...
 
void open ()
 Open the loadable object file. More...
 
void close ()
 Close the loadable object file. More...
 
bool isOpen () const
 Determine if the object file has been opened. More...
 
void * lookup (const char *symbol)
 Look up a symbol within the loadable object. More...
 
void * lookup (const String &symbol)
 Look up a symbol within the loadable object. More...
 
void * operator[] (const char *symbol)
 Look up a symbol within the loadable object. More...
 
void * operator[] (const String &symbol)
 Look up a symbol within the loadable object. More...
 
void setPath (const String &path)
 Set the object file path. More...
 
String getPath () const
 Get the object file path. More...
 

Static Public Member Functions

static String getExtension ()
 Get the filename extension for loadable objects (shared libraries) on the host system. More...
 
static String getPrefix ()
 Get the filename prefix for loadable objects (shared libraries) on the host system. More...
 
static String fileNameForStem (const String &stem)
 Construct a complete filename for a loadable module stem based on the conventions of the host system. More...
 
static String fileNameForStem (const String &stem, const Version &version)
 Construct a complete filename for a shared library stem and version based on the conventions of the host system. More...
 
static bool isLoadableModuleFile (const String &fileName)
 Test a filename to determine if it matches the naming convention for shared libraries on the host system. More...
 

Detailed Description

An encapsulation of a dynamically loadable module, such as a shared library or object file on UNIX systems or a DLL on Windows.

Note that on Mac OS X, loadable modules are expected to have an ".so" extension, which is in more common use than the ".bundle" extension recommended by Apple.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ LoadableModule()

LoadableModule ( const String path = String::null)

Construct a LoadableModule for the loadable object specified by the given path.

Parameters
pathThe path to the object file. If the path is empty or null, the module will represent the calling executable itself.

◆ ~LoadableModule()

Destructor.

Closes the object file.

Member Function Documentation

◆ close()

void close ( )

Close the loadable object file.

◆ fileNameForStem() [1/2]

String fileNameForStem ( const String stem)
static

Construct a complete filename for a loadable module stem based on the conventions of the host system.

For example, "foo" produces "foo.dll" on Windows, and "libfoo.so" on Mac OS X and all other (POSIX) systems.

Parameters
stemThe stem.
Returns
The complete filename.

◆ fileNameForStem() [2/2]

String fileNameForStem ( const String stem,
const Version version 
)
static

Construct a complete filename for a shared library stem and version based on the conventions of the host system.

For example, a stem of "foo" and version of "9:0:6" produces "foo-3.dll" on Windows, "libfoo.3.6.0.so" on Mac OS X, and "libfoo.so.3.6.0" on all other (POSIX) systems. (Note that a loadable module on Mac OS X may also have the extension ".bundle", though ".so" is more commonly used.)

Parameters
stemThe stem.
versionThe version.
Returns
The complete filename.

◆ getExtension()

String getExtension ( )
static

Get the filename extension for loadable objects (shared libraries) on the host system.

This returns "dll" on Windows, "so" on Mac OS X, and "so" on all other (POSIX) systems.

◆ getPath()

String getPath ( ) const
inline

Get the object file path.

◆ getPrefix()

String getPrefix ( )
static

Get the filename prefix for loadable objects (shared libraries) on the host system.

This returns "lib" on POSIX systems (including Mac OS X) and an empty string on Windows.

◆ isLoadableModuleFile()

bool isLoadableModuleFile ( const String fileName)
static

Test a filename to determine if it matches the naming convention for shared libraries on the host system.

Parameters
fileNameThe filename to test.

◆ isOpen()

bool isOpen ( ) const
inline

Determine if the object file has been opened.

◆ lookup() [1/2]

void * lookup ( const char *  symbol)

Look up a symbol within the loadable object.

Parameters
symbolThe symbol to look up.
Returns
A pointer to the symbol, or NULL if the symbol was not found, or if the file is not open.

◆ lookup() [2/2]

void * lookup ( const String symbol)

Look up a symbol within the loadable object.

Parameters
symbolThe symbol to look up.
Returns
A pointer to the symbol, or NULL if the symbol was not found, or if the file is not open.

◆ open()

void open ( )

Open the loadable object file.

Exceptions
IOExceptionIf the object could not be loaded, or if no path has been specified.

◆ operator[]() [1/2]

void* operator[] ( const char *  symbol)
inline

Look up a symbol within the loadable object.

Parameters
symbolThe symbol to look up.
Returns
A pointer to the symbol, or NULL if the symbol was not found, or if the file is not open.

◆ operator[]() [2/2]

void* operator[] ( const String symbol)
inline

Look up a symbol within the loadable object.

Parameters
symbolThe symbol to look up.
Returns
A pointer to the symbol, or NULL if the symbol was not found, or if the file is not open.

◆ setPath()

void setPath ( const String path)
inline

Set the object file path.

If the object file is open, the call has no effect.


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