cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros
cmnPlugin.h File Reference

Macro for generating plugin wrappers (factory methods). More...

#include <typeinfo>
#include <cisstCommon/cmnExport.h>

Go to the source code of this file.

Macros

#define _cmnPlugin_h
 
#define CMN_PLUGIN_WRAPPERS(base, derived)
 

Detailed Description

Macro for generating plugin wrappers (factory methods).

This macro should be used if the base class is NOT derived from cmnGenericObject. In this case, the macro creates the factory methods and associated data to ensure safe creation of instances of the derived class. If this macro is used, the shared library should be loaded using the osaDynamicLoaderAndFactory class. Note that this factory verifies the base class type and its version (to ensure that the shared library was compiled with the same version of the base class as the executable).

If the base class is (or is derived from) cmnGenericObject, then this macro should not be used. Instead, it is better to use osaDynamicLoader to load the shared library and to use the class services (cmnClassRegister) to create instances of the derived class.

See Also
osaDynamicLoader, osaDynamicLoaderAndFactory

Macro Definition Documentation

#define _cmnPlugin_h
#define CMN_PLUGIN_WRAPPERS (   base,
  derived 
)
Value:
extern "C" CISST_EXPORT base* derived##Create() \
{ return new derived; } \
extern "C" CISST_EXPORT void derived##Destroy(base* obj) \
{ delete obj; obj = 0; } \
extern "C" CISST_EXPORT const std::type_info &derived##BaseType = typeid(base); \
extern "C" CISST_EXPORT const int derived##Version = derived::VERSION;
#define CISST_EXPORT
Definition: cmnExportMacros.h:50

This macro creates the functions and data necessary to allow the derived class to be dynamically loaded (as a "plugin") into a running application, using the osaDynamicLoaderAndFactory class. The only requirement on the base class is that it define a public VERSION enum that specifies its "interface version."

Parameters
baseBase class that defines the interface (usually abstract)
derivedDerived class implemented in the plugin module