mc_rtc::ObjectLoader Class Reference

ltdl wrapper for factory-like classes More...

#include <mc_rtc/loader.h>

Collaboration diagram for mc_rtc::ObjectLoader:

Classes

struct  ObjectDeleter
 

Public Types

using unique_ptr = std::unique_ptr< T, ObjectDeleter >
 

Public Member Functions

 ObjectLoader (const std::string &class_name, const std::vector< std::string > &paths, bool verbose, Loader::callback_t cb=Loader::default_cb)
 
 ~ObjectLoader ()
 
bool has_object (const std::string &name) const
 
std::vector< std::string > objects () const
 
void load_libraries (const std::vector< std::string > &paths, Loader::callback_t cb=Loader::default_cb)
 
void clear ()
 
void set_verbosity (bool verbose)
 
template<typename RetT , typename... Args>
void register_object (const std::string &name, std::function< RetT *(const Args &...)> callback)
 
template<typename... Args>
std::shared_ptr< T > create_object (const std::string &name, Args... args)
 
std::string get_object_runtime_directory (const std::string &name) const noexcept
 
template<typename... Args>
unique_ptr create_unique_object (const std::string &name, Args... args)
 

Protected Member Functions

template<typename... Args>
T * create (const std::string &name, Args... args)
 
template<typename... Args>
T * create_from_handles (const std::string &name, Args... args)
 
template<typename... Args>
T * create_from_callbacks (const std::string &name, Args... args)
 

Protected Attributes

std::string class_name
 
bool verbose
 
Loader::handle_map_t handles_
 
mc_rtc::DataStore callbacks_
 
std::unordered_map< std::string, ObjectDeleterdeleters_
 

Detailed Description

ltdl wrapper for factory-like classes

Member Typedef Documentation

◆ unique_ptr

using mc_rtc::ObjectLoader::unique_ptr = std::unique_ptr<T, ObjectDeleter>

Constructor & Destructor Documentation

◆ ObjectLoader()

mc_rtc::ObjectLoader::ObjectLoader ( const std::string &  class_name,
const std::vector< std::string > &  paths,
bool  verbose,
Loader::callback_t  cb = Loader::default_cb 
)

Create ObjectLoader instance

Parameters
class_nameSymbol used to distinguish the relevant libraries
pathsdirectories searched for libraries
verboseIf true, output some warning information
cbFunction called when a new object is loaded

◆ ~ObjectLoader()

mc_rtc::ObjectLoader::~ObjectLoader ( )

Destructor

Member Function Documentation

◆ clear()

void mc_rtc::ObjectLoader::clear ( )

Remove all loaded libraries

◆ create()

template<typename... Args>
T* mc_rtc::ObjectLoader::create ( const std::string &  name,
Args...  args 
)
protected

Internal function to create a raw pointer

◆ create_from_callbacks()

template<typename... Args>
T* mc_rtc::ObjectLoader::create_from_callbacks ( const std::string &  name,
Args...  args 
)
protected

Internal function to create a raw pointer from a registered callback

◆ create_from_handles()

template<typename... Args>
T* mc_rtc::ObjectLoader::create_from_handles ( const std::string &  name,
Args...  args 
)
protected

Internal function to create a raw pointer from an handle

◆ create_object()

template<typename... Args>
std::shared_ptr<T> mc_rtc::ObjectLoader::create_object ( const std::string &  name,
Args...  args 
)

Create a new object of type name

Parameters
namethe object's name
Argsargument required by the constructor
Returns
a shared pointer properly equipped to destroy the pointer
Exceptions
LoaderExceptionthrow if the name does not exist or if symbol resolution fails

◆ create_unique_object()

template<typename... Args>
unique_ptr mc_rtc::ObjectLoader::create_unique_object ( const std::string &  name,
Args...  args 
)

Create a new object of type name

Parameters
namethe object's name
Argsarguments required by the constructor
Returns
a unique pointer with a destructor provided by the library
Exceptions
LoaderExceptionif the name does not exist or if symbol resolution fails

◆ get_object_runtime_directory()

std::string mc_rtc::ObjectLoader::get_object_runtime_directory ( const std::string &  name) const
noexcept

Returns the runtime directory of an object

Returns an empty string when the object is registered via a callback or if the object is unknown

Parameters
nameName of the object

◆ has_object()

bool mc_rtc::ObjectLoader::has_object ( const std::string &  name) const

Returns true if the loader has the name object

Parameters
nameName to be tested

◆ load_libraries()

void mc_rtc::ObjectLoader::load_libraries ( const std::vector< std::string > &  paths,
Loader::callback_t  cb = Loader::default_cb 
)

Load libraries from the paths provided

Parameters
pathsdirectories searched for libraries
verboseIf true, output some warning information

◆ objects()

std::vector<std::string> mc_rtc::ObjectLoader::objects ( ) const

Returns the list of available objects

Returns
A list of available objects

◆ register_object()

template<typename RetT , typename... Args>
void mc_rtc::ObjectLoader::register_object ( const std::string &  name,
std::function< RetT *(const Args &...)>  callback 
)

Register a new loading function

Parameters
nameName that will be used to create new instance
callbackCallback that will be used to create the object
Template Parameters
RetTMust be derived from T
Exceptions
LoaderExceptionif the object is already registered

◆ set_verbosity()

void mc_rtc::ObjectLoader::set_verbosity ( bool  verbose)

Set the verbosity

Parameters
verboseIf true, loader will be more verbose

Member Data Documentation

◆ callbacks_

mc_rtc::DataStore mc_rtc::ObjectLoader::callbacks_
protected

◆ class_name

std::string mc_rtc::ObjectLoader::class_name
protected

◆ deleters_

std::unordered_map<std::string, ObjectDeleter> mc_rtc::ObjectLoader::deleters_
protected

◆ handles_

Loader::handle_map_t mc_rtc::ObjectLoader::handles_
protected

◆ verbose

bool mc_rtc::ObjectLoader::verbose
protected

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