VTK  9.3.20240721
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() { VTK_AUTOINIT_CONSTRUCT_##T } \
22 } M##_AutoInit_Instance; /* NOLINT(misc-definitions-in-headers) */ \
23 }
24
25#define VTK_AUTOINIT_DECLARE_0()
26#define VTK_AUTOINIT_DECLARE_1(t1) VTK_AUTOINIT_DECLARE_0() VTK_AUTOINIT_DECLARE(t1)
27#define VTK_AUTOINIT_DECLARE_2(t1, t2) VTK_AUTOINIT_DECLARE_1(t1) VTK_AUTOINIT_DECLARE(t2)
28#define VTK_AUTOINIT_DECLARE_3(t1, t2, t3) VTK_AUTOINIT_DECLARE_2(t1, t2) VTK_AUTOINIT_DECLARE(t3)
29#define VTK_AUTOINIT_DECLARE_4(t1, t2, t3, t4) \
30 VTK_AUTOINIT_DECLARE_3(t1, t2, t3) VTK_AUTOINIT_DECLARE(t4)
31#define VTK_AUTOINIT_DECLARE_5(t1, t2, t3, t4, t5) \
32 VTK_AUTOINIT_DECLARE_4(t1, t2, t3, t4) VTK_AUTOINIT_DECLARE(t5)
33#define VTK_AUTOINIT_DECLARE_6(t1, t2, t3, t4, t5, t6) \
34 VTK_AUTOINIT_DECLARE_5(t1, t2, t3, t4, t5) VTK_AUTOINIT_DECLARE(t6)
35#define VTK_AUTOINIT_DECLARE_7(t1, t2, t3, t4, t5, t6, t7) \
36 VTK_AUTOINIT_DECLARE_6(t1, t2, t3, t4, t5, t6) VTK_AUTOINIT_DECLARE(t7)
37#define VTK_AUTOINIT_DECLARE_8(t1, t2, t3, t4, t5, t6, t7, t8) \
38 VTK_AUTOINIT_DECLARE_7(t1, t2, t3, t4, t5, t6, t7) VTK_AUTOINIT_DECLARE(t8)
39#define VTK_AUTOINIT_DECLARE_9(t1, t2, t3, t4, t5, t6, t7, t8, t9) \
40 VTK_AUTOINIT_DECLARE_8(t1, t2, t3, t4, t5, t6, t7, t8) VTK_AUTOINIT_DECLARE(t9)
41#define VTK_AUTOINIT_DECLARE(M) \
42 VTK_ABI_NAMESPACE_BEGIN void M##_AutoInit_Construct(); \
43 VTK_ABI_NAMESPACE_END
44
45#define VTK_AUTOINIT_CONSTRUCT_0()
46#define VTK_AUTOINIT_CONSTRUCT_1(t1) VTK_AUTOINIT_CONSTRUCT_0() VTK_AUTOINIT_CONSTRUCT(t1)
47#define VTK_AUTOINIT_CONSTRUCT_2(t1, t2) VTK_AUTOINIT_CONSTRUCT_1(t1) VTK_AUTOINIT_CONSTRUCT(t2)
48#define VTK_AUTOINIT_CONSTRUCT_3(t1, t2, t3) \
49 VTK_AUTOINIT_CONSTRUCT_2(t1, t2) VTK_AUTOINIT_CONSTRUCT(t3)
50#define VTK_AUTOINIT_CONSTRUCT_4(t1, t2, t3, t4) \
51 VTK_AUTOINIT_CONSTRUCT_3(t1, t2, t3) VTK_AUTOINIT_CONSTRUCT(t4)
52#define VTK_AUTOINIT_CONSTRUCT_5(t1, t2, t3, t4, t5) \
53 VTK_AUTOINIT_CONSTRUCT_4(t1, t2, t3, t4) VTK_AUTOINIT_CONSTRUCT(t5)
54#define VTK_AUTOINIT_CONSTRUCT_6(t1, t2, t3, t4, t5, t6) \
55 VTK_AUTOINIT_CONSTRUCT_5(t1, t2, t3, t4, t5) VTK_AUTOINIT_CONSTRUCT(t6)
56#define VTK_AUTOINIT_CONSTRUCT_7(t1, t2, t3, t4, t5, t6, t7) \
57 VTK_AUTOINIT_CONSTRUCT_6(t1, t2, t3, t4, t5, t6) VTK_AUTOINIT_CONSTRUCT(t7)
58#define VTK_AUTOINIT_CONSTRUCT_8(t1, t2, t3, t4, t5, t6, t7, t8) \
59 VTK_AUTOINIT_CONSTRUCT_7(t1, t2, t3, t4, t5, t6, t7) VTK_AUTOINIT_CONSTRUCT(t8)
60#define VTK_AUTOINIT_CONSTRUCT_9(t1, t2, t3, t4, t5, t6, t7, t8, t9) \
61 VTK_AUTOINIT_CONSTRUCT_8(t1, t2, t3, t4, t5, t6, t7, t8) VTK_AUTOINIT_CONSTRUCT(t9)
62#define VTK_AUTOINIT_CONSTRUCT(M) M##_AutoInit_Construct();
63
64// Description:
65// Initialize the named module, ensuring its object factory is correctly
66// registered. This call must be made in global scope in the
67// translation unit of your executable (which can include a shared library, but
68// will not work as expected in a static library).
69//
70// @code{.cpp}
71// #include "vtkAutoInit.h"
72// VTK_MODULE_INIT(vtkRenderingOpenGL2);
73// @endcode
74//
75// The above snippet if included in the global scope will ensure the object
76// factories for vtkRenderingOpenGL2 are correctly registered and unregistered.
77#define VTK_MODULE_INIT(M) \
78 VTK_AUTOINIT_DECLARE(M) \
79 namespace \
80 { \
81 static struct M##_ModuleInit \
82 { \
83 /* Call <mod>_AutoInit_Construct during initialization. */ \
84 M##_ModuleInit() { VTK_AUTOINIT_CONSTRUCT(M) } \
85 } M##_ModuleInit_Instance; \
86 }
87
88#endif
89// VTK-HeaderTest-Exclude: vtkAutoInit.h