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.


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


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


#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,
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:


Then, inside an executable, we can place:

   #include "smtk/AutoInit.h"

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().

static bool unregisterExtension(const std::string &name)
Remove an extension from the registry.
Definition: Extension.cxx:50
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