forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkTypeList.h
170 lines (145 loc) · 5.55 KB
/
vtkTypeList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTypeList.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The author or Addison-Wesley Longman make no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
/**
* @class vtkTypeList
* @brief TypeList implementation and utilities.
*
*
* vtkTypeList provides a way to collect a list of types using C++ templates.
* In VTK, this is used heavily by the vtkArrayDispatch system to instantiate
* templated code for specific array implementations. The book "Modern C++
* Design: Generic Programming and Design Patterns Applied" by Andrei
* Alexandrescu provides additional details and applications for typeLists. This
* implementation is heavily influenced by the example code in the book.
*
* Note that creating a typelist in C++ is simplified greatly by using the
* vtkTypeList_Create_N macros defined in the CMake-generated
* vtkTypeListMacros.h header.
*
* @sa
* vtkArrayDispatch vtkTypeListMacros
*/
#ifndef vtkTypeList_h
#define vtkTypeList_h
#include "vtkTypeListMacros.h"
namespace vtkTypeList
{
//------------------------------------------------------------------------------
/**
* Used to terminate a TypeList.
*/
struct NullType {};
//------------------------------------------------------------------------------
//@{
/**
* Generic implementation of TypeList.
*/
template <typename T, typename U>
struct TypeList
{
typedef T Head;
typedef U Tail;
};
//@}
//------------------------------------------------------------------------------
/**
* Sets Result to T if Exp is true, or F if Exp is false.
*/
template <bool Exp, typename T, typename F>
struct Select;
//------------------------------------------------------------------------------
/**
* Sets member Result to true if a conversion exists to convert type From to
* type To. Member SameType will be true if the types are identical.
*/
template <typename From, typename To>
struct CanConvert;
//------------------------------------------------------------------------------
/**
* Sets the enum value Result to the index of type T in the TypeList TList.
* Result will equal -1 if the type is not found.
*/
template <typename TList, typename T>
struct IndexOf;
//------------------------------------------------------------------------------
/**
* Erase the first element of type T from TypeList TList, storing the new list
* in Result.
*/
template <typename TList, typename T>
struct Erase;
//------------------------------------------------------------------------------
/**
* Erase all type T from TypeList TList, storing the new list in Result.
*/
template <typename TList, typename T>
struct EraseAll;
//------------------------------------------------------------------------------
/**
* Remove all duplicate types from TypeList TList, storing the new list in
* Result.
*/
template <typename TList>
struct Unique;
//------------------------------------------------------------------------------
/**
* Replace the first instance of Bad with Good in the TypeList TList, storing
* the new list in Result.
*/
template <typename TList, typename Bad, typename Good>
struct Replace;
//------------------------------------------------------------------------------
/**
* Replace all instances of Bad with Good in the TypeList TList, storing the
* new list in Result.
*/
template <typename TList, typename Bad, typename Good>
struct ReplaceAll;
//------------------------------------------------------------------------------
/**
* Given a type T and a TypeList TList, store the most derived type of T in
* TList as Result. If no subclasses of T exist in TList, T will be set as
* Result, even if T itself is not in TList.
*/
template <typename TList, typename T>
struct MostDerived;
//------------------------------------------------------------------------------
/**
* Sort the TypeList from most-derived to least-derived type, storing the
* sorted TypeList in Result. Note that the input TypeList cannot have duplicate
* types (see Unique).
*/
template <typename TList>
struct DerivedToFront;
//------------------------------------------------------------------------------
/**
* Appends type T to TypeList TList and stores the result in Result.
*/
template <typename TList, typename T>
struct Append;
} // end namespace vtkTypeList
#include "vtkTypeList.txx"
#endif // vtkTypeList_h
// VTK-HeaderTest-Exclude: vtkTypeList.h