VTK  9.7.20260801
vtkWrappingHints.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
10
11#ifndef vtkWrappingHints_h
12#define vtkWrappingHints_h
13
14// When using Clang frontend, define VTK_WRAP_HINTS_USE_CLANG_ANNOTATE to use
15// the annotate attribute instead of VTK custom C++ attributes.
16// This is useful for external clang-based tool,
17// since Clang will remove unknown attributes from its AST.
18// When VTK_WRAP_HINTS_USE_CLANG_ANNOTATE is defined,
19// `[[vtk::attr(value)]]` will become `annotate("vtk::attr(value)")`,
20// which will appear as `AnnotateAttr "vtk::attr(value)"` in the AST.
21#ifdef VTK_WRAP_HINTS_USE_CLANG_ANNOTATE
22#define VTK_DEFINE_WRAP_HINT(name) __attribute__((annotate(#name)))
23#define VTK_DEFINE_WRAP_HINT_ARGS(name, ...) __attribute__((annotate(#name "(" #__VA_ARGS__ ")")))
24#else
25#define VTK_DEFINE_WRAP_HINT(name) [[name]]
26#define VTK_DEFINE_WRAP_HINT_ARGS(name, ...) [[name(__VA_ARGS__)]]
27#endif
28
29#if defined(__VTK_WRAP__) || defined(VTK_WRAP_HINTS_USE_CLANG_ANNOTATE)
30#define VTK_WRAP_HINTS_DEFINED
31// Exclude a method or class from wrapping
32#define VTK_WRAPEXCLUDE VTK_DEFINE_WRAP_HINT(vtk::wrapexclude)
33// Exclude a method or class from JavaScript wrapping
34#ifdef __EMSCRIPTEN__
35#define VTK_WRAPEXCLUDE_JAVASCRIPT VTK_WRAPEXCLUDE
36#else
37#define VTK_WRAPEXCLUDE_JAVASCRIPT
38#endif
39// Tell wrappers not to associate this method with any property.
40#define VTK_PROPEXCLUDE VTK_DEFINE_WRAP_HINT(vtk::propexclude)
41// The return value points to a newly-created VTK object.
42#define VTK_NEWINSTANCE VTK_DEFINE_WRAP_HINT(vtk::newinstance)
43// The parameter is a pointer to a zerocopy buffer.
44#define VTK_ZEROCOPY VTK_DEFINE_WRAP_HINT(vtk::zerocopy)
45// The parameter is a path on the filesystem.
46#define VTK_FILEPATH VTK_DEFINE_WRAP_HINT(vtk::filepath)
47// Release Python GIL for the duration of the call
48#define VTK_UNBLOCKTHREADS VTK_DEFINE_WRAP_HINT(vtk::unblockthreads)
49// Set preconditions for a function
50#define VTK_EXPECTS(x) VTK_DEFINE_WRAP_HINT_ARGS(vtk::expects, x)
51// Set size hint for parameter or return value
52#define VTK_SIZEHINT(...) VTK_DEFINE_WRAP_HINT_ARGS(vtk::sizehint, __VA_ARGS__)
53// Opt-in a class for automatic code generation of (de)serializers.
54#define VTK_MARSHALAUTO VTK_DEFINE_WRAP_HINT(vtk::marshalauto)
55// Specifies that a class has hand written (de)serializers.
56#define VTK_MARSHALMANUAL VTK_DEFINE_WRAP_HINT(vtk::marshalmanual)
57// Excludes a function from the auto-generated (de)serialization process.
58#define VTK_MARSHALEXCLUDE(reason) VTK_DEFINE_WRAP_HINT_ARGS(vtk::marshalexclude, reason)
59// Enforces a function as the getter for `property`
60#define VTK_MARSHALGETTER(property) VTK_DEFINE_WRAP_HINT_ARGS(vtk::marshalgetter, #property)
61// Enforces a function as the setter for `property`
62#define VTK_MARSHALSETTER(property) VTK_DEFINE_WRAP_HINT_ARGS(vtk::marshalsetter, #property)
63// The method may suspend execution (e.g. WebGPU/JSPI await), so wrappers that
64// support coroutines must invoke it asynchronously (return a Promise).
65#define VTK_MAYSUSPEND VTK_DEFINE_WRAP_HINT(vtk::maysuspend)
66#endif
67
68#ifndef VTK_WRAP_HINTS_DEFINED
69#define VTK_WRAPEXCLUDE
70#define VTK_WRAPEXCLUDE_JAVASCRIPT
71#define VTK_PROPEXCLUDE
72#define VTK_NEWINSTANCE
73#define VTK_ZEROCOPY
74#define VTK_FILEPATH
75#define VTK_UNBLOCKTHREADS
76#define VTK_EXPECTS(x)
77#define VTK_SIZEHINT(...)
78#define VTK_MARSHALAUTO
79#define VTK_MARSHALMANUAL
80#define VTK_MARSHALEXCLUDE(reason)
81#define VTK_MARSHALGETTER(property)
82#define VTK_MARSHALSETTER(property)
83#define VTK_MAYSUSPEND
84#endif
85
86#define VTK_MARSHAL_EXCLUDE_REASON_IS_REDUNDANT "is redundant"
87#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL "is internal"
88#define VTK_MARSHAL_EXCLUDE_REASON_NOT_SUPPORTED \
89 "(de)serialization is not supported for this type of property"
90
91#endif
92// VTK-HeaderTest-Exclude: vtkWrappingHints.h