DART  6.7.3
dart::common::SharedLibrary Class Reference

SharedLibrary is a RAII object wrapping a shared library. More...

#include <SharedLibrary.hpp>

Public Member Functions

 SharedLibrary (ProtectedConstructionTag, const boost::filesystem::path &path)
 Constructs from a path to the shared library. More...
 
virtual ~SharedLibrary ()
 Destructor. More...
 
const boost::filesystem::path & getCanonicalPath () const
 Returns the path to the shared library file. More...
 
bool isValid () const
 Returns true if the shared library loading was successful. More...
 
void * getSymbol (const std::string &symbolName) const
 Returns a symbol from the shared library if it exists. More...
 

Static Public Member Functions

static std::shared_ptr< SharedLibrarycreate (const boost::filesystem::path &path)
 Creates a SharedLibrary from a path to the shared library. More...
 

Protected Types

enum  ProtectedConstructionTag { ProtectedConstruction }
 

Protected Attributes

boost::filesystem::path mCanonicalPath
 Canonical path to the shared library where a canonical path is an absolute path that has no elements which are symbolic links, and no dot or dot dot elements such as "/path/../to/yourfile". More...
 
DYNLIB_HANDLE mInstance
 Handle to the loaded library. More...
 

Private Member Functions

std::string getLastError () const
 Returns the last loading error. More...
 

Friends

class detail::SharedLibraryManager
 

Detailed Description

SharedLibrary is a RAII object wrapping a shared library.

Member Enumeration Documentation

◆ ProtectedConstructionTag

Enumerator
ProtectedConstruction 

Constructor & Destructor Documentation

◆ SharedLibrary()

dart::common::SharedLibrary::SharedLibrary ( ProtectedConstructionTag  ,
const boost::filesystem::path &  path 
)
explicit

Constructs from a path to the shared library.

This constructor is only called by detail::SharedLibraryManager. ProtectedConstructionTag is necessary to enforce creating SharedLibrary using std::make_shared.

Note
Please use create() to contruct SharedLibrary instead of this constructor.
Parameters
[in]pathThe canonical path to the shared library.
Returns
Pointer to the created SharedLibrary upon success in loading. Otherwise, returns nullptr.

◆ ~SharedLibrary()

dart::common::SharedLibrary::~SharedLibrary ( )
virtual

Destructor.

Member Function Documentation

◆ create()

std::shared_ptr< SharedLibrary > dart::common::SharedLibrary::create ( const boost::filesystem::path &  path)
static

Creates a SharedLibrary from a path to the shared library.

Note
SharedLibrary should be always created from this create function.
Parameters
[in]pathThe path to the shared library. The path can be a relative path or an absolute path. If the path doens't exist this function returns nullptr. If the path exist, the path will be stored as the canonical path where a canonical path is an absolute path that has no elements which are symbolic links, and no dot or dot dot elements such as "/path/../to/yourfile".
Returns
Pointer to the created SharedLibrary upon success in loading. Otherwise, returns nullptr.

◆ getCanonicalPath()

const boost::filesystem::path & dart::common::SharedLibrary::getCanonicalPath ( ) const

Returns the path to the shared library file.

◆ getLastError()

std::string dart::common::SharedLibrary::getLastError ( ) const
private

Returns the last loading error.

◆ getSymbol()

void * dart::common::SharedLibrary::getSymbol ( const std::string &  symbolName) const

Returns a symbol from the shared library if it exists.

Return nullptr otherwise.

You have to reinterpret_cast the return value to the appropriate type to make use of the void* returned by this function.

◆ isValid()

bool dart::common::SharedLibrary::isValid ( ) const

Returns true if the shared library loading was successful.

Friends And Related Function Documentation

◆ detail::SharedLibraryManager

friend class detail::SharedLibraryManager
friend

Member Data Documentation

◆ mCanonicalPath

boost::filesystem::path dart::common::SharedLibrary::mCanonicalPath
protected

Canonical path to the shared library where a canonical path is an absolute path that has no elements which are symbolic links, and no dot or dot dot elements such as "/path/../to/yourfile".

◆ mInstance

DYNLIB_HANDLE dart::common::SharedLibrary::mInstance
protected

Handle to the loaded library.