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 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 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 #define UINT_ADD_SIZE(x,s,y) x ## s ## y
47 #define UINT_ADD_DEF_SIZE(x,s,y) UINT_ADD_SIZE(x,s,y)
48 #define UINT_SIZE(x,y) UINT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
49 
50 #if WM_LABEL_SIZE != 32 && WM_LABEL_SIZE != 64
51  #error "uLabel.H: WM_LABEL_SIZE must be set to either 32 or 64"
52 #endif
53 
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 typedef UINT_SIZE(uint, _t) uLabel;
63 
64 constexpr uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
65 
66 //- Read uLabel from stream.
67 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
69 {
70  return UINT_SIZE(readUint,) (is);
71 }
72 
73 //- Parse entire buffer as a uLabel, skipping leading/trailing whitespace.
74 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
75 // \return Parsed value or FatalIOError on any problem
76 inline uLabel readULabel(const char* buf)
77 {
78  return UINT_SIZE(readUint,) (buf);
79 }
80 
81 //- Parse entire string as a uLabel, skipping leading/trailing whitespace.
82 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
83 // \return Parsed value or FatalIOError on any problem
84 inline uLabel readULabel(const std::string& str)
85 {
86  return UINT_SIZE(readUint,) (str);
87 }
88 
89 //- Parse entire buffer as a uLabel, skipping leading/trailing whitespace.
90 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
91 // \return True if successful.
92 inline bool readULabel(const char* buf, uLabel& val)
93 {
94  return UINT_SIZE(readUint,) (buf, val);
95 }
96 
97 
98 //- Parse entire string as a uLabel, skipping leading/trailing whitespace.
99 // Uses readUint32 or readUint64 according to WM_LABEL_SIZE
100 // \return True if successful.
101 inline bool readULabel(const std::string& str, uLabel& val)
102 {
103  return UINT_SIZE(readUint,) (str, val);
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 //- Raise one uLabel to the power of another
110 uLabel pow(uLabel a, uLabel b);
111 
112 //- Evaluate n! : 0 < n <= 12
114 
115 
117 {
118  return l;
119 }
120 
121 inline uLabel component(const uLabel l, const direction)
122 {
123  return l;
124 }
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 } // End namespace Foam
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 #undef UINT_ADD_SIZE
133 #undef UINT_ADD_DEF_SIZE
134 #undef UINT_SIZE
135 
136 #endif
137 
138 // ************************************************************************* //
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:127
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
Foam::uLabelMax
constexpr uLabel uLabelMax
Definition: uLabel.H:64
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
uint.H
System unsigned integer.
UINT_SIZE
#define UINT_SIZE(x, y)
Definition: uLabel.H:48
Foam::readULabel
uLabel readULabel(Istream &is)
Read uLabel from stream.
Definition: uLabel.H:68
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::factorial
label factorial(label n)
Evaluate n! : 0 < n <= 12.
Definition: label.C:145
Foam::uLabel
uintWM_LABEL_SIZE_t uLabel
A uLabel is an uint32_t or uint64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: uLabel.H:62