VTK
vtkAutoInit.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAutoInit.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #ifndef vtkAutoInit_h
16 #define vtkAutoInit_h
17 
18 #include "vtkDebugLeaksManager.h" // DebugLeaks exists longer.
19 #include "vtkTimeStamp.h" // Here so that TimeStamp Schwarz initializer works
20 
21 #define VTK_AUTOINIT(M) VTK_AUTOINIT0(M,M##_AUTOINIT)
22 #define VTK_AUTOINIT0(M,T) VTK_AUTOINIT1(M,T)
23 #define VTK_AUTOINIT1(M,T) \
24  /* Declare every <mod>_AutoInit_(Construct|Destruct) function. */ \
25  VTK_AUTOINIT_DECLARE_##T \
26  static struct M##_AutoInit { \
27  /* Call every <mod>_AutoInit_Construct during initialization. */ \
28  M##_AutoInit() { VTK_AUTOINIT_CONSTRUCT_##T } \
29  /* Call every <mod>_AutoInit_Destruct during finalization. */ \
30  ~M##_AutoInit() { VTK_AUTOINIT_DESTRUCT_##T } \
31  } M##_AutoInit_Instance;
32 
33 #define VTK_AUTOINIT_DECLARE_0()
34 #define VTK_AUTOINIT_DECLARE_1(t1) VTK_AUTOINIT_DECLARE_0() VTK_AUTOINIT_DECLARE(t1)
35 #define VTK_AUTOINIT_DECLARE_2(t1,t2) VTK_AUTOINIT_DECLARE_1(t1) VTK_AUTOINIT_DECLARE(t2)
36 #define VTK_AUTOINIT_DECLARE_3(t1,t2,t3) VTK_AUTOINIT_DECLARE_2(t1,t2) VTK_AUTOINIT_DECLARE(t3)
37 #define VTK_AUTOINIT_DECLARE_4(t1,t2,t3,t4) VTK_AUTOINIT_DECLARE_3(t1,t2,t3) VTK_AUTOINIT_DECLARE(t4)
38 #define VTK_AUTOINIT_DECLARE_5(t1,t2,t3,t4,t5) VTK_AUTOINIT_DECLARE_4(t1,t2,t3,t4) VTK_AUTOINIT_DECLARE(t5)
39 #define VTK_AUTOINIT_DECLARE_6(t1,t2,t3,t4,t5,t6) VTK_AUTOINIT_DECLARE_5(t1,t2,t3,t4,t5) VTK_AUTOINIT_DECLARE(t6)
40 #define VTK_AUTOINIT_DECLARE_7(t1,t2,t3,t4,t5,t6,t7) VTK_AUTOINIT_DECLARE_6(t1,t2,t3,t4,t5,t6) VTK_AUTOINIT_DECLARE(t7)
41 #define VTK_AUTOINIT_DECLARE_8(t1,t2,t3,t4,t5,t6,t7,t8) VTK_AUTOINIT_DECLARE_7(t1,t2,t3,t4,t5,t6,t7) VTK_AUTOINIT_DECLARE(t8)
42 #define VTK_AUTOINIT_DECLARE_9(t1,t2,t3,t4,t5,t6,t7,t8,t9) VTK_AUTOINIT_DECLARE_8(t1,t2,t3,t4,t5,t6,t7,t8) VTK_AUTOINIT_DECLARE(t9)
43 #define VTK_AUTOINIT_DECLARE(M) \
44  void M##_AutoInit_Construct(); \
45  void M##_AutoInit_Destruct();
46 
47 #define VTK_AUTOINIT_CONSTRUCT_0()
48 #define VTK_AUTOINIT_CONSTRUCT_1(t1) VTK_AUTOINIT_CONSTRUCT_0() VTK_AUTOINIT_CONSTRUCT(t1)
49 #define VTK_AUTOINIT_CONSTRUCT_2(t1,t2) VTK_AUTOINIT_CONSTRUCT_1(t1) VTK_AUTOINIT_CONSTRUCT(t2)
50 #define VTK_AUTOINIT_CONSTRUCT_3(t1,t2,t3) VTK_AUTOINIT_CONSTRUCT_2(t1,t2) VTK_AUTOINIT_CONSTRUCT(t3)
51 #define VTK_AUTOINIT_CONSTRUCT_4(t1,t2,t3,t4) VTK_AUTOINIT_CONSTRUCT_3(t1,t2,t3) VTK_AUTOINIT_CONSTRUCT(t4)
52 #define VTK_AUTOINIT_CONSTRUCT_5(t1,t2,t3,t4,t5) VTK_AUTOINIT_CONSTRUCT_4(t1,t2,t3,t4) VTK_AUTOINIT_CONSTRUCT(t5)
53 #define VTK_AUTOINIT_CONSTRUCT_6(t1,t2,t3,t4,t5,t6) VTK_AUTOINIT_CONSTRUCT_5(t1,t2,t3,t4,t5) VTK_AUTOINIT_CONSTRUCT(t6)
54 #define VTK_AUTOINIT_CONSTRUCT_7(t1,t2,t3,t4,t5,t6,t7) VTK_AUTOINIT_CONSTRUCT_6(t1,t2,t3,t4,t5,t6) VTK_AUTOINIT_CONSTRUCT(t7)
55 #define VTK_AUTOINIT_CONSTRUCT_8(t1,t2,t3,t4,t5,t6,t7,t8) VTK_AUTOINIT_CONSTRUCT_7(t1,t2,t3,t4,t5,t6,t7) VTK_AUTOINIT_CONSTRUCT(t8)
56 #define VTK_AUTOINIT_CONSTRUCT_9(t1,t2,t3,t4,t5,t6,t7,t8,t9) VTK_AUTOINIT_CONSTRUCT_8(t1,t2,t3,t4,t5,t6,t7,t8) VTK_AUTOINIT_CONSTRUCT(t9)
57 #define VTK_AUTOINIT_CONSTRUCT(M) \
58  M##_AutoInit_Construct();
59 
60 #define VTK_AUTOINIT_DESTRUCT_0()
61 #define VTK_AUTOINIT_DESTRUCT_1(t1) VTK_AUTOINIT_DESTRUCT_0() VTK_AUTOINIT_DESTRUCT(t1)
62 #define VTK_AUTOINIT_DESTRUCT_2(t1,t2) VTK_AUTOINIT_DESTRUCT_1(t1) VTK_AUTOINIT_DESTRUCT(t2)
63 #define VTK_AUTOINIT_DESTRUCT_3(t1,t2,t3) VTK_AUTOINIT_DESTRUCT_2(t1,t2) VTK_AUTOINIT_DESTRUCT(t3)
64 #define VTK_AUTOINIT_DESTRUCT_4(t1,t2,t3,t4) VTK_AUTOINIT_DESTRUCT_3(t1,t2,t3) VTK_AUTOINIT_DESTRUCT(t4)
65 #define VTK_AUTOINIT_DESTRUCT_5(t1,t2,t3,t4,t5) VTK_AUTOINIT_DESTRUCT_4(t1,t2,t3,t4) VTK_AUTOINIT_DESTRUCT(t5)
66 #define VTK_AUTOINIT_DESTRUCT_6(t1,t2,t3,t4,t5,t6) VTK_AUTOINIT_DESTRUCT_5(t1,t2,t3,t4,t5) VTK_AUTOINIT_DESTRUCT(t6)
67 #define VTK_AUTOINIT_DESTRUCT_7(t1,t2,t3,t4,t5,t6,t7) VTK_AUTOINIT_DESTRUCT_6(t1,t2,t3,t4,t5,t6) VTK_AUTOINIT_DESTRUCT(t7)
68 #define VTK_AUTOINIT_DESTRUCT_8(t1,t2,t3,t4,t5,t6,t7,t8) VTK_AUTOINIT_DESTRUCT_7(t1,t2,t3,t4,t5,t6,t7) VTK_AUTOINIT_DESTRUCT(t8)
69 #define VTK_AUTOINIT_DESTRUCT_9(t1,t2,t3,t4,t5,t6,t7,t8,t9) VTK_AUTOINIT_DESTRUCT_8(t1,t2,t3,t4,t5,t6,t7,t8) VTK_AUTOINIT_DESTRUCT(t9)
70 #define VTK_AUTOINIT_DESTRUCT(M) \
71  M##_AutoInit_Destruct();
72 
73 // Description:
74 // Initialize the named module, ensuring its object factory is correctly
75 // registered and unregistered. This call must be made in global scope in the
76 // translation unit of your executable (which can include a shared library, but
77 // will not work as expected in a static library).
78 //
79 // @code{.cpp}
80 // #include "vtkAutoInit.h"
81 // VTK_MODULE_INIT(vtkRenderingOpenGL);
82 // @endcode
83 //
84 // The above snippet if included in the global scope will ensure the object
85 // factories for vtkRenderingOpenGL are correctly registered and unregistered.
86 #define VTK_MODULE_INIT(M) \
87  VTK_AUTOINIT_DECLARE(M) \
88  static struct M##_ModuleInit { \
89  /* Call <mod>_AutoInit_Construct during initialization. */ \
90  M##_ModuleInit() { VTK_AUTOINIT_CONSTRUCT(M) } \
91  /* Call <mod>_AutoInit_Destruct during finalization. */ \
92  ~M##_ModuleInit() { VTK_AUTOINIT_DESTRUCT(M) } \
93  } M##_ModuleInit_Instance;
94 
95 
96 #endif
97 // VTK-HeaderTest-Exclude: vtkAutoInit.h