OpenWalker Project
Documentation of the ROS Packages
Public Types | Public Member Functions | Protected Attributes | List of all members
ow_plugin_loader::ClassLoader Class Reference

The ClassLoader class. More...

#include <class_loader.h>

Public Types

typedef ow_core::IGenericClass IGenericClass
 

Public Member Functions

 ClassLoader (const std::string &libFilePath="")
 Default constructor.
 
virtual ~ClassLoader ()
 Deconstructor.
 
bool open (const std::string &libFilePath="")
 Open and load the shared lib which contains the desired class to create. More...
 
bool close ()
 Unload and close the shared lib. More...
 
bool isOpened () const
 
bool isClosed () const
 
IGenericClasscreateClassGeneric ()
 Create a new class of the loaded library and return a generic pointer.
 
template<class IClass >
IClass * createClass ()
 Create a new class of the loaded library with the specified type. More...
 
void destroyClass (IGenericClass *ptr)
 Destroy a created class using the loaded lib to avoid memory leaks. More...
 

Protected Attributes

void * handle_
 the handle for shared library
 
bool opened_
 opened/closed flag
 
std::string libFilePath_
 file path to .so library
 

Detailed Description

The ClassLoader class.

This class can load shared libraries at runtime and can create classes from the loaded lib.

Member Function Documentation

bool ow_plugin_loader::ClassLoader::close ( )

Unload and close the shared lib.

NOTE: This invalidates all the classes which might have been created.

template<class IClass >
IClass* ow_plugin_loader::ClassLoader::createClass ( )
inline

Create a new class of the loaded library with the specified type.

NOTE: You need to be sure that you use the right interface class type IClass.

NOTE: The class is allocated on the heap and the caller of this function needs to free the class when needed.

The return of a nullptr indicates that something went wrong.

void ow_plugin_loader::ClassLoader::destroyClass ( IGenericClass ptr)

Destroy a created class using the loaded lib to avoid memory leaks.

This is the counter part for the createXXX functions. Don't use delete on the pointer that you get from the createXXX fuctions. Use this function instead.

bool ow_plugin_loader::ClassLoader::open ( const std::string &  libFilePath = "")

Open and load the shared lib which contains the desired class to create.

Uses the previously defined file path if the arg is empty.


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