exprTraits.C
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-2023 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 \*---------------------------------------------------------------------------*/
27 
28 #include "exprTraits.H"
29 
30 //TBD: handle complex?
31 
32 #undef FOR_ALL_EXPR_TYPE_CODES
33 #define FOR_ALL_EXPR_TYPE_CODES(Macro, ...) \
34  Macro(bool, __VA_ARGS__) \
35  Macro(label, __VA_ARGS__) \
36  Macro(scalar, __VA_ARGS__) \
37  Macro(vector, __VA_ARGS__) \
38  Macro(sphericalTensor, __VA_ARGS__) \
39  Macro(symmTensor, __VA_ARGS__) \
40  Macro(tensor, __VA_ARGS__)
41 
42 
43 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
44 
47 (
48  const expressions::valueTypeCode typeCode
49 ) noexcept
50 {
51  switch (typeCode)
52  {
53  case expressions::valueTypeCode::NONE :
54  case expressions::valueTypeCode::INVALID :
55  {
56  break;
57  }
58 
59  #undef doLocalCode
60  #define doLocalCode(Type, UnusedParam) \
61  \
62  case expressions::valueTypeCode::type_##Type : \
63  { \
64  return exprTypeTraits<Type>::nComponents; \
65  }
66 
68  #undef doLocalCode
69  }
70 
71  return 0;
72 }
73 
74 
77 (
78  const expressions::valueTypeCode typeCode
79 ) noexcept
80 {
81  switch (typeCode)
82  {
83  case expressions::valueTypeCode::NONE :
84  case expressions::valueTypeCode::INVALID :
85  {
86  break;
87  }
88 
89  #undef doLocalCode
90  #define doLocalCode(Type, UnusedParam) \
91  \
92  case expressions::valueTypeCode::type_##Type : \
93  { \
94  return exprTypeTraits<Type>::rank; \
95  }
96 
98  #undef doLocalCode
99  }
101  return 0;
102 }
103 
104 
107 (
108  const word& dataTypeName,
109  const expressions::valueTypeCode deflt
110 )
111 {
112  if (!dataTypeName.empty())
113  {
114  // Could compare with pTraits<Type>::typeName instead of
115  // exprTypeTraits<Type>::name, but then we might miss
116  // possible typos.
117 
118  #undef doLocalCode
119  #define doLocalCode(Type, UnusedParam) \
120  \
121  if (dataTypeName == exprTypeTraits<Type>::name) \
122  { \
123  return expressions::valueTypeCode::type_##Type; \
124  }
125 
127  #undef doLocalCode
128  }
129 
130  return deflt;
131 }
132 
133 
135 {
136  switch (typeCode)
137  {
138  case expressions::valueTypeCode::NONE :
139  {
140  return "none";
141  }
142 
143  case expressions::valueTypeCode::INVALID :
144  {
145  // returns "", could also return "bad"
146  break;
147  }
148 
149  #undef doLocalCode
150  #define doLocalCode(Type, UnusedParam) \
151  case expressions::valueTypeCode::type_##Type : \
152  { \
153  return exprTypeTraits<Type>::name; \
154  }
155 
157  #undef doLocalCode
158  }
159 
160  return word();
161 }
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #undef FOR_ALL_EXPR_TYPE_CODES
167 
168 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
valueTypeCode
An enumeration of known and expected expression value types.
Definition: exprTraits.H:81
valueTypeCode valueTypeCodeOf(const word &dataTypeName, const expressions::valueTypeCode deflt=expressions::valueTypeCode::INVALID)
From string to valueTypeCode (if any)
Definition: exprTraits.C:100
const direction noexcept
Definition: Scalar.H:258
#define FOR_ALL_EXPR_TYPE_CODES(Macro,...)
Definition: exprTraits.C:26
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
#define doLocalCode(Type, UnusedParam)