AutoInit.h 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9
//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================
10 11
#ifndef __smtk_AutoInit_h
#define __smtk_AutoInit_h
12
/*! \file */
13 14 15 16 17

// This file contains macros used to initialize components of SMTK
// that may defined in separate libraries but which need to be
// exposed to SMTK's core components.
//
18
// See smtk/model/Session.h and its subclasses for an example of how
19
// these macros are used to register components with the model Manager.
20

21 22
#define smtkAutoInitComponentMacro(C)                                                              \
  void C##_AutoInit_Construct();                                                                   \
23
  void C##_AutoInit_Destruct();
24 25
#define smtkAutoInitConstructMacro(C) C##_AutoInit_Construct();
#define smtkAutoInitDestructMacro(C) C##_AutoInit_Destruct();
26 27 28 29 30 31 32 33 34 35 36 37

/**\brief Register an SMTK component for use.
  *
  * Initialize the named SMTK component (such as a modeling kernel), ensuring
  * it is correctly registered and unregistered. This call must be made in
  * global scope in the translation unit of your executable (which can include
  * code built into a shared library linked to your executable, but will not
  * work as expected in code linked to your executable as part of a static
  * library).
  *
  * @code{.cpp}
  * #include "vtkAutoInit.h"
38
  * smtkComponentInitMacro(smtk_cgm_session);
39 40 41
  * @endcode
  *
  * If included in the global scope, the above snippet will ensure the
42
  * global function smtk_cgm_session_AutoInit_Construct is called during
43
  * dynamic C++ initialization and and the global function
44
  * smtk_cgm_session_AutoInit_Destruct is called during finalization.
45
  */
46 47 48 49 50 51 52
#define smtkComponentInitMacro(C)                                                                  \
  smtkAutoInitComponentMacro(C) static struct C##_ComponentInit                                    \
  {                                                                                                \
    /* Call <mod>_AutoInit_Construct during initialization.  */                                    \
    C##_ComponentInit() { smtkAutoInitConstructMacro(C) }                                          \
    /* Call <mod>_AutoInit_Destruct during finalization.  */                                       \
    ~C##_ComponentInit() { smtkAutoInitDestructMacro(C) }                                          \
53 54
  } C##_ComponentInit_Instance;

55
#endif // __smtk_AutoInit_h