00001
00002
00003
00004
00005
00006
00007
00008 #ifndef PLATFORM_H_IS_INCLUDED
00009 #define PLATFORM_H_IS_INCLUDED
00010
00011 #if defined(__GNUC__)
00012
00013 #if (__GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 2 ))
00014 #define JOT_NEW_STYLE_IOSTREAM
00015
00016 #define JOT_STDCPP_HEADER_ALGORITHM_INCLUDED
00017 #include <algorithm>
00018 using namespace std;
00019
00020 #elif (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
00021 #define JOT_BACKWARD_IOSTREAM
00022
00023 #define JOT_STDCPP_HEADER_ALGORITHM_INCLUDED
00024 #include <algorithm>
00025 using namespace std;
00026
00027 #elif (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
00028
00029 #define JOT_STDCPP_HEADER_ALGORITHM_INCLUDED
00030 #include <algorithm>
00031 using namespace std;
00032 #endif
00033
00034
00035
00036
00037 #elif defined(WIN32)
00038
00039
00040 #define JOT_NEW_STYLE_IOSTREAM
00041 #include <ios>
00042 #define JOT_STDCPP_HEADER_ALGORITHM_INCLUDED
00043 #include <algorithm>
00044 using namespace std;
00045
00046
00047 #endif
00048
00049
00050
00051
00052 #if (defined(__sgi) && !defined(__GNUC__) && defined(_STANDARD_C_PLUS_PLUS)) || defined(__VACPP_MULTI__)
00053 #define TYPENAME typename
00054 #elif (defined(__GNUC__) && (__GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 2 )))
00055 #define TYPENAME typename
00056 #elif (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1300))
00057 #define TYPENAME typename
00058 #else
00059 #define TYPENAME
00060 #endif
00061
00062
00063
00064
00065
00066 #if !defined(true) && !defined(__GNUC__) && !defined(WIN32) && !defined(_ABIN32) && !defined(__VACPP_MULTI__)
00067 #if !defined(__SUNPRO_CC) || __SUNPRO_CC < 0x500
00068 #if !defined(sgi) || !defined(_BOOL)
00069 #if !defined(__KCC)
00070 typedef int bool;
00071 const int true = 1;
00072 const int false = 0;
00073 #endif
00074 #endif
00075 #endif
00076 #endif
00077
00078
00079 #ifdef WIN32
00080 #ifdef _MSC_VER
00081 #if (_MSC_VER <= 1200)
00082 #define NOMINMAX
00083 #endif
00084 #endif
00085 #include <windows.h>
00086 #include <winbase.h>
00087 #include <sys/types.h>
00088 #include <sys/stat.h>
00089 #include <direct.h>
00090 #include <cstdlib>
00091 #include <cstdio>
00092 #include <ctime>
00093 #include <climits>
00094 #include <cfloat>
00095 #include <cstring>
00096 #include <cerrno>
00097 #include <cctype>
00098 #include <cmath>
00099 #define strncasecmp _strnicmp
00100 inline double drand48() { return rand()/double(RAND_MAX); }
00101 inline void srand48(long seed) { srand((unsigned int) seed); }
00102 inline long lrand48() { return rand(); }
00103 #else
00104 #include <sys/types.h>
00105 #include <sys/stat.h>
00106 #include <sys/time.h>
00107 #include <unistd.h>
00108 #include <dirent.h>
00109 #include <fnmatch.h>
00110 #include <termios.h>
00111 #include <cstdlib>
00112 #include <cstdio>
00113 #include <ctime>
00114 #include <climits>
00115 #include <cfloat>
00116 #include <cstring>
00117 #include <cerrno>
00118 #include <cstdarg>
00119 #include <cctype>
00120 #include <cmath>
00121 #endif
00122
00123 #if defined(__KCC) || defined(__GNUC__) || defined(sgi) || defined(WIN32) || defined(_AIX) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x500)
00124
00125
00126 #define JOT_NEEDS_FULL_CLASS_TYPE
00127 #endif
00128
00129
00130
00131
00132 #if defined(WIN32) || defined(_AIX) || (defined(__GNUC__) && !defined(MAKE_DEPEND))
00133 #define JOT_NEEDS_TEMPLATES_IN_H_FILE
00134 #endif
00135
00136
00137 #ifdef _AIX
00138 #define unix
00139 #endif
00140
00141 #if defined(WIN32) || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x500)
00142 #define JOT_AVOID_STATIC_LOCAL_INLINE_VAR
00143 #endif
00144
00145
00146 #define JOT_NEEDS_DOUBLE_STAR_EXPLICIT
00147
00148
00149
00150 #ifndef JOT_NEEDS_DOUBLE_STAR_EXPLICIT
00151 template <class T>
00152 inline T operator *(double s, const T &p) { return p * s; }
00153 #endif
00154
00155
00156 template <class T>
00157 inline T sqr(const T& x) { return x*x; }
00158
00159
00160 #if (defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)))
00161
00162 #else
00163 inline int round(double x) { return int(x + ((x<0) ? -0.5 : 0.5)); }
00164 #endif
00165
00166
00167
00168
00169
00170
00171
00172 #ifndef JOT_STDCPP_HEADER_ALGORITHM_INCLUDED
00173 template <class T>
00174 inline void swap(T &a, T &b) { T c(a); a = b; b = c; }
00175 #endif
00176
00177
00178
00179
00180
00181
00182
00183
00184 #ifndef JOT_STDCPP_HEADER_ALGORITHM_INCLUDED
00185 template <class T>
00186 inline T min(const T& a, const T& b) { return a < b ? a : b; }
00187 template <class T>
00188 inline T max(const T& a, const T& b) { return a > b ? a : b; }
00189 #endif
00190
00191
00192 template <class T>
00193 inline T
00194 clamp(const T& a, const T& b, const T& c)
00195 {
00196 return (a > b) ? (a < c ? a : c) : b ;
00197 }
00198
00199
00200
00201 template <class T>
00202 inline T
00203 interp(const T& A, const T& B, double w)
00204 {
00205 return A + (B - A)*w;
00206 }
00207
00208
00209 template <class T>
00210 inline bool
00211 in_interval(const T& p, const T& a, const T& b)
00212 {
00213 return (p >= a && p <= b);
00214 }
00215
00216
00217
00218
00219 inline int
00220 Sign(double a) { return (a >= 0) ? 1 : -1; }
00221
00222
00223
00224
00225
00226 inline int
00227 Sign2(double a) { return (a > 0) ? 1 : (a < 0) ? -1 : 0; }
00228
00229 inline bool
00230 XOR(bool x, bool y)
00231 {
00232 return (x && !y) || (!x && y);
00233 }
00234
00235 #if (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x510)
00236 #define JOT_NEW_STYLE_IOSTREAM
00237 #endif
00238
00239 #if defined(__PGI)
00240 #define JOT_NEW_STYLE_IOSTREAM
00241 #define JOT_AVOID_STATIC_LOCAL_INLINE_VAR
00242 #endif
00243
00244 #endif // CONFIG_H_IS_INCLUDED
00245
00246