VTK  9.7.1
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)
30 
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  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  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  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 
167 template <typename VTKObjectType, typename Container>
168 void Inherits(Container& container)
169 {
170  detail::AddNames<Container> addNames(container);
172 }
173 
174 template <typename VTKObjectType, typename StopAtType, typename Container>
175 void Inherits(Container& container)
176 {
177  detail::AddNames<Container, StopAtType> addNames(container);
179 }
181 
182 VTK_ABI_NAMESPACE_END
183 } // namespace vtk
184 
185 #endif // vtkInherits_h
abstract base class for most VTK objects
Definition: vtkObject.h:52
Container & m_container
Definition: vtkInherits.h:58
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
static std::enable_if< std::is_same< decltype(std::declval< Functor >).template operator()< vtkObject >)), bool >::value, void >::type enumerate(Functor &ff)
Definition: vtkInherits.h:145
AddNames(Container &c)
Definition: vtkInherits.h:42
Determine whether the provided class (VTKObjectType ) has a parent class.
Definition: vtkInherits.h:75
static std::enable_if< std::is_same< decltype(std::declval< Functor >).template operator()< vtkObject >)), void >::value, void >::type enumerate(Functor &ff)
Definition: vtkInherits.h:135
Invoke a functor on the named type and each of its parent types.
Definition: vtkInherits.h:116
void Inherits(Container &container)
Populate the container with the name of this class and its ancestors.
Definition: vtkInherits.h:168