![]() |
Home | Libraries | People | FAQ | More |
boost::dll::experimental::smart_library — This class is an extension of shared_library, which allows to load C++ symbols.
// In header: <boost/dll/smart_library.hpp> class smart_library { public: // types typedef ; // construct/copy/destruct () ; (, = ); (, , = ); (, , ); (smart_library &) ; (smart_library &&) ; (shared_library &) ; (shared_library &&) ; ~(); // public member functions shared_library & () ; () ; (); (, = ); (, , = ); (, , ); template<typename T> () ; template<typename Func> () ; template<typename Class, typename Func> () ; template<typename Signature> () ; template<typename Class> () ; template<typename Class> () ; template<typename Alias> (); () ; () ; () ; () ; () ; () ; smart_library & (smart_library &); (smart_library &) ; };
This class allows type safe loading of overloaded functions, member-functions, constructors and variables. It also allows to overwrite classes so they can be loaded, while being declared with different names.
![]() |
Warning |
---|---|
Is still very experimental. |
Currently known limitations:
Member functions must be defined outside of the class to be exported. That is:
//not exported:
With the current analysis, the first version does get exported in MSVC. MinGW also does export it, BOOST_SYMBOL_EXPORT is written before it. To allow this on windows one can use BOOST_DLL_MEMBER_EXPORT for this, so that MinGW and MSVC can provide those functions. This does however not work with gcc on linux.
Direct initialization of members. On linux the following member variable i will not be initialized when using the allocating constructor:
This does however not happen when the value is set inside the constructor function.
smart_library
public
construct/copy/destruct() ;
Creates in anstance that does not reference any DLL/DSO.
Postconditions: |
this->is_loaded() returns false. |
Throws: |
Nothing. |
( lib_path, mode = );
Loads a library by specified path with a specified mode.
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link>, std::bad_alloc in case of insufficient memory.
Parameters: |
|
||||
Throws: |
( lib_path, ec, mode = );
Loads a library by specified path with a specified mode.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters: |
|
||||||
Throws: |
std::bad_alloc in case of insufficient memory. |
( lib_path, mode, ec);
(smart_library & lib) ;
copy a smart_library
object.
Parameters: |
|
||
Throws: |
Nothing. |
(smart_library && lib) ;
Move a smart_library
object.
Parameters: |
|
||
Throws: |
Nothing. |
(shared_library & lib) ;
Construct from a shared_library
object.
Parameters: |
|
||
Throws: |
Nothing. |
(shared_library && lib) ;
Construct from a shared_library
object.
Parameters: |
|
||
Throws: |
Nothing. |
~();
Destroys the smart_library
. unload()
is called if the DLL/DSO was loaded. If library was loaded multiple times by different instances of shared_library
, the actual DLL/DSO won't be unloaded until there is at least one instance of shared_library
.
Throws: |
Nothing. |
smart_library
public member functionsshared_library & () ;
Get the underlying shared_library
() ;
Access to the mangled storage, which is created on construction.
Throws: |
Nothing. |
();Overload, for current development.
( lib_path, mode = );
Loads a library by specified path with a specified mode.
Note that if some library is already loaded in this instance, load will call unload() and then load the new provided library.
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link>, std::bad_alloc in case of insufficient memory.
Parameters: |
|
||||
Throws: |
( lib_path, ec, mode = );
Loads a library by specified path with a specified mode.
Note that if some library is already loaded in this instance, load will call unload() and then load the new provided library.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters: |
|
||||||
Throws: |
std::bad_alloc in case of insufficient memory. |
( lib_path, mode, ec);
template<typename T> ( name) ;
Load a variable from the referenced library.
Unlinke shared_library::get this function will also load scoped variables, which also includes static class members.
![]() |
Note |
---|---|
When mangled, MSVC will also check the type. |
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link> if symbol does not exist or if the DLL/DSO was not loaded.
Parameters: |
|
||
Template Parameters: |
|
||
Returns: |
A reference to the variable of type T. |
||
Throws: |
template<typename Func> ( name) ;
Load a function from the referenced library.
Example:
![]() |
Note |
---|---|
When mangled, MSVC will also check the return type. |
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link> if symbol does not exist or if the DLL/DSO was not loaded.
Parameters: |
|
||
Template Parameters: |
|
||
Returns: |
A reference to the function of type F. |
||
Throws: |
template<typename Class, typename Func> ( name) ;
Load a member-function from the referenced library.
Example (import class is MyClass, which is available inside the library and the host):
![]() |
Note |
---|---|
When mangled, MSVC will also check the return type. |
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link> if symbol does not exist or if the DLL/DSO was not loaded.
Parameters: |
|
||||
Template Parameters: |
|
||||
Returns: |
A pointer to the member-function with the signature provided |
||||
Throws: |
template<typename Signature> () ;
Load a constructor from the referenced library.
Example (import class is MyClass, which is available inside the library and the host):
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link> if symbol does not exist or if the DLL/DSO was not loaded.
Template Parameters: |
|
||
Returns: |
A constructor object. |
||
Throws: |
template<typename Class> () ;
Load a destructor from the referenced library.
Example (import class is MyClass, which is available inside the library and the host):
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link> if symbol does not exist or if the DLL/DSO was not loaded.
Template Parameters: |
|
||
Returns: |
A destructor object. |
||
Throws: |
template<typename Class> () ;
Load the typeinfo of the given type.
Example (import class is MyClass, which is available inside the library and the host):
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link> if symbol does not exist or if the DLL/DSO was not loaded.
Template Parameters: |
|
||
Returns: |
A reference to a type_info object. |
||
Throws: |
template<typename Alias> ( name);
This function can be used to add a type alias.
This is to be used, when a class shall be imported, which is not declared on the host side.
Example:
![]() |
Note |
---|---|
If the alias-type is not large enough for the imported class, it will result in undefined behaviour. |
![]() |
Warning |
---|---|
The alias will only be applied for the type signature, it will not replace the token in the scoped name. |
Parameters: |
|
() ;
Unloads a shared library. If library was loaded multiple times by different instances, the actual DLL/DSO won't be unloaded until there is at least one instance that references the DLL/DSO.
Postconditions: |
this->is_loaded() returns false. |
Throws: |
Nothing. |
() ;
Check if an library is loaded.
Returns: |
true if a library has been loaded. |
Throws: |
Nothing. |
() ;
Check if an library is not loaded.
Returns: |
true if a library has not been loaded. |
Throws: |
Nothing. |
() ;bool() const
bool() const
( symbol_name) ;
Search for a given symbol on loaded library. Works for all symbols, including alias names.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters: |
|
||
Returns: |
|
||
Throws: |
Nothing. |
( symbol_name) ;
smart_library & (smart_library & lib);
Makes *this share the same shared object as lib. If *this is loaded, then unloads it.
xmlonly <link linkend='boost.dll.fs.system_error'>boost::dll::fs::system_error</link>, std::bad_alloc in case of insufficient memory.
Parameters: |
|
||
Postconditions: |
lib.location() == this->location() |
||
Throws: |
(smart_library & rhs) ;
Swaps two libraries. Does not invalidate existing symbols and functions loaded from libraries.
Parameters: |
|
||
Throws: |
Nothing. |