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 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 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
31 
33 Foam::expressions::valueTypeCodeOf(const word& dataTypeName)
34 {
35  #undef stringToTypeCode
36  #define stringToTypeCode(Type) \
37  \
38  if (dataTypeName == exprTypeTraits<Type>::name) \
39  { \
40  return expressions::valueTypeCode::type_##Type; \
41  }
42 
43  if (!dataTypeName.empty())
44  {
45  stringToTypeCode(bool);
46  stringToTypeCode(label);
47  stringToTypeCode(scalar);
52  }
53  #undef stringToTypeCode
54 
55  return expressions::valueTypeCode::INVALID;
56 }
57 
58 
60 {
61  #undef case_typeCodeToString
62  #define case_typeCodeToString(Type) \
63  \
64  case expressions::valueTypeCode::type_##Type : \
65  { \
66  return exprTypeTraits<Type>::name; \
67  }
68 
69  switch (typeCode)
70  {
71  case expressions::valueTypeCode::NONE :
72  {
73  return "none";
74  }
75 
76  case expressions::valueTypeCode::INVALID :
77  {
78  // ie, ""
79  break;
80  }
81 
83  case_typeCodeToString(label);
84  case_typeCodeToString(scalar);
89  }
90  #undef case_typeCodeToString
91 
92  return word();
93 }
94 
95 
96 // ************************************************************************* //
Tensor< scalar > tensor
Definition: symmTensor.H:57
#define case_typeCodeToString(Type)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:55
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:62
Vector< scalar > vector
Definition: vector.H:57
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
valueTypeCode valueTypeCodeOf(const word &dataTypeName)
From string to valueTypeCode (if any)
Definition: exprTraits.C:26
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
#define stringToTypeCode(Type)
Tensor of scalars, i.e. Tensor<scalar>.