Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
us::SharedLibrary Class Reference

The SharedLibrary class loads shared libraries at runtime. More...

#include <usSharedLibrary.h>

Public Member Functions

 SharedLibrary ()
 Default constructor. More...
 
 SharedLibrary (const SharedLibrary &other)
 Copy constructor. More...
 
 SharedLibrary (const std::string &libPath, const std::string &name)
 Construct a SharedLibrary object using a library search path and a library base name. More...
 
 SharedLibrary (const std::string &absoluteFilePath)
 Construct a SharedLibrary object using an absolute file path to the shared library. Using this constructor effectively disables all setters except SetFilePath(). More...
 
 ~SharedLibrary ()
 Destroys this object but does not unload the shared library. More...
 
SharedLibrary & operator= (const SharedLibrary &other)
 Assignment operator. More...
 
void Load ()
 Loads the shared library pointed to by this SharedLibrary object. On POSIX systems dlopen() is called with the RTLD_LAZY and RTLD_LOCAL flags unless the compiler is gcc 4.4.x or older. Then the RTLD_LAZY and RTLD_GLOBAL flags are used to load the shared library to work around RTTI problems across shared library boundaries. More...
 
void Load (int flags)
 Loads the shared library pointed to by this SharedLibrary object, using the specified flags on POSIX systems. More...
 
void Unload ()
 Un-loads the shared library pointed to by this SharedLibrary object. More...
 
void SetName (const std::string &name)
 Sets the base name of the shared library. Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used. More...
 
std::string GetName () const
 Gets the base name of the shared library. More...
 
std::string GetFilePath (const std::string &name) const
 Gets the absolute file path for the shared library with base name name, using the search path returned by GetLibraryPath(). More...
 
void SetFilePath (const std::string &absoluteFilePath)
 Sets the absolute file path of this SharedLibrary object. Using this methods with a non-empty absoluteFilePath argument effectively disables all other setters. More...
 
std::string GetFilePath () const
 Gets the absolute file path of this SharedLibrary object. More...
 
void SetLibraryPath (const std::string &path)
 Sets a new library search path. Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used. More...
 
std::string GetLibraryPath () const
 Gets the library search path of this SharedLibrary object. More...
 
void SetSuffix (const std::string &suffix)
 Sets the suffix for shared library names (e.g. .dll or .so). Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used. More...
 
std::string GetSuffix () const
 Gets the file name suffix of this SharedLibrary object. More...
 
void SetPrefix (const std::string &prefix)
 Sets the file name prefix for shared library names (e.g. lib). Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used. More...
 
std::string GetPrefix () const
 Gets the file name prefix of this SharedLibrary object. More...
 
void * GetHandle () const
 Gets the internal handle of this SharedLibrary object. More...
 
bool IsLoaded () const
 Gets the loaded/unloaded stated of this SharedLibrary object. More...
 

Detailed Description

The SharedLibrary class loads shared libraries at runtime.

Definition at line 31 of file usSharedLibrary.h.

Constructor & Destructor Documentation

◆ SharedLibrary() [1/4]

us::SharedLibrary::SharedLibrary ( )

Default constructor.

◆ SharedLibrary() [2/4]

us::SharedLibrary::SharedLibrary ( const SharedLibrary &  other)

Copy constructor.

Parameters
[in]otherThe SharedLibrary to copy.

◆ SharedLibrary() [3/4]

us::SharedLibrary::SharedLibrary ( const std::string &  libPath,
const std::string &  name 
)

Construct a SharedLibrary object using a library search path and a library base name.

Parameters
[in]libPathAn absolute path containing the shared library
[in]nameThe base name of the shared library, without prefix and suffix.

◆ SharedLibrary() [4/4]

us::SharedLibrary::SharedLibrary ( const std::string &  absoluteFilePath)

Construct a SharedLibrary object using an absolute file path to the shared library. Using this constructor effectively disables all setters except SetFilePath().

Parameters
[in]absoluteFilePathThe absolute path to the shared library.

◆ ~SharedLibrary()

us::SharedLibrary::~SharedLibrary ( )

Destroys this object but does not unload the shared library.

Member Function Documentation

◆ GetFilePath() [1/2]

std::string us::SharedLibrary::GetFilePath ( ) const

Gets the absolute file path of this SharedLibrary object.

Returns
The absolute file path of the shared library.

◆ GetFilePath() [2/2]

std::string us::SharedLibrary::GetFilePath ( const std::string &  name) const

Gets the absolute file path for the shared library with base name name, using the search path returned by GetLibraryPath().

Parameters
[in]nameThe shared library base name.
Returns
The absolute file path of the shared library.

◆ GetHandle()

void* us::SharedLibrary::GetHandle ( ) const

Gets the internal handle of this SharedLibrary object.

Returns
nullptr if the shared library is not loaded, the operating system specific handle otherwise.

◆ GetLibraryPath()

std::string us::SharedLibrary::GetLibraryPath ( ) const

Gets the library search path of this SharedLibrary object.

Returns
The library search path.

◆ GetName()

std::string us::SharedLibrary::GetName ( ) const

Gets the base name of the shared library.

Returns
The shared libraries base name.

◆ GetPrefix()

std::string us::SharedLibrary::GetPrefix ( ) const

Gets the file name prefix of this SharedLibrary object.

Returns
The file name prefix of the shared library.

◆ GetSuffix()

std::string us::SharedLibrary::GetSuffix ( ) const

Gets the file name suffix of this SharedLibrary object.

Returns
The file name suffix of the shared library.

◆ IsLoaded()

bool us::SharedLibrary::IsLoaded ( ) const

Gets the loaded/unloaded stated of this SharedLibrary object.

Returns
true if the shared library is loaded, false otherwise.

◆ Load() [1/2]

void us::SharedLibrary::Load ( )

Loads the shared library pointed to by this SharedLibrary object. On POSIX systems dlopen() is called with the RTLD_LAZY and RTLD_LOCAL flags unless the compiler is gcc 4.4.x or older. Then the RTLD_LAZY and RTLD_GLOBAL flags are used to load the shared library to work around RTTI problems across shared library boundaries.

Exceptions
std::logic_errorIf the library is already loaded.
std::runtime_errorIf loading the library failed.

◆ Load() [2/2]

void us::SharedLibrary::Load ( int  flags)

Loads the shared library pointed to by this SharedLibrary object, using the specified flags on POSIX systems.

Parameters
[in]flagsThe POSIX dlopen flags (e.g. RTLD_LAZY, RTLD_GLOBAL).
Exceptions
std::logic_errorIf the library is already loaded.
std::runtime_errorIf loading the library failed.

◆ operator=()

SharedLibrary& us::SharedLibrary::operator= ( const SharedLibrary &  other)

Assignment operator.

Parameters
[in]otherThe SharedLibrary to assign from.
Returns
A reference to this SharedLibrary.

◆ SetFilePath()

void us::SharedLibrary::SetFilePath ( const std::string &  absoluteFilePath)

Sets the absolute file path of this SharedLibrary object. Using this methods with a non-empty absoluteFilePath argument effectively disables all other setters.

Parameters
[in]absoluteFilePathThe new absolute file path of this SharedLibrary object.

◆ SetLibraryPath()

void us::SharedLibrary::SetLibraryPath ( const std::string &  path)

Sets a new library search path. Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.

Parameters
[in]pathThe new shared library search path.

◆ SetName()

void us::SharedLibrary::SetName ( const std::string &  name)

Sets the base name of the shared library. Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.

Parameters
[in]nameThe base name of the shared library, without prefix and suffix.

◆ SetPrefix()

void us::SharedLibrary::SetPrefix ( const std::string &  prefix)

Sets the file name prefix for shared library names (e.g. lib). Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.

Parameters
[in]prefixThe shared library name prefix.

◆ SetSuffix()

void us::SharedLibrary::SetSuffix ( const std::string &  suffix)

Sets the suffix for shared library names (e.g. .dll or .so). Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.

Parameters
[in]suffixThe shared library name suffix.

◆ Unload()

void us::SharedLibrary::Unload ( )

Un-loads the shared library pointed to by this SharedLibrary object.

Exceptions
std::runtime_errorIf an error occurred while un-loading the shared library.

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