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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::exprTypeTraits
28 
29 Description
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 
51 namespace Foam
52 {
53 namespace 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
65 
66 enum class valueTypeCode : unsigned char
67 {
68  NONE = 0,
69  INVALID,
70 
71  // Rank 0 types
72  type_bool,
73  type_label,
74  type_scalar,
75 
76  // Rank 1 types
77  type_vector,
78 
79  // Rank 2 types
83 };
84 
85 
86 // Global Functions
87 
88 //- From string to valueTypeCode (if any)
89 valueTypeCode 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)
101 template<class Type>
102 struct exprTypeTraits
103 {
104  typedef Type value_type;
105  static constexpr const char* const name = "";
106  static constexpr
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
127 defineExprTypeTraits(::Foam::label, label);
128 defineExprTypeTraits(::Foam::scalar, scalar);
133 
134 #undef defineExprTypeTraits
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 //- A word representation of a valueTypeCode. Empty for INVALID
139 word name(const expressions::valueTypeCode typeCode);
140 
141 
142 //- A word representation of a valueTypeCode. Empty for INVALID
143 template<>
144 struct nameOp<expressions::valueTypeCode>
145 {
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 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::expressions::valueTypeCode::INVALID
Invalid/unknown/error type.
Foam::SymmTensor< scalar >
Foam::expressions::valueTypeCode::NONE
No type, or default initialized type.
Foam::expressions::valueTypeCode::type_symmTensor
Type is 'symmTensor'.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::expressions::valueTypeCode::type_scalar
Type is 'scalar'.
Foam::expressions::valueTypeCode::type_tensor
Type is 'tensor'.
tensor.H
sphericalTensor.H
Foam::expressions::valueTypeCode
valueTypeCode
An enumeration of known and expected expression value types.
Definition: exprTraits.H:65
symmTensor.H
Foam::nameOp
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:237
Foam::expressions::valueTypeCode::type_sphericalTensor
Type is 'sphericalTensor'.
Foam::nameOp::operator()
word operator()(const T &obj) const
Definition: word.H:239
scalar.H
Foam::nameOp< expressions::valueTypeCode >::operator()
word operator()(const expressions::valueTypeCode typeCode) const
Definition: exprTraits.H:145
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exprTypeTraits::name
static constexpr const char *const name
Definition: exprTraits.H:104
Foam::SphericalTensor< scalar >
Foam::exprTypeTraits::value_type
Type value_type
Definition: exprTraits.H:103
Foam::expressions::valueTypeCode::type_vector
Type is 'vector'.
Foam::expressions::valueTypeCodeOf
valueTypeCode valueTypeCodeOf(const word &dataTypeName)
From string to valueTypeCode (if any)
Definition: exprTraits.C:33
Foam::exprTypeTraits::value
static constexpr ::Foam::expressions::valueTypeCode value
Definition: exprTraits.H:106
Foam::expressions::valueTypeCode::type_bool
Type is 'bool'.
Foam::Vector< scalar >
defineExprTypeTraits
#define defineExprTypeTraits(Type, Name)
Definition: exprTraits.H:112
label.H
Foam::exprTypeTraits
Simple type identifiers for polymorphic expression values.
Definition: exprTraits.H:101
vector.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
word.H
Foam::expressions::valueTypeCode::type_label
Type is 'label'.