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
11namespace vtk
12{
13namespace detail
14{
15VTK_ABI_NAMESPACE_BEGIN
16
17// Used by Inherits with ParentClasses to produce a list of inherited type names.
18template <typename Container, typename StopAtType = void>
20{
21 AddNames(Container& c)
22 : m_container(c)
23 {
24 }
25
26 template <typename T>
28 {
29 if (!std::is_same<StopAtType, T>::value)
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
40VTK_ABI_NAMESPACE_END
41} // namespace detail
42
43VTK_ABI_NAMESPACE_BEGIN
45
53template <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
69public:
70 enum
71 {
72 value = sizeof(Test<VTKObjectType>(nullptr)) == sizeof(Yes)
73 };
74};
76
78
94template <typename VTKObjectType, bool IsDerived = HasSuperclass<VTKObjectType>::value>
96
97template <typename VTKObjectType>
98struct ParentClasses<VTKObjectType, false>
99{
100 template <typename Functor>
101 inline static void enumerate(Functor& ff)
102 {
103 ff.template operator()<VTKObjectType>();
104 }
105};
106
107template <typename VTKObjectType>
108struct 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
148template <typename VTKObjectType, typename Container>
149void Inherits(Container& container)
150{
151 detail::AddNames<Container> addNames(container);
153}
154
155template <typename VTKObjectType, typename StopAtType, typename Container>
156void Inherits(Container& container)
157{
158 detail::AddNames<Container, StopAtType> addNames(container);
160}
162
163VTK_ABI_NAMESPACE_END
164} // namespace vtk
165
166#endif // vtkInherits_h
abstract base class for most VTK objects
Definition vtkObject.h:49
Determine whether the provided class (VTKObjectType ) has a parent class.
Definition vtkInherits.h:55
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.
Definition vtkInherits.h:95
Container & m_container
Definition vtkInherits.h:37
AddNames(Container &c)
Definition vtkInherits.h:21