Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef label_H
00036 #define label_H
00037
00038 #include <climits>
00039 #include <cstdlib>
00040
00041
00042
00043
00044 #if FOAM_LABEL64
00045 # define FOAM_LABEL_MAX 9000000000000000000
00046 #else
00047 # define FOAM_LABEL_MAX 2000000000
00048 #endif
00049
00050
00051 #if INT_MAX > FOAM_LABEL_MAX
00052
00053
00054
00055 # undef FOAM_LABEL_MAX
00056 # define FOAM_LABEL_MAX INT_MAX
00057
00058 # include <OpenFOAM/int.H>
00059
00060 namespace Foam
00061 {
00062 typedef int label;
00063
00064 static const label labelMin = INT_MIN;
00065 static const label labelMax = INT_MAX;
00066
00067 inline label readLabel(Istream& is)
00068 {
00069 return readInt(is);
00070 }
00071
00072 }
00073
00074
00075 #elif LONG_MAX > FOAM_LABEL_MAX
00076
00077
00078 # undef FOAM_LABEL_MAX
00079 # define FOAM_LABEL_MAX LONG_MAX
00080
00081 # include <OpenFOAM/int.H>
00082 # include <OpenFOAM/long.H>
00083
00084 namespace Foam
00085 {
00086 typedef long label;
00087
00088 static const label labelMin = LONG_MIN;
00089 static const label labelMax = LONG_MAX;
00090
00091 inline label readLabel(Istream& is)
00092 {
00093 return readLong(is);
00094 }
00095
00096 }
00097
00098
00099 #elif LLONG_MAX > FOAM_LABEL_MAX
00100
00101
00102
00103 # undef FOAM_LABEL_MAX
00104 # define FOAM_LABEL_MAX LLONG_MAX
00105
00106 # include <OpenFOAM/int.H>
00107 # include <OpenFOAM/long.H>
00108 # include <OpenFOAM/longLong.H>
00109
00110 namespace Foam
00111 {
00112 typedef long long label;
00113
00114 static const label labelMin = LLONG_MIN;
00115 static const label labelMax = LLONG_MAX;
00116
00117 inline label readLabel(Istream& is)
00118 {
00119 return readLongLong(is);
00120 }
00121
00122 }
00123
00124 #endif
00125
00126
00127
00128
00129 #include <OpenFOAM/pTraits.H>
00130 #include <OpenFOAM/direction.H>
00131
00132 namespace Foam
00133 {
00134
00135
00136 template<>
00137 class pTraits<label>
00138 {
00139 label p_;
00140
00141 public:
00142
00143
00144 typedef label cmptType;
00145
00146
00147
00148 enum
00149 {
00150 dim = 3,
00151 rank = 0,
00152 nComponents = 1
00153 };
00154
00155
00156
00157
00158 static const char* const typeName;
00159 static const char* componentNames[];
00160 static const label zero;
00161 static const label one;
00162 static const label min;
00163 static const label max;
00164
00165
00166
00167
00168
00169 pTraits(const label l)
00170 {
00171 p_ = l;
00172 }
00173
00174
00175 pTraits(Istream&);
00176
00177
00178
00179
00180 operator label() const
00181 {
00182 return p_;
00183 }
00184
00185 operator label&()
00186 {
00187 return p_;
00188 }
00189 };
00190
00191
00192
00193
00194
00195 label pow(label a, label b);
00196
00197
00198 label factorial(label n);
00199
00200
00201 #define MAXMIN(retType, type1, type2) \
00202 \
00203 inline retType max(const type1 s1, const type2 s2) \
00204 { \
00205 return (s1 > s2)? s1: s2; \
00206 } \
00207 \
00208 inline retType min(const type1 s1, const type2 s2) \
00209 { \
00210 return (s1 < s2)? s1: s2; \
00211 }
00212
00213
00214 MAXMIN(char, char, char)
00215 MAXMIN(short, short, short)
00216 MAXMIN(int, int, int)
00217 MAXMIN(long, long, long)
00218 MAXMIN(long long, long long, long long)
00219
00220 MAXMIN(unsigned char, unsigned char, unsigned char)
00221 MAXMIN(unsigned short, unsigned short, unsigned short)
00222 MAXMIN(unsigned int, unsigned int, unsigned int)
00223 MAXMIN(unsigned long, unsigned long, unsigned long)
00224 MAXMIN(unsigned long long, unsigned long long, unsigned long long)
00225
00226 MAXMIN(long, int, long)
00227 MAXMIN(long long, int, long long)
00228 MAXMIN(long long, long long, int)
00229
00230 inline label& setComponent(label& l, const direction)
00231 {
00232 return l;
00233 }
00234
00235 inline label component(const label l, const direction)
00236 {
00237 return l;
00238 }
00239
00240 inline label mag(const label l)
00241 {
00242 return ::abs(l);
00243 }
00244
00245 inline label sign(const label s)
00246 {
00247 return (s >= 0)? 1: -1;
00248 }
00249
00250 inline label pos(const label s)
00251 {
00252 return (s >= 0)? 1: 0;
00253 }
00254
00255 inline label neg(const label s)
00256 {
00257 return (s < 0)? 1: 0;
00258 }
00259
00260
00261
00262
00263 }
00264
00265
00266
00267 #endif
00268
00269