1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 A label is an int/long/long long depending on the range desired.
30 A readLabel function is defined so that label can be constructed from
33 \*---------------------------------------------------------------------------*/
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 # define FOAM_LABEL_MAX 9000000000000000000
47 # define FOAM_LABEL_MAX 2000000000
51 #if INT_MAX > FOAM_LABEL_MAX
53 // Define label as an int
55 # undef FOAM_LABEL_MAX
56 # define FOAM_LABEL_MAX INT_MAX
60 # include "longLong.H"
66 static const label labelMin = INT_MIN;
67 static const label labelMax = INT_MAX;
69 inline label readLabel(Istream& is)
74 } // End namespace Foam
77 #elif LONG_MAX > FOAM_LABEL_MAX
78 // Define label as a long
80 # undef FOAM_LABEL_MAX
81 # define FOAM_LABEL_MAX LONG_MAX
90 static const label labelMin = LONG_MIN;
91 static const label labelMax = LONG_MAX;
93 inline label readLabel(Istream& is)
98 } // End namespace Foam
101 #elif LLONG_MAX > FOAM_LABEL_MAX
103 // Define label as a long long
105 # undef FOAM_LABEL_MAX
106 # define FOAM_LABEL_MAX LLONG_MAX
110 # include "longLong.H"
114 typedef long long label;
116 static const label labelMin = LLONG_MIN;
117 static const label labelMax = LLONG_MAX;
119 inline label readLabel(Istream& is)
121 return readLongLong(is);
124 } // End namespace Foam
128 #error "Undefined size for label in label.H"
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 #include "direction.H"
142 //- template specialization for pTraits<label>
151 typedef label cmptType;
157 dim = 3, // Dimensionality of space
158 rank = 0, // Rank of label is 0
159 nComponents = 1 // Number of components in label is 1
163 // Static data members
165 static const char* const typeName;
166 static const char* componentNames[];
167 static const label zero;
168 static const label one;
169 static const label min;
170 static const label max;
175 //- Construct from label
176 pTraits(const label l)
181 //- Construct from Istream
187 operator label() const
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 //- Raise one label to the power of another
202 label pow(label a, label b);
204 //- Evaluate n! : n <= 12
205 label factorial(label n);
208 #define MAXMIN(retType, type1, type2) \
210 inline retType max(const type1 s1, const type2 s2) \
212 return (s1 > s2)? s1: s2; \
215 inline retType min(const type1 s1, const type2 s2) \
217 return (s1 < s2)? s1: s2; \
221 MAXMIN(char, char, char)
222 MAXMIN(short, short, short)
223 MAXMIN(int, int, int)
224 MAXMIN(long, long, long)
225 MAXMIN(long long, long long, long long)
227 MAXMIN(unsigned char, unsigned char, unsigned char)
228 MAXMIN(unsigned short, unsigned short, unsigned short)
229 MAXMIN(unsigned int, unsigned int, unsigned int)
230 MAXMIN(unsigned long, unsigned long, unsigned long)
231 MAXMIN(unsigned long long, unsigned long long, unsigned long long)
233 MAXMIN(long, int, long)
234 MAXMIN(long long, int, long long)
235 MAXMIN(long long, long long, int)
237 inline label& setComponent(label& l, const direction)
242 inline label component(const label l, const direction)
247 inline label mag(const label l)
252 inline label sign(const label s)
254 return (s >= 0)? 1: -1;
257 inline label pos(const label s)
259 return (s >= 0)? 1: 0;
262 inline label neg(const label s)
264 return (s < 0)? 1: 0;
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 } // End namespace Foam
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 // ************************************************************************* //