VTK  9.3.0
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 namespace vtk
12 {
13 namespace detail
14 {
15 VTK_ABI_NAMESPACE_BEGIN
16 
17 // Used by Inherits with ParentClasses to produce a list of inherited type names.
18 template <typename Container, typename StopAtType = void>
19 struct AddNames
20 {
21  AddNames(Container& c)
22  : m_container(c)
23  {
24  }
25 
26  template <typename T>
27  bool operator()()
28  {
30  {
31  std::string typeName = vtk::TypeName<T>();
32  m_container.insert(m_container.end(), typeName);
33  return true;
34  }
35  return false;
36  }
37  Container& m_container;
38 };
39 
40 VTK_ABI_NAMESPACE_END
41 } // namespace detail
42 
43 VTK_ABI_NAMESPACE_BEGIN
45 
53 template <typename VTKObjectType>
55 {
56  class No
57  {
58  };
59  class Yes
60  {
61  No no[2];
62  };
63 
64  template <typename C>
65  static Yes Test(typename C::Superclass*);
66  template <typename C>
67  static No Test(...);
68 
69 public:
70  enum
71  {
72  value = sizeof(Test<VTKObjectType>(nullptr)) == sizeof(Yes)
73  };
74 };
76 
78 
96 
97 template <typename VTKObjectType>
98 struct ParentClasses<VTKObjectType, false>
99 {
100  template <typename Functor>
101  inline static void enumerate(Functor& ff)
102  {
103  ff.template operator()<VTKObjectType>();
104  }
105 };
106 
107 template <typename VTKObjectType>
108 struct ParentClasses<VTKObjectType, true>
109 {
110  // This variant handles Functors with a void return type.
111  template <typename Functor>
112  inline static typename std::enable_if<
113  std::is_same<decltype(std::declval<Functor>().template operator()<vtkObject>()), void>::value,
114  void>::type
115  enumerate(Functor& ff)
116  {
117  ff.template operator()<VTKObjectType>();
119  }
120 
121  // This variant handles Functors with a bool return type.
122  template <typename Functor>
123  inline static typename std::enable_if<
124  std::is_same<decltype(std::declval<Functor>().template operator()<vtkObject>()), bool>::value,
125  void>::type
126  enumerate(Functor& ff)
127  {
128  if (ff.template operator()<VTKObjectType>())
129  {
131  }
132  }
133 };
135 
137 
148 template <typename VTKObjectType, typename Container>
149 void Inherits(Container& container)
150 {
151  detail::AddNames<Container> addNames(container);
153 }
154 
155 template <typename VTKObjectType, typename StopAtType, typename Container>
156 void Inherits(Container& container)
157 {
158  detail::AddNames<Container, StopAtType> addNames(container);
160 }
162 
163 VTK_ABI_NAMESPACE_END
164 } // namespace vtk
165 
166 #endif // vtkInherits_h
abstract base class for most VTK objects
Definition: vtkObject.h:61
Determine whether the provided class (VTKObjectType ) has a parent class.
Definition: vtkInherits.h:55
@ 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:149
static std::enable_if< std::is_same< decltype(std::declval< Functor >).template operator()<vtkObject >)), void >::value, void >::type enumerate(Functor &ff)
Definition: vtkInherits.h:115
static std::enable_if< std::is_same< decltype(std::declval< Functor >).template operator()<vtkObject >)), bool >::value, void >::type enumerate(Functor &ff)
Definition: vtkInherits.h:126
Invoke a functor on the named type and each of its parent types.
Definition: vtkInherits.h:95
Container & m_container
Definition: vtkInherits.h:37
AddNames(Container &c)
Definition: vtkInherits.h:21