VTK  9.3.20240327
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 
32 namespace vtk
33 {
34 namespace detail
35 {
36 VTK_ABI_NAMESPACE_BEGIN
37 
38 // Used by Inherits with ParentClasses to produce a list of inherited type names.
39 template <typename Container, typename StopAtType = void>
40 struct AddNames
41 {
42  AddNames(Container& c)
43  : m_container(c)
44  {
45  }
46 
47  template <typename T>
48  bool operator()()
49  {
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 
61 VTK_ABI_NAMESPACE_END
62 } // namespace detail
63 
64 VTK_ABI_NAMESPACE_BEGIN
66 
74 template <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 
90 public:
91  enum
92  {
93  value = sizeof(Test<VTKObjectType>(nullptr)) == sizeof(Yes)
94  };
95 };
97 
99 
117 
118 template <typename VTKObjectType>
119 struct ParentClasses<VTKObjectType, false>
120 {
121  template <typename Functor>
122  inline static void enumerate(Functor& ff)
123  {
124  ff.template operator()<VTKObjectType>();
125  }
126 };
127 
128 template <typename VTKObjectType>
129 struct 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
136  enumerate(Functor& ff)
137  {
138  ff.template operator()<VTKObjectType>();
140  }
141 
142  // This variant handles Functors with a bool return type.
143  template <typename Functor>
144  inline static typename std::enable_if<
145  std::is_same<decltype(std::declval<Functor>().template operator()<vtkObject>()), bool>::value,
146  void>::type
147  enumerate(Functor& ff)
148  {
149  if (ff.template operator()<VTKObjectType>())
150  {
152  }
153  }
154 };
156 
158 
169 template <typename VTKObjectType, typename Container>
170 void Inherits(Container& container)
171 {
172  detail::AddNames<Container> addNames(container);
174 }
175 
176 template <typename VTKObjectType, typename StopAtType, typename Container>
177 void Inherits(Container& container)
178 {
179  detail::AddNames<Container, StopAtType> addNames(container);
181 }
183 
184 VTK_ABI_NAMESPACE_END
185 } // namespace vtk
186 
187 #endif // vtkInherits_h
abstract base class for most VTK objects
Definition: vtkObject.h:161
Determine whether the provided class (VTKObjectType ) has a parent class.
Definition: vtkInherits.h:76
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
@ string
Definition: vtkX3D.h:490
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
void Inherits(Container &container)
Populate the container with the name of this class and its ancestors.
Definition: vtkInherits.h:170
static std::enable_if< std::is_same< decltype(std::declval< Functor >).template operator()<vtkObject >)), void >::value, void >::type enumerate(Functor &ff)
Definition: vtkInherits.h:136
static std::enable_if< std::is_same< decltype(std::declval< Functor >).template operator()<vtkObject >)), bool >::value, void >::type enumerate(Functor &ff)
Definition: vtkInherits.h:147
Invoke a functor on the named type and each of its parent types.
Definition: vtkInherits.h:116
Container & m_container
Definition: vtkInherits.h:58
AddNames(Container &c)
Definition: vtkInherits.h:42