VTK  9.4.20241222
vtkAutoInit.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#ifndef vtkAutoInit_h
4#define vtkAutoInit_h
5
6#include "vtkABINamespace.h"
7#include "vtkDebugLeaksManager.h" // DebugLeaks exists longer.
8#include "vtkTimeStamp.h" // Here so that TimeStamp Schwarz initializer works
9
10#define VTK_MODULE_AUTOINIT VTK_AUTOINIT
11
12#define VTK_AUTOINIT(M) VTK_AUTOINIT0(M, M##_AUTOINIT)
13#define VTK_AUTOINIT0(M, T) VTK_AUTOINIT1(M, T)
14#define VTK_AUTOINIT1(M, T) \
15 /* Declare every <mod>_AutoInit_Construct function. */ \
16 VTK_AUTOINIT_DECLARE_##T namespace \
17 { \
18 static struct M##_AutoInit \
19 { \
20 /* Call every <mod>_AutoInit_Construct during initialization. */ \
21 M##_AutoInit() \
22 { \
23 VTK_AUTOINIT_CONSTRUCT_##T \
24 } \
25 } M##_AutoInit_Instance; /* NOLINT(misc-definitions-in-headers) */ \
26 }
27
28#define VTK_AUTOINIT_DECLARE_0()
29#define VTK_AUTOINIT_DECLARE_1(t1) VTK_AUTOINIT_DECLARE_0() VTK_AUTOINIT_DECLARE(t1)
30#define VTK_AUTOINIT_DECLARE_2(t1, t2) VTK_AUTOINIT_DECLARE_1(t1) VTK_AUTOINIT_DECLARE(t2)
31#define VTK_AUTOINIT_DECLARE_3(t1, t2, t3) VTK_AUTOINIT_DECLARE_2(t1, t2) VTK_AUTOINIT_DECLARE(t3)
32#define VTK_AUTOINIT_DECLARE_4(t1, t2, t3, t4) \
33 VTK_AUTOINIT_DECLARE_3(t1, t2, t3) VTK_AUTOINIT_DECLARE(t4)
34#define VTK_AUTOINIT_DECLARE_5(t1, t2, t3, t4, t5) \
35 VTK_AUTOINIT_DECLARE_4(t1, t2, t3, t4) VTK_AUTOINIT_DECLARE(t5)
36#define VTK_AUTOINIT_DECLARE_6(t1, t2, t3, t4, t5, t6) \
37 VTK_AUTOINIT_DECLARE_5(t1, t2, t3, t4, t5) VTK_AUTOINIT_DECLARE(t6)
38#define VTK_AUTOINIT_DECLARE_7(t1, t2, t3, t4, t5, t6, t7) \
39 VTK_AUTOINIT_DECLARE_6(t1, t2, t3, t4, t5, t6) VTK_AUTOINIT_DECLARE(t7)
40#define VTK_AUTOINIT_DECLARE_8(t1, t2, t3, t4, t5, t6, t7, t8) \
41 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) \
43 VTK_AUTOINIT_DECLARE_8(t1, t2, t3, t4, t5, t6, t7, t8) VTK_AUTOINIT_DECLARE(t9)
44#define VTK_AUTOINIT_DECLARE(M) \
45 VTK_ABI_NAMESPACE_BEGIN void M##_AutoInit_Construct(); \
46 VTK_ABI_NAMESPACE_END
47
48#define VTK_AUTOINIT_CONSTRUCT_0()
49#define VTK_AUTOINIT_CONSTRUCT_1(t1) VTK_AUTOINIT_CONSTRUCT_0() VTK_AUTOINIT_CONSTRUCT(t1)
50#define VTK_AUTOINIT_CONSTRUCT_2(t1, t2) VTK_AUTOINIT_CONSTRUCT_1(t1) VTK_AUTOINIT_CONSTRUCT(t2)
51#define VTK_AUTOINIT_CONSTRUCT_3(t1, t2, t3) \
52 VTK_AUTOINIT_CONSTRUCT_2(t1, t2) VTK_AUTOINIT_CONSTRUCT(t3)
53#define VTK_AUTOINIT_CONSTRUCT_4(t1, t2, t3, t4) \
54 VTK_AUTOINIT_CONSTRUCT_3(t1, t2, t3) VTK_AUTOINIT_CONSTRUCT(t4)
55#define VTK_AUTOINIT_CONSTRUCT_5(t1, t2, t3, t4, t5) \
56 VTK_AUTOINIT_CONSTRUCT_4(t1, t2, t3, t4) VTK_AUTOINIT_CONSTRUCT(t5)
57#define VTK_AUTOINIT_CONSTRUCT_6(t1, t2, t3, t4, t5, t6) \
58 VTK_AUTOINIT_CONSTRUCT_5(t1, t2, t3, t4, t5) VTK_AUTOINIT_CONSTRUCT(t6)
59#define VTK_AUTOINIT_CONSTRUCT_7(t1, t2, t3, t4, t5, t6, t7) \
60 VTK_AUTOINIT_CONSTRUCT_6(t1, t2, t3, t4, t5, t6) VTK_AUTOINIT_CONSTRUCT(t7)
61#define VTK_AUTOINIT_CONSTRUCT_8(t1, t2, t3, t4, t5, t6, t7, t8) \
62 VTK_AUTOINIT_CONSTRUCT_7(t1, t2, t3, t4, t5, t6, t7) VTK_AUTOINIT_CONSTRUCT(t8)
63#define VTK_AUTOINIT_CONSTRUCT_9(t1, t2, t3, t4, t5, t6, t7, t8, t9) \
64 VTK_AUTOINIT_CONSTRUCT_8(t1, t2, t3, t4, t5, t6, t7, t8) VTK_AUTOINIT_CONSTRUCT(t9)
65#define VTK_AUTOINIT_CONSTRUCT(M) M##_AutoInit_Construct();
66
67// Description:
68// Initialize the named module, ensuring its object factory is correctly
69// registered. This call must be made in global scope in the
70// translation unit of your executable (which can include a shared library, but
71// will not work as expected in a static library).
72//
73// @code{.cpp}
74// #include "vtkAutoInit.h"
75// VTK_MODULE_INIT(vtkRenderingOpenGL2);
76// @endcode
77//
78// The above snippet if included in the global scope will ensure the object
79// factories for vtkRenderingOpenGL2 are correctly registered and unregistered.
80#define VTK_MODULE_INIT(M) \
81 VTK_AUTOINIT_DECLARE(M) \
82 namespace \
83 { \
84 static struct M##_ModuleInit \
85 { \
86 /* Call <mod>_AutoInit_Construct during initialization. */ \
87 M##_ModuleInit() \
88 { \
89 VTK_AUTOINIT_CONSTRUCT(M) \
90 } \
91 } M##_ModuleInit_Instance; \
92 }
93
94#endif
95// VTK-HeaderTest-Exclude: vtkAutoInit.h