SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Namespaces | Macros
Extension.h File Reference
#include "smtk/CoreExports.h"
#include "smtk/SharedFromThis.h"
#include "smtk/common/CompilerInformation.h"
#include <functional>
Include dependency graph for Extension.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  smtk::common::Extension
 Allow extension of operator functionality in separate libraries. More...
 

Namespaces

 smtk
 The main namespace for the Simulation Modeling Tool Kit (SMTK).
 
 smtk::common
 Classes used throughout the toolkit.
 

Macros

#define smtkDeclareExtension(exportmacro, name, cls)
 Provide a way to force registration of operator extensions at load time. More...
 

Macro Definition Documentation

◆ smtkDeclareExtension

#define smtkDeclareExtension (   exportmacro,
  name,
  cls 
)
Value:
void exportmacro smtk_##name##_extension_AutoInit_Construct() \
{ \
#name, \
[]() { return std::dynamic_pointer_cast<smtk::common::Extension>(cls::create()); }, \
/* Never register class-static extension constructor as one-shot */ false); \
} \
void exportmacro smtk_##name##_extension_AutoInit_Destruct() \
{ \
}

Provide a way to force registration of operator extensions at load time.

Invoke this macro in the implementation file of your Extension subclass. Then, including "smtk/AutoInit.h" and invoking smtkAutoInit() in an object file that is directly compiled into an executable target will force registration of the extension even when dynamically linked to the extension with a lazy link-loader.

The macro takes 3 arguments:

  • a macro used to export a global function that will register the class;
  • a unique name under which the extension should be exported (make this a valid variable name as it will be used as such);
  • the fully-qualified name of your class (including all namespaces it is in).

As an example, consider a subclass named AuxGeomFileTestExtension. Inside the AuxGeomFileTestExtension.cxx file, we place:

   smtkDeclareExtension(
     SMTKVTKEXTENSIONS_EXPORT,
     aux_geom_file_test,
     AuxGeomFileTestExtension);
 

Then, inside an executable, we can place:

   #include "smtk/AutoInit.h"
   smtkAutoInit(aux_geom_file_test_extension);
 

and be guaranteed that the extension will be registered. Note that when you call the smtkAutoInit() macro, you should add _extension to the name you passed to smtkDeclareExtension().

smtk::common::Extension::unregisterExtension
static bool unregisterExtension(const std::string &name)
Remove an extension from the registry.
Definition: Extension.cxx:50
smtk::common::Extension::registerExtension
static bool registerExtension(const std::string &name, std::function< Extension::Ptr(void)> ctor, bool oneShot=true)
Register an extension with a unique name.
Definition: Extension.cxx:28