cpp-sdl2
C++ header-only SDL2 wrapper
sdl::SharedObject Class Reference

Represent a shared object (dynamic library, dynamically loaded library, module, plugin...). More...

#include <shared_object.hpp>

Public Types

using FunctionAddress = void *
 Alias void* to a descriptive "pointer to function" typename. More...
 

Public Member Functions

 SharedObject (std::string const &objectName)
 Get a shared object ( = Load the named library dynamically) More...
 
 SharedObject ()=default
 Construct an empty shared object handler. You can move assign to it. More...
 
 ~SharedObject ()
 Automatically unload the library for you. More...
 
 SharedObject (SharedObject &&other) noexcept
 Move ctor. More...
 
SharedObjectoperator= (SharedObject &&other) noexcept
 Move shared object into this one. More...
 
 SharedObject (SharedObject const &)=delete
 This class isn't copyable. More...
 
SharedObjectoperator= (SharedObject const &)=delete
 This class isn't copyable. More...
 
FunctionAddress function_pointer (std::string const &functionName) const
 Retrieve the raw address of a function inside the owned object. User has to cast this to the correct function pointer type. More...
 
template<typename FunctionPointerSignature >
FunctionPointerSignature function_pointer (std::string const &functionName) const
 Syntactic sugar overload, provide you a way to specify the actual type of the function pointer e.g: mySharedObject.function_pointer<returnType (*) (args)>("nameOfExportedFunction");. More...
 

Private Types

using SharedObjectHandle = void *
 Types should be at least named. Alias void* to "SharedObjectHandle*. More...
 

Private Attributes

SharedObjectHandle handle_ = nullptr
 This class wrap an handle to a shared object. More...
 

Detailed Description

Represent a shared object (dynamic library, dynamically loaded library, module, plugin...).

This class wraps a platform-specific "handle" to a loaded library. An instanciated SharedObject permit to retrieve callable function from them in a cross-platform way. This class automatically manages the lifetime of the loaded library for you

Definition at line 16 of file shared_object.hpp.

Member Typedef Documentation

◆ FunctionAddress

Alias void* to a descriptive "pointer to function" typename.

Definition at line 25 of file shared_object.hpp.

◆ SharedObjectHandle

Types should be at least named. Alias void* to "SharedObjectHandle*.

Definition at line 19 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ SharedObject() [1/4]

sdl::SharedObject::SharedObject ( std::string const &  objectName)
inline

Get a shared object ( = Load the named library dynamically)

Parameters
objectNameName of the library.

Definition at line 29 of file shared_object.hpp.

References SharedObject().

◆ SharedObject() [2/4]

sdl::SharedObject::SharedObject ( )
default

Construct an empty shared object handler. You can move assign to it.

Referenced by operator=(), and SharedObject().

◆ ~SharedObject()

sdl::SharedObject::~SharedObject ( )
inline

Automatically unload the library for you.

Definition at line 38 of file shared_object.hpp.

◆ SharedObject() [3/4]

sdl::SharedObject::SharedObject ( SharedObject &&  other)
inlinenoexcept

Move ctor.

Definition at line 41 of file shared_object.hpp.

◆ SharedObject() [4/4]

sdl::SharedObject::SharedObject ( SharedObject const &  )
delete

This class isn't copyable.

Member Function Documentation

◆ function_pointer() [1/2]

FunctionAddress sdl::SharedObject::function_pointer ( std::string const &  functionName) const
inline

Retrieve the raw address of a function inside the owned object. User has to cast this to the correct function pointer type.

Definition at line 70 of file shared_object.hpp.

Referenced by function_pointer().

◆ function_pointer() [2/2]

template<typename FunctionPointerSignature >
FunctionPointerSignature sdl::SharedObject::function_pointer ( std::string const &  functionName) const
inline

Syntactic sugar overload, provide you a way to specify the actual type of the function pointer e.g: mySharedObject.function_pointer<returnType (*) (args)>("nameOfExportedFunction");.

Parameters
functionNameThe name of a callable symbol that can be found in the loaded library

Definition at line 81 of file shared_object.hpp.

References function_pointer().

◆ operator=() [1/2]

SharedObject& sdl::SharedObject::operator= ( SharedObject &&  other)
inlinenoexcept

Move shared object into this one.

Definition at line 44 of file shared_object.hpp.

References SharedObject().

◆ operator=() [2/2]

SharedObject& sdl::SharedObject::operator= ( SharedObject const &  )
delete

This class isn't copyable.

Member Data Documentation

◆ handle_

SharedObjectHandle sdl::SharedObject::handle_ = nullptr
private

This class wrap an handle to a shared object.

Definition at line 21 of file shared_object.hpp.


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