TypeSet.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::TypeSet
26 
27 Description
28  Template meta-programming for operations involving sets of types
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef TypeSet_H
33 #define TypeSet_H
34 
35 #include "autoPtr.H"
36 #include "typeInfo.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 /*---------------------------------------------------------------------------*\
44  Class TypeSet Declaration
45 \*---------------------------------------------------------------------------*/
46 
47 template<class ... Types>
48 struct TypeSet;
49 
50 template<class Type, class ... Types>
51 struct TypeSet<Type, Types ...>
52 {
53  template<class OtherType>
54  static bool isAny(const OtherType& t)
55  {
56  return isA<Type>(t) || TypeSet<Types ...>::isAny(t);
57  }
58 
59  template<class OtherType>
60  static bool isAll(const OtherType& t)
61  {
62  return isA<Type>(t) && TypeSet<Types ...>::isAll(t);
63  }
64 
65  //- Clone into the first matching type, or return an empty pointer if a
66  // matching type is not in the set
67  template<class OtherType>
68  static autoPtr<OtherType> clone(const OtherType& t)
69  {
70  return
71  isA<Type>(t)
72  ? autoPtr<OtherType>(new Type(refCast<const Type>(t)))
74  }
75 };
76 
77 template<>
78 struct TypeSet<>
79 {
80  template<class OtherType>
81  static bool isAny(const OtherType&)
82  {
83  return false;
84  }
85 
86  template<class OtherType>
87  static bool isAll(const OtherType&)
88  {
89  return true;
90  }
91 
92  template<class OtherType>
93  static autoPtr<OtherType> clone(const OtherType&)
94  {
95  return autoPtr<OtherType>();
96  }
97 };
98 
99 
100 /*---------------------------------------------------------------------------*\
101  Class TypeSetContains Declaration
102 \*---------------------------------------------------------------------------*/
103 
104 template<class Set, class OtherType>
105 struct TypeSetContains;
106 
107 template<class Type, class ... Types, class OtherType>
108 struct TypeSetContains<TypeSet<Type, Types ...>, OtherType>
109 :
110  public TypeSetContains<TypeSet<Types ...>, OtherType>
111 {};
112 
113 template<class Type, class ... Types>
114 struct TypeSetContains<TypeSet<Type, Types ...>, Type>
115 :
116  public std::true_type
117 {};
118 
119 template<class OtherType>
120 struct TypeSetContains<TypeSet<>, OtherType>
121 :
122  public std::false_type
123 {};
124 
125 
126 /*---------------------------------------------------------------------------*\
127  Class TypeSetConcatenate Declaration
128 \*---------------------------------------------------------------------------*/
129 
130 template<class SetA, class SetB>
131 struct TypeSetConcatenate;
132 
133 template<class ... TypesA, class ... TypesB>
134 struct TypeSetConcatenate<TypeSet<TypesA ...>, TypeSet<TypesB ...>>
135 {
136  typedef TypeSet<TypesA ..., TypesB ...> type;
137 };
138 
139 
140 /*---------------------------------------------------------------------------*\
141  Class TypeSetRemove Declaration
142 \*---------------------------------------------------------------------------*/
143 
144 template<class Set, class RemoveSet>
145 struct TypeSetRemove;
146 
147 template<class Type, class ... Types, class RemoveSet>
148 struct TypeSetRemove<TypeSet<Type, Types ...>, RemoveSet>
149 {
150  typedef typename
151  TypeSetRemove<TypeSet<Types ...>, RemoveSet>::type
152  subType;
153 
154  typedef typename
155  std::conditional
156  <
158  subType,
160  >::type type;
161 };
162 
163 template<class RemoveSet>
164 struct TypeSetRemove<TypeSet<>, RemoveSet>
165 {
166  typedef TypeSet<> type;
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Foam
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #endif
177 
178 // ************************************************************************* //
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Namespace for OpenFOAM.
T clone(const T &t)
Definition: List.H:55
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
std::conditional< TypeSetContains< RemoveSet, Type >::value, subType, typename TypeSetConcatenate< TypeSet< Type >, subType >::type >::type type
Definition: TypeSet.H:159
TypeSetRemove< TypeSet< Types ... >, RemoveSet >::type subType
Definition: TypeSet.H:151
Template meta-programming for operations involving sets of types.
Definition: TypeSet.H:47
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...