1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A label is an int/long/long long depending on the range desired.
31 A readLabel function is defined so that label can be constructed from
34 \*---------------------------------------------------------------------------*/
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 # define FOAM_LABEL_MAX 9000000000000000000
48 # define FOAM_LABEL_MAX 2000000000
52 #if INT_MAX > FOAM_LABEL_MAX
54 // Define label as an int
56 # undef FOAM_LABEL_MAX
57 # define FOAM_LABEL_MAX INT_MAX
65 static const label labelMin = INT_MIN;
66 static const label labelMax = INT_MAX;
68 inline label readLabel(Istream& is)
73 } // End namespace Foam
76 #elif LONG_MAX > FOAM_LABEL_MAX
77 // Define label as a long
79 # undef FOAM_LABEL_MAX
80 # define FOAM_LABEL_MAX LONG_MAX
89 static const label labelMin = LONG_MIN;
90 static const label labelMax = LONG_MAX;
92 inline label readLabel(Istream& is)
97 } // End namespace Foam
100 #elif LLONG_MAX > FOAM_LABEL_MAX
102 // Define label as a long long
104 # undef FOAM_LABEL_MAX
105 # define FOAM_LABEL_MAX LLONG_MAX
109 # include "longLong.H"
113 typedef long long label;
115 static const label labelMin = LLONG_MIN;
116 static const label labelMax = LLONG_MAX;
118 inline label readLabel(Istream& is)
120 return readLongLong(is);
123 } // End namespace Foam
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 #include "direction.H"
136 //- template specialization for pTraits<label>
145 typedef label cmptType;
151 dim = 3, // Dimensionality of space
152 rank = 0, // Rank of label is 0
153 nComponents = 1 // Number of components in label is 1
156 // Static data members
158 static const char* const typeName;
159 static const char* componentNames[];
160 static const label zero;
161 static const label one;
162 static const label min;
163 static const label max;
167 //- Construct from label
168 pTraits(const label l)
173 //- Construct from Istream
178 operator label() const
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 //- Raise one label to the power of another
188 label pow(label a, label b);
190 //- Evaluate n! : n <= 12
191 label factorial(label n);
194 #define MAXMIN(retType, type1, type2) \
196 inline retType max(const type1 s1, const type2 s2) \
198 return (s1 > s2)? s1: s2; \
201 inline retType min(const type1 s1, const type2 s2) \
203 return (s1 < s2)? s1: s2; \
207 MAXMIN(char, char, char)
208 MAXMIN(short, short, short)
209 MAXMIN(int, int, int)
210 MAXMIN(long, long, long)
211 MAXMIN(long long, long long, long long)
213 MAXMIN(unsigned char, unsigned char, unsigned char)
214 MAXMIN(unsigned short, unsigned short, unsigned short)
215 MAXMIN(unsigned int, unsigned int, unsigned int)
216 MAXMIN(unsigned long, unsigned long, unsigned long)
217 MAXMIN(unsigned long long, unsigned long long, unsigned long long)
219 MAXMIN(long, int, long)
220 MAXMIN(long long, int, long long)
221 MAXMIN(long long, long long, int)
223 inline label& setComponent(label& l, const direction)
228 inline label component(const label l, const direction)
233 inline label mag(const label l)
238 inline label sign(const label s)
240 return (s >= 0)? 1: -1;
243 inline label pos(const label s)
245 return (s >= 0)? 1: 0;
248 inline label neg(const label s)
250 return (s < 0)? 1: 0;
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 } // End namespace Foam
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 // ************************************************************************* //