// global definitions and useful macros // WTF is turning this on when using -fno-exceptions???? #undef __EXCEPTIONS #define _NOTHREADS #ifndef Global_H #define Global_H /* (c) Michael Buro, mic@research.nj.nec.com NEC Research Institute 4 Independence Way Princeton, NJ 08540, USA This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include using namespace std; typedef signed char sint1; typedef unsigned char uint1; typedef signed short sint2; typedef unsigned short uint2; typedef signed int sint4; typedef unsigned int uint4; typedef float real4; typedef double real8; typedef long double realC; typedef signed long long sint8; typedef unsigned long long uint8; typedef void* vptr; typedef char* cptr; typedef const void* cvptr; typedef const char* ccptr; typedef const void* const cvptrc; typedef const char* const ccptrc; const sint1 min_sint1 = 0x80; const sint1 max_sint1 = 0x7F; const uint1 min_uint1 = 0x00; const uint1 max_uint1 = 0xFF; const sint2 min_sint2 = 0x8000; const sint2 max_sint2 = 0x7FFF; const uint2 min_uint2 = 0x0000; const uint2 max_uint2 = 0xFFFF; const sint4 min_sint4 = 0x80000000; const sint4 max_sint4 = 0x7FFFFFFF; const uint4 min_uint4 = 0x00000000; const uint4 max_uint4 = 0xFFFFFFFF; const sint8 min_sint8 = 0x8000000000000000LL; const sint8 max_sint8 = 0x7FFFFFFFFFFFFFFFLL; const uint8 min_uint8 = 0x0000000000000000LL; const uint8 max_uint8 = 0xFFFFFFFFFFFFFFFFLL; #define FOREVER for (;;) #define FOR(i, n) for (i = 0; i < (n); ++i) #define FORS(i, n) for (sint4 i = 0; i < (n); ++i) #define FORU(i, n) for (uint4 i = 0; i < (n); ++i) #if defined(__GNUC__) #define FORT(i, n) for (typeof(n) i = 0; i < (n); ++i) #else #define FORT(i, n) for (int i = 0; i < (n); ++i) #endif #define FORALL(TYPE,CONT,i) \ TYPE::iterator i = CONT.begin(); \ TYPE::iterator i##_end = CONT.end(); \ for (; i != i##_end; i++) #define FORALL_CONST(TYPE,CONT,i) \ TYPE::const_iterator i = (CONT).begin(); \ TYPE::const_iterator i##_end = (CONT).end();\ for (; i != i##_end; i++) #define STR2STRING(os, s) \ {\ (s).erase(); (s).append((os).str(), (os).pcount());\ (os).rdbuf()->freeze(false);\ } #define errstr cerr #define ABORT assert(0==1) #if defined(__GNUC__) #define ERR(s) {\ errstr << endl << __FILE__ << " " << __FUNCTION__ << "() (line " << __LINE__ << "): "\ << s << endl; ABORT; exit(20); \ } #define ERR2(s1, s2) {\ errstr << endl << __FILE__ << " " << __FUNCTION__ << "() (line " << __LINE__ << "): "\ << s1 << " " << s2 << endl; ABORT; exit(20); \ } #else #define ERR(s) {\ errstr << endl << __FILE__ << " (line " << __LINE__ << "): "\ << s << endl; ABORT; exit(20); \ } #define ERR2(s1, s2) {\ errstr << endl << __FILE__ << " (line " << __LINE__ << "): "\ << s1 << " " << s2 << endl; ABORT; exit(20); \ } #endif inline sint4 my_round(real4 x) { return sint4(rint(x)); } inline uint8 cpu_cycles() { uint8 x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } template T square(T x) { return x*x; } extern char *alloc_sprintf(const char *fmt, ...); extern char *alloc_sprintf(const char *fmt, va_list ap); extern ostream &form(ostream& os, const char* fmt, ... ); extern ostream &form(ostream& os, const char* fmt, va_list ap); class Rand { public: static bool use_time_seed; static sint4 num(sint4 limit); // return random 0 <= x < limit }; extern Rand ra; // for testing #define EOL '\n' #undef __EXCEPTIONS #endif