VTK  9.4.20241108
vtkInherits.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 vtkInherits_h
5#define vtkInherits_h
6
7#include "vtkTypeName.h"
8
9#include <string>
10
11#define vtkInheritanceHierarchyBodyMacro(thisClass) \
12 { \
13 std::vector<vtkStringToken> result; \
14 vtk::Inherits<thisClass>(result); \
15 return result; \
16 }
17
22
23#define vtkInheritanceHierarchyBaseMacro(thisClass) \
24 virtual std::vector<vtkStringToken> InheritanceHierarchy() \
25 const vtkInheritanceHierarchyBodyMacro(thisClass)
26
27#define vtkInheritanceHierarchyOverrideMacro(thisClass) \
28 std::vector<vtkStringToken> InheritanceHierarchy() \
29 const override vtkInheritanceHierarchyBodyMacro(thisClass)
31
32namespace vtk
33{
34namespace detail
35{
36VTK_ABI_NAMESPACE_BEGIN
37
38// Used by Inherits with ParentClasses to produce a list of inherited type names.
39template <typename Container, typename StopAtType = void>
41{
42 AddNames(Container& c)
43 : m_container(c)
44 {
45 }
46
47 template <typename T>
49 {
50 if (!std::is_same<StopAtType, T>::value)
51 {
52 std::string typeName = vtk::TypeName<T>();
53 m_container.insert(m_container.end(), typeName);
54 return true;
55 }
56 return false;
57 }
58 Container& m_container;
59};
60
61VTK_ABI_NAMESPACE_END
62} // namespace detail
63
64VTK_ABI_NAMESPACE_BEGIN
66
74template <typename VTKObjectType>
76{
77 class No
78 {
79 };
80 class Yes
81 {
82 No no[2];
83 };
84
85 template <typename C>
86 static Yes Test(typename C::Superclass*);
87 template <typename C>
88 static No Test(...);
89
90public:
91 enum
92 {
93 value = sizeof(Test<VTKObjectType>(nullptr)) == sizeof(Yes)
94 };
95};
97
99
115template <typename VTKObjectType, bool IsDerived = HasSuperclass<VTKObjectType>::value>
117
118template <typename VTKObjectType>
119struct ParentClasses<VTKObjectType, false>
120{
121 template <typename Functor>
122 inline static void enumerate(Functor& ff)
123 {
124 ff.template operator()<VTKObjectType>();
125 }
126};
127
128template <typename VTKObjectType>
129struct ParentClasses<VTKObjectType, true>
130{
131 // This variant handles Functors with a void return type.
132 template <typename Functor>
133 inline static typename std::enable_if<
134 std::is_same<decltype(std::declval<Functor>().template operator()<vtkObject>()), void>::value,
135 void>::type enumerate(Functor& ff)
136 {
137 ff.template operator()<VTKObjectType>();
139 }
140
141 // This variant handles Functors with a bool return type.
142 template <typename Functor>
143 inline static typename std::enable_if<
144 std::is_same<decltype(std::declval<Functor>().template operator()<vtkObject>()), bool>::value,
145 void>::type enumerate(Functor& ff)
146 {
147 if (ff.template operator()<VTKObjectType>())
148 {
150 }
151 }
152};
154
156
167template <typename VTKObjectType, typename Container>
168void Inherits(Container& container)
169{
170 detail::AddNames<Container> addNames(container);
172}
173
174template <typename VTKObjectType, typename StopAtType, typename Container>
175void Inherits(Container& container)
176{
177 detail::AddNames<Container, StopAtType> addNames(container);
179}
181
182VTK_ABI_NAMESPACE_END
183} // namespace vtk
184
185#endif // vtkInherits_h
abstract base class for most VTK objects
Definition vtkObject.h:162
Determine whether the provided class (VTKObjectType ) has a parent class.
Definition vtkInherits.h:76
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
void Inherits(Container &container)
Populate the container with the name of this class and its ancestors.
static void ::type enumerate(Functor &ff)
Invoke a functor on the named type and each of its parent types.
Container & m_container
Definition vtkInherits.h:58
AddNames(Container &c)
Definition vtkInherits.h:42