Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

global.h

Go to the documentation of this file.
00001 #if !defined(SM_PCH) || SM_PCH == FALSE 00002 00003 #ifndef GLOBAL_H 00004 #define GLOBAL_H 00005 00006 #ifdef HAVE_CONFIG_H 00007 #include "config.h" 00008 #endif 00009 00010 #if _MSC_VER >= 1000 00011 #pragma once 00012 #endif // _MSC_VER >= 1000 00013 00014 /* Platform-specific fixes. */ 00015 #if defined(WIN32) 00016 #include "archutils/Win32/arch_setup.h" 00017 #elif defined(PBBUILD) 00018 #include "archutils/Darwin/arch_setup.h" 00019 #elif defined(UNIX) 00020 #include "archutils/Unix/arch_setup.h" 00021 #endif 00022 00023 /* Set one of these in arch_setup.h. (Don't bother trying to fall back on BYTE_ORDER 00024 * if it was already set; too many systems are missing endian.h.) */ 00025 #if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG) 00026 #error Neither ENDIAN_LITTLE nor ENDIAN_BIG defined 00027 #endif 00028 00029 /* Define standard endianness macros, if they're missing. */ 00030 #if defined(HAVE_ENDIAN_H) 00031 #include <endian.h> 00032 #else 00033 #define LITTLE_ENDIAN 1234 00034 #define BIG_ENDIAN 4321 00035 #if defined(ENDIAN_LITTLE) 00036 #define BYTE_ORDER LITTLE_ENDIAN 00037 #elif defined(ENDIAN_BIG) 00038 #define BYTE_ORDER BIG_ENDIAN 00039 #endif 00040 00041 #endif 00042 00043 /* Make sure everyone has min and max: */ 00044 #include <algorithm> 00045 00046 /* Everything will need string for one reason or another: */ 00047 #include <string> 00048 00049 /* And vector: */ 00050 #include <vector> 00051 00052 #if !defined(MISSING_STDINT_H) /* need to define int64_t if so */ 00053 #include <stdint.h> 00054 #endif 00055 00056 #if defined(NEED_CSTDLIB_WORKAROUND) 00057 #define llabs ::llabs 00058 #endif 00059 00060 #if defined(NEED_MINMAX_TEMPLATES) 00061 /* Some old <algorithm>s don't actually define min and max. */ 00062 template<class T> 00063 inline const T& max(const T &a, const T &b) { return a < b? b:a; } 00064 template<class T, class P> 00065 inline const T& max(const T &a, const T &b, P Pr) { return Pr(a, b)? b:a; } 00066 template<class T> 00067 inline const T& min(const T &a, const T &b) { return b < a? b:a; } 00068 template<class T, class P> 00069 inline const T& min(const T &a, const T &b, P Pr) { return Pr(b, a)? b:a; } 00070 #endif 00071 00072 using namespace std; 00073 00074 #ifdef ASSERT 00075 #undef ASSERT 00076 #endif 00077 00078 /* RageThreads defines (don't pull in all of RageThreads.h here) */ 00079 namespace Checkpoints 00080 { 00081 void SetCheckpoint( const char *file, int line, const char *message ); 00082 }; 00083 #define CHECKPOINT (Checkpoints::SetCheckpoint(__FILE__, __LINE__, NULL)) 00084 #define CHECKPOINT_M(m) (Checkpoints::SetCheckpoint(__FILE__, __LINE__, m)) 00085 00086 00087 /* Define a macro to tell the compiler that a function doesn't return. This just 00088 * improves compiler warnings. This should be placed near the beginning of the 00089 * function prototype (although it looks better near the end, VC only accepts it 00090 * at the beginning). */ 00091 #if defined(_MSC_VER) 00092 #define NORETURN __declspec(noreturn) 00093 #elif defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) 00094 #define NORETURN __attribute__ ((__noreturn__)) 00095 #else 00096 #define NORETURN 00097 #endif 00098 00099 void NORETURN sm_crash( const char *reason = "Internal error" ); 00100 00101 /* Assertion that sets an optional message and brings up the crash handler, so 00102 * we get a backtrace. This should probably be used instead of throwing an 00103 * exception in most cases we expect never to happen (but not in cases that 00104 * we do expect, such as DSound init failure.) */ 00105 #define FAIL_M(MESSAGE) { CHECKPOINT_M(MESSAGE); sm_crash(MESSAGE); } 00106 #define ASSERT_M(COND, MESSAGE) { if(!(COND)) { FAIL_M(MESSAGE); } } 00107 #define ASSERT(COND) ASSERT_M((COND), "Assertion '" #COND "' failed") 00108 00109 #ifdef DEBUG 00110 #define DEBUG_ASSERT(x) ASSERT(x) 00111 #else 00112 #define DEBUG_ASSERT(x) 00113 #endif 00114 00115 /* Define a macro to tell the compiler that a function has printf() semantics, to 00116 * aid warning output. */ 00117 #if defined(__GNUC__) 00118 #define PRINTF(a,b) __attribute__((format(__printf__,a,b))) 00119 #else 00120 #define PRINTF(a,b) 00121 #endif 00122 00123 #if !defined(ALIGN) 00124 #if defined(__GNUC__) 00125 #define ALIGN(n) __attribute__((aligned(n))) 00126 #else 00127 #define ALIGN(n) 00128 #endif 00129 #endif 00130 00131 /* Use CStdString: */ 00132 #include "StdString.h" 00133 00134 typedef const CString& CCStringRef; 00135 00136 /* Include this here to make sure our assertion handler is always 00137 * used. (This file is a dependency of most everything anyway, 00138 * so there's no real problem putting it here.) */ 00139 #include "RageException.h" 00140 00141 #if !defined(WIN32) 00142 #define stricmp strcasecmp 00143 #define strnicmp strncasecmp 00144 #endif 00145 00146 /* Define a few functions if necessary */ 00147 #include <cmath> 00148 #ifdef NEED_POWF 00149 inline float powf (float x, float y) { return float(pow(double(x),double(y))); } 00150 #endif 00151 00152 #ifdef NEED_SQRTF 00153 inline float sqrtf(float x) { return float(sqrt(double(x))); } 00154 #endif 00155 00156 #ifdef NEED_SINF 00157 inline float sinf(float x) { return float(sin(double(x))); } 00158 #endif 00159 00160 #ifdef NEED_TANF 00161 inline float tanf(float x) { return float(tan(double(x))); } 00162 #endif 00163 00164 #ifdef NEED_COSF 00165 inline float cosf(float x) { return float(cos(double(x))); } 00166 #endif 00167 00168 #ifdef NEED_ACOSF 00169 inline float acosf(float x) { return float(acos(double(x))); } 00170 #endif 00171 00172 #ifdef NEED_TRUNCF 00173 inline float truncf( float f ) { return float(int(f)); }; 00174 #endif 00175 00176 #ifdef NEED_ROUNDF 00177 inline float roundf( float f ) { if(f < 0) return truncf(f-0.5f); return truncf(f+0.5f); }; 00178 #endif 00179 00180 #ifdef NEED_STRTOF 00181 inline float strtof( const char *s, char **se ) { return (float) strtod( s, se ); } 00182 #endif 00183 00184 /* Don't include our own headers here, since they tend to change often. */ 00185 00186 #endif 00187 00188 #endif /* SM_PCH */ 00189 00190 /* 00191 * (c) 2001-2004 Chris Danford, Glenn Maynard 00192 * All rights reserved. 00193 * 00194 * Permission is hereby granted, free of charge, to any person obtaining a 00195 * copy of this software and associated documentation files (the 00196 * "Software"), to deal in the Software without restriction, including 00197 * without limitation the rights to use, copy, modify, merge, publish, 00198 * distribute, and/or sell copies of the Software, and to permit persons to 00199 * whom the Software is furnished to do so, provided that the above 00200 * copyright notice(s) and this permission notice appear in all copies of 00201 * the Software and that both the above copyright notice(s) and this 00202 * permission notice appear in supporting documentation. 00203 * 00204 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00205 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00206 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00207 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00208 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00209 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00210 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00211 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00212 * PERFORMANCE OF THIS SOFTWARE. 00213 */

Generated on Thu Jan 27 20:57:21 2005 for StepMania by doxygen 1.3.7