EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Public Member Functions | Static Public Member Functions | List of all members
EGS_Library Class Reference

A class for dynamically loading shared libraries. More...

#include <egs_library.h>

Public Member Functions

 EGS_Library (const char *lib_name, const char *path=0)
 Constructs the library object and sets the DSO name to lib_name. More...
 
 ~EGS_Library ()
 Destructs the library object. More...
 
bool load ()
 Loads the library. More...
 
void * resolve (const char *func)
 Returns the address of the exported symbol func. More...
 
bool unload ()
 Unloads the library. More...
 
bool isLoaded () const
 Returns true if the library is loaded, false otherwise.
 
bool autoUnload () const
 Returns true if the library automatically unloads when the object is destructed, false otherwise. More...
 
void setUnload (bool u)
 Set automatic unloading to u.
 
const char * libraryName () const
 Returns the name of the library object as given in the constructor.
 
const char * libraryFile () const
 Returns the name of the DSO, including full path and platform-specific prefix and extension.
 

Static Public Member Functions

static void * resolve (const char *lname, const char *func, const char *path=0)
 Resolve the address of the symbol func from the DSO lname. More...
 

Detailed Description

A class for dynamically loading shared libraries.

This class provides a platform-independent interface to the system specific process of loading dynamic shared objects (DSO), a.k.a. DLLs and resolving the addresses of symbols exported by the library.

Definition at line 52 of file egs_library.h.

Constructor & Destructor Documentation

EGS_Library::EGS_Library ( const char *  lib_name,
const char *  path = 0 
)

Constructs the library object and sets the DSO name to lib_name.

lib_name should not contain platform specific prefixes or extensions, this will be handled by the library object (i.e. lib_name = mylib will result in mylib.dll under Windows and libmylib.so under Unix.) If path is null, the library must be in the standard search path for DSOs. If path contains a valid path specification, the library name will be constracted from path and lib_name.

Definition at line 182 of file egs_library.cpp.

EGS_Library::~EGS_Library ( )

Destructs the library object.

The library will be unloaded unless the auto_unload flag is set to false using setUnload().

Definition at line 186 of file egs_library.cpp.

Member Function Documentation

bool EGS_Library::load ( )

Loads the library.

It is not necessary to call this function before using resolve(). Will return true on success and false otherwise.

Definition at line 190 of file egs_library.cpp.

Referenced by EGS_ObjectFactory::createSingleObject().

void * EGS_Library::resolve ( const char *  func)

Returns the address of the exported symbol func.

Calls the load() function if necessary. Returns the address of the symbol on success or null if the symbol could not be resolved or the library could not be loaded.

Definition at line 194 of file egs_library.cpp.

Referenced by EGS_ObjectFactory::createSingleObject(), and EGS_BeamSource::EGS_BeamSource().

bool EGS_Library::unload ( )

Unloads the library.

Returns true on success, false otherwise. This function is called by the destructor if the library object was set to automatically unload the library with setUnload().

Definition at line 198 of file egs_library.cpp.

bool EGS_Library::autoUnload ( ) const

Returns true if the library automatically unloads when the object is destructed, false otherwise.

See Also
setUnload().

Definition at line 206 of file egs_library.cpp.

void * EGS_Library::resolve ( const char *  lname,
const char *  func,
const char *  path = 0 
)
static

Resolve the address of the symbol func from the DSO lname.

This static function is provided for convenience. It loads the library lname and returns the address of the symbol func on success, null if the library could not be loaded or if it does not export a symbol named func. If path is null, the library will be searched for in the standard set of library search paths, otherwise the library file name will be constructed from path and lname.

See Also
EGS_Library::EGS_Library(), load(), resolve().

Definition at line 222 of file egs_library.cpp.


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