exprTraits.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::exprTypeTraits
28
29Description
30 Simple type identifiers for polymorphic expression values.
31
32 The definitions are similar to std::integral_constant in that they
33 provide value, value_type (and name).
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef expressions_exprTraits_H
38#define expressions_exprTraits_H
39
40// Regular field types
41#include "label.H"
42#include "scalar.H"
43#include "vector.H"
44#include "sphericalTensor.H"
45#include "symmTensor.H"
46#include "tensor.H"
47#include "word.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53namespace expressions
54{
55
56//- An enumeration of known and expected expression value types.
57// Do not rely on the enumeration values for any direct coding.
58//
59// \note NONE use used when initializing types, whereas INVALID is used
60// for unsupported types (never as a stored type).
61// This avoids false positives when testing.
62//
63// Except NONE and INVALID, the enumerations will mostly not be used
64// directly, but through exprTypeTraits :: value
66enum class valueTypeCode : unsigned char
67{
68 NONE = 0,
69 INVALID,
70
71 // Rank 0 types
72 type_bool,
75
76 // Rank 1 types
78
79 // Rank 2 types
83};
84
85
86// Global Functions
87
88//- From string to valueTypeCode (if any)
89valueTypeCode valueTypeCodeOf(const word& dataTypeName);
90
91// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92
93} // End namespace expressions
94
95
96/*---------------------------------------------------------------------------*\
97 Class exprTypeTraits Declaration
98\*---------------------------------------------------------------------------*/
99
100// Generic enumerated traits is INVALID (unknown)
101template<class Type>
102struct exprTypeTraits
104 typedef Type value_type;
105 static constexpr const char* const name = "";
106 static constexpr
107 ::Foam::expressions::valueTypeCode value =
109};
110
111
112#undef defineExprTypeTraits
113#define defineExprTypeTraits(Type, Name) \
114 template<> \
115 struct exprTypeTraits<Type> \
116 { \
117 typedef Type value_type; \
118 static constexpr const char* const name = #Name; \
119 static constexpr \
120 ::Foam::expressions::valueTypeCode value = \
121 ::Foam::expressions::valueTypeCode::type_##Name; \
122 };
123
124
125// Define with "name" to match regular pTraits typeName
127defineExprTypeTraits(::Foam::label, label);
128defineExprTypeTraits(::Foam::scalar, scalar);
133
134#undef defineExprTypeTraits
135
136// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137
138//- A word representation of a valueTypeCode. Empty for INVALID
139word name(const expressions::valueTypeCode typeCode);
140
141
142//- A word representation of a valueTypeCode. Empty for INVALID
143template<>
144struct nameOp<expressions::valueTypeCode>
146 word operator()(const expressions::valueTypeCode typeCode) const
147 {
148 return Foam::name(typeCode);
149 }
150};
151
152// No IOstream Operators for valueTypeCode at the moment (Nov 2021)
153
154} // End namespace Foam
155
156// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157
158#endif
159
160// ************************************************************************* //
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineExprTypeTraits(Type, Name)
Definition: exprTraits.H:112
valueTypeCode
An enumeration of known and expected expression value types.
Definition: exprTraits.H:66
@ type_sphericalTensor
Type is 'sphericalTensor'.
@ type_symmTensor
Type is 'symmTensor'.
@ type_scalar
Type is 'scalar'.
@ type_vector
Type is 'vector'.
@ NONE
No type, or default initialized type.
@ INVALID
Invalid/unknown/error type.
@ type_tensor
Type is 'tensor'.
valueTypeCode valueTypeCodeOf(const word &dataTypeName)
From string to valueTypeCode (if any)
Definition: exprTraits.C:33
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Simple type identifiers for polymorphic expression values.
Definition: exprTraits.H:102
static constexpr const char *const name
Definition: exprTraits.H:104
static constexpr::Foam::expressions::valueTypeCode value
Definition: exprTraits.H:106
word operator()(const expressions::valueTypeCode typeCode) const
Definition: exprTraits.H:145
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:238
word operator()(const T &obj) const
Definition: word.H:239