All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
te::common::Library Class Reference

A class for handling shared libraries (DLLs, SO, DyLibs). More...

#include <Library.h>

Inheritance diagram for te::common::Library:

Classes

class  Impl
 

Public Member Functions

void * getAddress (const std::string &symbol) const throw (Exception)
 It returns the address where the given symbol is loaded into memory. More...
 
const std::string & getFileName () const throw ()
 It returns the library file name as informed in the constructor. More...
 
bool isLoaded () const throw ()
 It returns true if the shared library is loaded otherwise return false. More...
 
 Library (const std::string &fileName, bool delayLoad=false) throw (Exception)
 Loads a new library specified by the file name. More...
 
void load () throw (Exception)
 It loads the shared library to memory. More...
 
void unload () throw (Exception)
 It forces the unload of the shared library from memory. More...
 
 ~Library ()
 The destructor will automatically unload the library from memory. More...
 

Static Public Member Functions

static void addSearchDir (const std::string &d) throw (Exception)
 It adds the informed dir to the path used by the operational system to lookup for shared libraries. More...
 
static std::string getNativeName (const std::string &name) throw ()
 Given a library name without file extensions, prefixes and nor suffixes it will construct a library name according to the specifc platform. More...
 
static std::string getSearchPath () throw (Exception)
 It returns the system lookup path. More...
 
static void resetSearchPath () throw (Exception)
 It comes back the application lookupo path to the original state, before any addPath has been called. More...
 

Private Attributes

Implm_pImpl
 A pointer to the real implementation. More...
 

Detailed Description

A class for handling shared libraries (DLLs, SO, DyLibs).

Note
If the library you are trying to load has dependencies on other shared libraries then these are automatically loaded by the underlying operational system. The dependencies must be in a folder where the system can search for these dependencies.
This class is based on pimpl idiom.

Definition at line 58 of file Library.h.

Constructor & Destructor Documentation

te::common::Library::Library ( const std::string &  fileName,
bool  delayLoad = false 
)
throw (Exception
)

Loads a new library specified by the file name.

File name may be a relative or absolute path. If just the name of the library is given the class will look for the library in the operational system specific locations.

Parameters
fileNameThe library file name. The file name may contain the full library path.
delayLoadIf true the client object must call explicitly the load method before trying to access any symbol in the library.
Exceptions
ExceptionIt throws an exception if delayLoad is true and the library can not be loaded.

Definition at line 153 of file Library.cpp.

te::common::Library::~Library ( )

The destructor will automatically unload the library from memory.

Definition at line 159 of file Library.cpp.

References m_pImpl.

Member Function Documentation

void te::common::Library::addSearchDir ( const std::string &  d)
throw (Exception
)
static

It adds the informed dir to the path used by the operational system to lookup for shared libraries.

Parameters
dA directory to be added to the lookup of shared libraries.
Exceptions
ExceptionIt throws an exception if the path couldn't be added to the search path.
Note
Not thread-safe.

Definition at line 207 of file Library.cpp.

References te::common::win::GetLastError(), sg_addedSearchPath(), and TE_TR.

void * te::common::Library::getAddress ( const std::string &  symbol) const
throw (Exception
)

It returns the address where the given symbol is loaded into memory.

Parameters
symbolThe name of the symbol inside the library you are searching for. It may be for instance a function name.
Returns
The address where the symbol is loaded.
Exceptions
ExceptionIt throws an exception if it is not possible to locate the given symbol.
Note
Thread-safe.

Definition at line 184 of file Library.cpp.

const std::string & te::common::Library::getFileName ( ) const
throw (
)

It returns the library file name as informed in the constructor.

Returns
The library file name as informed in the constructor.
Note
Thread-safe.

Definition at line 179 of file Library.cpp.

std::string te::common::Library::getNativeName ( const std::string &  name)
throw (
)
static

Given a library name without file extensions, prefixes and nor suffixes it will construct a library name according to the specifc platform.

Returns
The library file name according to the specifc platform.
Note
Thread-safe.

Definition at line 189 of file Library.cpp.

Referenced by te::plugin::CppPluginEngine::getPluginFileName().

std::string te::common::Library::getSearchPath ( )
throw (Exception
)
static

It returns the system lookup path.

Returns
The system lookup path.
Exceptions
ExceptionIt throws an exception if the search path couldn't be reset.
Note
Thread-safe.

Definition at line 267 of file Library.cpp.

References te::common::win::GetLastError(), sg_addedSearchPath(), and TE_TR.

bool te::common::Library::isLoaded ( ) const
throw (
)

It returns true if the shared library is loaded otherwise return false.

Returns
True if the shared library is loaded otherwise returns false.
Note
Thread-safe.

Definition at line 174 of file Library.cpp.

void te::common::Library::load ( )
throw (Exception
)

It loads the shared library to memory.

If the library was already loaded this method doesn't perform operations.

Exceptions
ExceptionIf the library can not be load to memory this method raises an exception.
Note
Not thread-safe.

Definition at line 164 of file Library.cpp.

void te::common::Library::resetSearchPath ( )
throw (Exception
)
static

It comes back the application lookupo path to the original state, before any addPath has been called.

Exceptions
ExceptionIt throws an exception if the search path couldn't be reset.
Note
Not thread-safe.

Definition at line 251 of file Library.cpp.

References te::common::win::GetLastError(), sg_addedSearchPath(), and TE_TR.

void te::common::Library::unload ( )
throw (Exception
)

It forces the unload of the shared library from memory.

If the library wasn't previously loaded or if it was already unloaded this method doesn't perform operations.

Exceptions
ExceptionIf the library can not be unload from memory this method raises an exception.
Note
Not thread-safe.

Definition at line 169 of file Library.cpp.

Member Data Documentation

Impl* te::common::Library::m_pImpl
private

A pointer to the real implementation.

Definition at line 179 of file Library.h.

Referenced by ~Library().


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