vtkLegacy.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 
4 #ifndef vtkLegacy_h
5 #define vtkLegacy_h
6 
7 //----------------------------------------------------------------------------
8 // _ _ ___ _____ ___ _ _ ___ _____ ___
9 // | \| | / _ \ |_ _|| __| | \| | / _ \ |_ _|| __|
10 // | . || (_) | | | | _| | . || (_) | | | | _|
11 // |_|\_| \___/ |_| |___| |_|\_| \___/ |_| |___|
12 //
13 // The mechanisms present in this file should no longer be used. Instead, the
14 // mechanisms present in `vtkDeprecation.h` should be preferred. The benefits:
15 //
16 // - documentation of *when* the method was removed
17 // - support for ignoring warnings if an older VTK is also expected to work
18 // - no VTK build will magically take methods away from clients
19 //
20 // When these must be used (though it is no excuse; just pick a new name):
21 //
22 // - changing the signature of a method (e.g., the return type)
23 // - adding non-optional arguments in a way that doesn't support overloading
24 //----------------------------------------------------------------------------
25 
26 /* Compatibility settings. */
27 /* #undef VTK_LEGACY_REMOVE */
28 /* #undef VTK_LEGACY_SILENT */
29 
30 //----------------------------------------------------------------------------
31 // Setup legacy code policy.
32 
33 // Define VTK_LEGACY macro to mark legacy methods where they are
34 // declared in their class. Example usage:
35 //
36 // // @deprecated Replaced by MyOtherMethod() as of VTK 5.0.
37 // VTK_LEGACY(void MyMethod());
38 #if defined(VTK_LEGACY_REMOVE)
39 // Remove legacy methods completely. Put a bogus declaration in
40 // place to avoid stray semicolons because this is an error for some
41 // compilers. Using a class forward declaration allows any number
42 // of repeats in any context without generating unique names.
43 
44 #define VTK_LEGACY(method) VTK_LEGACY__0(method, __LINE__)
45 #define VTK_LEGACY__0(method, line) VTK_LEGACY__1(method, line)
46 #define VTK_LEGACY__1(method, line) class vtkLegacyMethodRemoved##line
47 
48 #elif defined(VTK_LEGACY_SILENT) || defined(VTK_WRAPPING_CXX)
49 // Provide legacy methods with no warnings.
50 #define VTK_LEGACY(method) method
51 #else
52 // Setup compile-time warnings for uses of deprecated methods if
53 // possible on this compiler.
54 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
55 #define VTK_LEGACY(method) method __attribute__((deprecated))
56 #elif defined(_MSC_VER)
57 #define VTK_LEGACY(method) __declspec(deprecated) method
58 #else
59 #define VTK_LEGACY(method) method
60 #endif
61 #endif
62 
63 // Macros to create runtime deprecation warning messages in function
64 // bodies. Example usage:
65 //
66 // #if !defined(VTK_LEGACY_REMOVE)
67 // void vtkMyClass::MyOldMethod()
68 // {
69 // VTK_LEGACY_BODY(vtkMyClass::MyOldMethod, "VTK 5.0");
70 // }
71 // #endif
72 //
73 // #if !defined(VTK_LEGACY_REMOVE)
74 // void vtkMyClass::MyMethod()
75 // {
76 // VTK_LEGACY_REPLACED_BODY(vtkMyClass::MyMethod, "VTK 5.0",
77 // vtkMyClass::MyOtherMethod);
78 // }
79 // #endif
80 #if defined(VTK_LEGACY_REMOVE) || defined(VTK_LEGACY_SILENT)
81 #define VTK_LEGACY_BODY(method, version)
82 #define VTK_LEGACY_REPLACED_BODY(method, version, replace)
83 #else
84 #define VTK_LEGACY_BODY(method, version) \
85  vtkGenericWarningMacro( \
86  #method " was deprecated for " version " and will be removed in a future version.")
87 #define VTK_LEGACY_REPLACED_BODY(method, version, replace) \
88  vtkGenericWarningMacro( \
89  #method " was deprecated for " version \
90  " and will be removed in a future version. Use " #replace " instead.")
91 #endif
92 
93 #endif