label.H
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
00036 #ifndef label_H
00037 #define label_H
00038
00039 #include <climits>
00040 #include <cstdlib>
00041
00042
00043
00044
00045 #if FOAM_LABEL64
00046 # define FOAM_LABEL_MAX 9000000000000000000
00047 #else
00048 # define FOAM_LABEL_MAX 2000000000
00049 #endif
00050
00051
00052 #if INT_MAX > FOAM_LABEL_MAX
00053
00054
00055
00056 # undef FOAM_LABEL_MAX
00057 # define FOAM_LABEL_MAX INT_MAX
00058
00059 # include "int.H"
00060
00061 namespace Foam
00062 {
00063 typedef int label;
00064
00065 static const label labelMin = INT_MIN;
00066 static const label labelMax = INT_MAX;
00067
00068 inline label readLabel(Istream& is)
00069 {
00070 return readInt(is);
00071 }
00072
00073 }
00074
00075
00076 #elif LONG_MAX > FOAM_LABEL_MAX
00077
00078
00079 # undef FOAM_LABEL_MAX
00080 # define FOAM_LABEL_MAX LONG_MAX
00081
00082 # include "int.H"
00083 # include "long.H"
00084
00085 namespace Foam
00086 {
00087 typedef long label;
00088
00089 static const label labelMin = LONG_MIN;
00090 static const label labelMax = LONG_MAX;
00091
00092 inline label readLabel(Istream& is)
00093 {
00094 return readLong(is);
00095 }
00096
00097 }
00098
00099
00100 #elif LLONG_MAX > FOAM_LABEL_MAX
00101
00102
00103
00104 # undef FOAM_LABEL_MAX
00105 # define FOAM_LABEL_MAX LLONG_MAX
00106
00107 # include "int.H"
00108 # include "long.H"
00109 # include "longLong.H"
00110
00111 namespace Foam
00112 {
00113 typedef long long label;
00114
00115 static const label labelMin = LLONG_MIN;
00116 static const label labelMax = LLONG_MAX;
00117
00118 inline label readLabel(Istream& is)
00119 {
00120 return readLongLong(is);
00121 }
00122
00123 }
00124
00125 #endif
00126
00127
00128
00129
00130 #include "pTraits.H"
00131 #include "direction.H"
00132
00133 namespace Foam
00134 {
00135
00136
00137 template<>
00138 class pTraits<label>
00139 {
00140 label p_;
00141
00142 public:
00143
00144
00145 typedef label cmptType;
00146
00147
00148
00149 enum
00150 {
00151 dim = 3,
00152 rank = 0,
00153 nComponents = 1
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 pTraits(Istream&);
00169
00170
00171
00172 operator label() const
00173 {
00174 return p_;
00175 }
00176 };
00177
00178
00179
00180
00181
00182 label pow(label a, label b);
00183
00184
00185 label factorial(label n);
00186
00187
00188 #define MAXMIN(retType, type1, type2) \
00189 \
00190 inline retType max(const type1 s1, const type2 s2) \
00191 { \
00192 return (s1 > s2)? s1: s2; \
00193 } \
00194 \
00195 inline retType min(const type1 s1, const type2 s2) \
00196 { \
00197 return (s1 < s2)? s1: s2; \
00198 }
00199
00200
00201 MAXMIN(char, char, char)
00202 MAXMIN(short, short, short)
00203 MAXMIN(int, int, int)
00204 MAXMIN(long, long, long)
00205 MAXMIN(long long, long long, long long)
00206
00207 MAXMIN(unsigned char, unsigned char, unsigned char)
00208 MAXMIN(unsigned short, unsigned short, unsigned short)
00209 MAXMIN(unsigned int, unsigned int, unsigned int)
00210 MAXMIN(unsigned long, unsigned long, unsigned long)
00211 MAXMIN(unsigned long long, unsigned long long, unsigned long long)
00212
00213 MAXMIN(long, int, long)
00214 MAXMIN(long long, int, long long)
00215 MAXMIN(long long, long long, int)
00216
00217 inline label& setComponent(label& l, const direction)
00218 {
00219 return l;
00220 }
00221
00222 inline label component(const label l, const direction)
00223 {
00224 return l;
00225 }
00226
00227 inline label mag(const label l)
00228 {
00229 return ::abs(l);
00230 }
00231
00232 inline label sign(const label s)
00233 {
00234 return (s >= 0)? 1: -1;
00235 }
00236
00237 inline label pos(const label s)
00238 {
00239 return (s >= 0)? 1: 0;
00240 }
00241
00242 inline label neg(const label s)
00243 {
00244 return (s < 0)? 1: 0;
00245 }
00246
00247
00248
00249
00250 }
00251
00252
00253
00254 #endif
00255
00256
Copyright © 2000-2009 OpenCFD Ltd