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 #if INT_MAX > 2000000000
00044
00045
00046
00047 #include "int.H"
00048
00049 namespace Foam
00050 {
00051 typedef int label;
00052
00053 static const label labelMax = INT_MAX;
00054 static const label labelMin = INT_MIN;
00055
00056 inline label readLabel(Istream& is)
00057 {
00058 return readInt(is);
00059 }
00060
00061 }
00062
00063 #else
00064
00065
00066
00067 #include "long.H"
00068
00069 namespace Foam
00070 {
00071 typedef long label;
00072
00073 static const label labelMax = LONG_MAX;
00074 static const label labelMin = LONG_MIN;
00075
00076 inline label readLabel(Istream& is)
00077 {
00078 return readLong(is);
00079 }
00080
00081 }
00082
00083 #endif
00084
00085
00086
00087
00088 #include "pTraits.H"
00089
00090 namespace Foam
00091 {
00092
00093
00094 template<>
00095 class pTraits<label>
00096 {
00097 label p_;
00098
00099 public:
00100
00101
00102 typedef label cmptType;
00103
00104
00105
00106 enum
00107 {
00108 dim = 3,
00109 rank = 0,
00110 nComponents = 1
00111 };
00112
00113
00114
00115 static const char* const typeName;
00116 static const char* componentNames[];
00117 static const label zero;
00118 static const label one;
00119
00120
00121
00122
00123 pTraits(Istream& is);
00124
00125
00126
00127 operator label() const
00128 {
00129 return p_;
00130 }
00131 };
00132
00133
00134
00135
00136
00137 label pow(label a, label b);
00138
00139
00140 label nCr(label n, label r);
00141
00142
00143 label factorial(label n);
00144
00145
00146 #define MAXMIN(retType, type1, type2) \
00147 \
00148 inline retType max(const type1 s1, const type2 s2) \
00149 { \
00150 return (s1 > s2)? s1: s2; \
00151 } \
00152 \
00153 inline retType min(const type1 s1, const type2 s2) \
00154 { \
00155 return (s1 < s2)? s1: s2; \
00156 }
00157
00158
00159 MAXMIN(char, char, char)
00160 MAXMIN(short, short, short)
00161 MAXMIN(int, int, int)
00162 MAXMIN(long, long, long)
00163 MAXMIN(unsigned char, unsigned char, unsigned char)
00164 MAXMIN(unsigned short, unsigned short, unsigned short)
00165 MAXMIN(unsigned int, unsigned int, unsigned int)
00166 MAXMIN(unsigned long, unsigned long, unsigned long)
00167 MAXMIN(long, int, long)
00168 MAXMIN(long, long, int)
00169
00170
00171 inline label mag(const label l)
00172 {
00173 return ::abs(l);
00174 }
00175
00176 inline label sign(const label s)
00177 {
00178 return (s >= 0)? 1: -1;
00179 }
00180
00181 inline label pos(const label s)
00182 {
00183 return (s >= 0)? 1: 0;
00184 }
00185
00186 inline label neg(const label s)
00187 {
00188 return (s < 0)? 1: 0;
00189 }
00190
00191
00192
00193
00194 }
00195
00196
00197
00198 #endif
00199
00200