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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Typedef
28 Foam::uLabel
29
30Description
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 Foam_primitives_uLabel_H
40#define Foam_primitives_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
55namespace Foam
56{
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59
60constexpr uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
61
62//- Read uLabel from stream.
63// Uses readUint32 or readUint64 according to WM_LABEL_SIZE
64inline 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
72inline 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
80inline 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.
88inline 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.
97inline 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
106uLabel pow(uLabel a, uLabel b);
107
108//- Evaluate n! : 0 < n <= 12
109uLabel factorial(uLabel n);
110
111
112//- Non-const access to unsigned-type (has no components)
113inline uLabel& setComponent(uLabel& val, const direction) noexcept
114{
115 return val;
116}
117
118
119//- Return unsigned value (has no components)
120inline constexpr uLabel component(const uLabel val, const direction) noexcept
121{
122 return val;
123}
124
125// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126
127} // End namespace Foam
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130
131#undef UINT_ADD_SIZE
132#undef UINT_ADD_DEF_SIZE
133#undef UINT_SIZE
134
135#endif
136
137// ************************************************************************* //
label n
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Typedefs for label/uLabel without requiring label.H.
Namespace for OpenFOAM.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
unsigned int readUint(Istream &is)
Read unsigned int from stream.
Definition: uintIO.C:33
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
Definition: label.H:123
constexpr uLabel uLabelMax
Definition: uLabel.H:60
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
uint8_t direction
Definition: direction.H:56
label factorial(label n)
Evaluate n! : 0 < n <= 12.
Definition: label.C:145
uLabel readULabel(Istream &is)
Read uLabel from stream.
Definition: uLabel.H:64
volScalarField & b
Definition: createFields.H:27
#define UINT_SIZE(x, y)
Definition: uLabel.H:49
System unsigned integer.