label.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Typedef
25  Foam::label
26 
27 Description
28  A label is an int32_t or int64_t as specified by the pre-processor macro
29  WM_LABEL_SIZE.
30 
31  A readLabel function is defined so that label can be constructed from
32  Istream.
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef label_H
37 #define label_H
38 
39 #include "int.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 #define INT_ADD_SIZE(x,s,y) x ## s ## y
44 #define INT_ADD_DEF_SIZE(x,s,y) INT_ADD_SIZE(x,s,y)
45 #define INT_SIZE(x,y) INT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
46 
47 #if WM_LABEL_SIZE != 32 && WM_LABEL_SIZE != 64
48  #error "label.H: WM_LABEL_SIZE must be set to either 32 or 64"
49 #endif
50 
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 typedef INT_SIZE(int, _t) label;
60 
61 static const label labelMin = INT_SIZE(INT, _MIN);
62 static const label labelMax = INT_SIZE(INT, _MAX);
63 
64 inline label readLabel(Istream& is)
65 {
66  return INT_SIZE(readInt,) (is);
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 //- Raise one label to the power of another
73 label pow(label a, label b);
74 
75 //- Return n! : 0 < n <= 12
76 label factorial(label n);
77 
78 //- Return the log base 2 by successive bit-shifting of the given label
79 inline label log2(label i)
80 {
81  label log2i = 0;
82  while (i >>= 1) log2i++;
83  return log2i;
84 }
85 
86 inline label& setComponent(label& l, const direction)
87 {
88  return l;
89 }
90 
91 inline label component(const label l, const direction)
92 {
93  return l;
94 }
95 
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 
98 } // End namespace Foam
99 
100 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101 
102 #include "labelSpecific.H"
103 
104 #undef INT_ADD_SIZE
105 #undef INT_ADD_DEF_SIZE
106 #undef INT_SIZE
107 
108 #endif
109 
110 // ************************************************************************* //
System integer.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
int readInt(Istream &)
Definition: intIO.C:31
label log2(label i)
Return the log base 2 by successive bit-shifting of the given label.
Definition: label.H:79
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
label factorial(label n)
Return n! : 0 < n <= 12.
Definition: label.C:63
static const label labelMax
Definition: label.H:62
label readLabel(Istream &is)
Definition: label.H:64
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
label n
label & setComponent(label &l, const direction)
Definition: label.H:86
#define INT_SIZE(x, y)
Definition: label.H:45
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
static const label labelMin
Definition: label.H:61
Namespace for OpenFOAM.