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 factorial(label n);
00141
00142
00143 #define MAXMIN(retType, type1, type2) \
00144 \
00145 inline retType max(const type1 s1, const type2 s2) \
00146 { \
00147 return (s1 > s2)? s1: s2; \
00148 } \
00149 \
00150 inline retType min(const type1 s1, const type2 s2) \
00151 { \
00152 return (s1 < s2)? s1: s2; \
00153 }
00154
00155
00156 MAXMIN(char, char, char)
00157 MAXMIN(short, short, short)
00158 MAXMIN(int, int, int)
00159 MAXMIN(long, long, long)
00160 MAXMIN(unsigned char, unsigned char, unsigned char)
00161 MAXMIN(unsigned short, unsigned short, unsigned short)
00162 MAXMIN(unsigned int, unsigned int, unsigned int)
00163 MAXMIN(unsigned long, unsigned long, unsigned long)
00164 MAXMIN(long, int, long)
00165 MAXMIN(long, long, int)
00166
00167
00168 inline label mag(const label l)
00169 {
00170 return ::abs(l);
00171 }
00172
00173 inline label sign(const label s)
00174 {
00175 return (s >= 0)? 1: -1;
00176 }
00177
00178 inline label pos(const label s)
00179 {
00180 return (s >= 0)? 1: 0;
00181 }
00182
00183 inline label neg(const label s)
00184 {
00185 return (s < 0)? 1: 0;
00186 }
00187
00188
00189
00190
00191 }
00192
00193
00194
00195 #endif
00196
00197
Copyright © 2000-2007 OpenCFD Ltd