iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::DynamicLoader Class Reference

#include <nrt/Core/Util/DynamicLoader.H>

A class to open shared object (.so) files and load functions contained in them.

Definition at line 48 of file DynamicLoader.H.

Public Member Functions

 DynamicLoader (std::string const &filename)
 Open the shared object located at filename. More...
 
void close ()
 Close the shared object file. More...
 
template<class Signature >
std::function< Signature > load (std::string const &functionName)
 Load the symbol named functionName. More...
 

Constructor & Destructor Documentation

nrt::DynamicLoader::DynamicLoader ( std::string const &  filename)
inline

Open the shared object located at filename.

Exceptions
nrt::exception::DynamicLoaderExceptionThe requested shared object file could not be opened

Definition at line 36 of file DynamicLoaderImpl.H.

References NRT_WARNING.

Member Function Documentation

void nrt::DynamicLoader::close ( )
inline

Close the shared object file.

Beware that closing the object file will remove all links to any objects/functions/etc that have been created from the shared object. Use this function only if you want nothing more to do with anything created from this object file.

Definition at line 58 of file DynamicLoaderImpl.H.

template<class Signature >
std::function< Signature > nrt::DynamicLoader::load ( std::string const &  functionName)
inline

Load the symbol named functionName.

      This method returns an std::function that points to the requested name in the shared object opened by this
      DynamicLoader. For example, to load the function <code>int foo(double x, bool y)</code> from the file
      "mySharedObject.so" you should write:
nrt::DynamicLoader loader("./mySharedObject.so");
try
{
std::function<int(double,bool)> foo = loader.load<int(double,bool)>("foo");
}
{
}
int result = foo(3.0, true);
Note
You should not try to use anything returned by load() after the DynamicLoader has been close()ed or destroyed.
Exceptions
nrt::exception::DynamicLoaderExceptionThe requested symbol could not be found in the opened shared object

Definition at line 65 of file DynamicLoaderImpl.H.

References NRT_WARNING.


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