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 Istream
172 operator label() const
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 //- Raise one label to the power of another
182 label pow(label a, label b);
184 //- Evaluate n! : n <= 12
185 label factorial(label n);
188 #define MAXMIN(retType, type1, type2) \
190 inline retType max(const type1 s1, const type2 s2) \
192 return (s1 > s2)? s1: s2; \
195 inline retType min(const type1 s1, const type2 s2) \
197 return (s1 < s2)? s1: s2; \
201 MAXMIN(char, char, char)
202 MAXMIN(short, short, short)
203 MAXMIN(int, int, int)
204 MAXMIN(long, long, long)
205 MAXMIN(long long, long long, long long)
207 MAXMIN(unsigned char, unsigned char, unsigned char)
208 MAXMIN(unsigned short, unsigned short, unsigned short)
209 MAXMIN(unsigned int, unsigned int, unsigned int)
210 MAXMIN(unsigned long, unsigned long, unsigned long)
211 MAXMIN(unsigned long long, unsigned long long, unsigned long long)
213 MAXMIN(long, int, long)
214 MAXMIN(long long, int, long long)
215 MAXMIN(long long, long long, int)
217 inline label& setComponent(label& l, const direction)
222 inline label component(const label l, const direction)
227 inline label mag(const label l)
232 inline label sign(const label s)
234 return (s >= 0)? 1: -1;
237 inline label pos(const label s)
239 return (s >= 0)? 1: 0;
242 inline label neg(const label s)
244 return (s < 0)? 1: 0;
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 } // End namespace Foam
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 // ************************************************************************* //