uLabel.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Typedef
28  Foam::uLabel
29 
30 Description
31  A uLabel is an uint32_t or uint64_t as specified by the pre-processor macro
32  WM_LABEL_SIZE.
33 
34  A readULabel function is defined so that uLabel can be constructed from
35  Istream.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef uLabel_H
40 #define uLabel_H
41 
42 #include "uint.H"
43 #include "labelFwd.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 #define UINT_ADD_SIZE(x,s,y) x ## s ## y
48 #define UINT_ADD_DEF_SIZE(x,s,y) UINT_ADD_SIZE(x,s,y)
49 #define UINT_SIZE(x,y) UINT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
50 
51 // Size checks and typedefs (uLabel) in labelFwd.H
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 constexpr uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
61 
62 //- Read uLabel from stream.
63 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
64 inline uLabel readULabel(Istream& is)
65 {
66  return UINT_SIZE(readUint,) (is);
67 }
68 
69 //- Parse entire buffer as a uLabel, skipping leading/trailing whitespace.
70 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
71 // \return Parsed value or FatalIOError on any problem
72 inline uLabel readULabel(const char* buf)
73 {
74  return UINT_SIZE(readUint,) (buf);
75 }
76 
77 //- Parse entire string as a uLabel, skipping leading/trailing whitespace.
78 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
79 // \return Parsed value or FatalIOError on any problem
80 inline uLabel readULabel(const std::string& str)
81 {
82  return UINT_SIZE(readUint,) (str);
83 }
84 
85 //- Parse entire buffer as a uLabel, skipping leading/trailing whitespace.
86 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
87 // \return True if successful.
88 inline bool readULabel(const char* buf, uLabel& val)
89 {
90  return UINT_SIZE(readUint,) (buf, val);
91 }
92 
93 
94 //- Parse entire string as a uLabel, skipping leading/trailing whitespace.
95 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
96 // \return True if successful.
97 inline bool readULabel(const std::string& str, uLabel& val)
98 {
99  return UINT_SIZE(readUint,) (str, val);
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
105 //- Raise one uLabel to the power of another
106 uLabel pow(uLabel a, uLabel b);
107 
108 //- Evaluate n! : 0 < n <= 12
109 uLabel factorial(uLabel n);
110 
111 
112 inline uLabel& setComponent(uLabel& l, const direction)
113 {
114  return l;
115 }
116 
117 inline uLabel component(const uLabel l, const direction)
118 {
119  return l;
120 }
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 } // End namespace Foam
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 #undef UINT_ADD_SIZE
129 #undef UINT_ADD_DEF_SIZE
130 #undef UINT_SIZE
131 
132 #endif
133 
134 // ************************************************************************* //
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:123
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::readUint
unsigned int readUint(Istream &is)
Read unsigned int from stream.
Definition: uintIO.C:33
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:75
labelFwd.H
Typedefs for label/uLabel without requiring label.H.
Foam::uLabelMax
constexpr uLabel uLabelMax
Definition: uLabel.H:60
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
uint.H
System unsigned integer.
UINT_SIZE
#define UINT_SIZE(x, y)
Definition: uLabel.H:49
Foam::readULabel
uLabel readULabel(Istream &is)
Read uLabel from stream.
Definition: uLabel.H:64
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::factorial
label factorial(label n)
Evaluate n! : 0 < n <= 12.
Definition: label.C:145