Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
csosdefs.h
00001 /* 00002 Copyright (C) 1998 by Jorrit Tyberghein 00003 Written by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSOSDEFS_H__ 00021 #define __CS_CSOSDEFS_H__ 00022 00023 #define CS_EXPORT_SYM_DLL __declspec(dllexport) 00024 #define CS_IMPORT_SYM_DLL __declspec(dllimport) 00025 00026 #ifdef CS_BUILD_SHARED_LIBS 00027 #define CS_EXPORT_SYM CS_EXPORT_SYM_DLL 00028 #define CS_IMPORT_SYM CS_IMPORT_SYM_DLL 00029 #else 00030 #define CS_EXPORT_SYM 00031 #define CS_IMPORT_SYM 00032 #endif // CS_BUILD_SHARED_LIBS 00033 00034 #if defined(CS_COMPILER_MSVC) 00035 #pragma warning(disable:4097) // use of xxx as synonym for a classname 00036 #pragma warning(disable:4099) // type seen as both 'struct' and `class' 00037 #pragma warning(disable:4100) // Use of void* as a formal function parameter 00038 #pragma warning(disable:4102) // 'label' : unreferenced label 00039 #pragma warning(disable:4146) /* unary minus operator applied to unsigned 00040 * type, result still unsigned */ 00041 #pragma warning(disable:4201) // VC6: structure/ union without name. 00042 #pragma warning(disable:4244) // conversion from 'double' to 'float' 00043 #pragma warning(disable:4250) // '...' inherits '..' via dominance 00044 #pragma warning(disable:4251) /* class needs to have dll-interface to be 00045 * used by clients */ 00046 #pragma warning(disable:4275) /* non-DLL-interface used as base for 00047 * DLL-interface */ 00048 #pragma warning(disable:4291) // no matching operator delete found 00049 #pragma warning(disable:4312) /* 'variable' : conversion from 'type' to 00050 * 'type' of greater size */ 00051 #pragma warning(disable:4345) /* VC7.1: an object of POD type constructed 00052 * with an initializer of the form () will 00053 * be default-initialized */ 00054 #pragma warning(disable:4355) // 'this' used in base member initializer list 00055 #pragma warning(disable:4390) // Empty control statement 00056 #pragma warning(disable:4505) /* 'function' : unreferenced local function 00057 * has been removed */ 00058 #pragma warning(disable:4611) /* interaction between _setjmp and C++ 00059 * destructors not portable */ 00060 #pragma warning(disable:4702) // Unreachable Code 00061 #pragma warning(disable:4706) // Assignment in conditional expression 00062 #pragma warning(disable:4710) // function not inlined 00063 #pragma warning(disable:4711) /* function 'function' selected for inline 00064 * expansion */ 00065 #pragma warning(disable:4786) /* VC6: identifier was truncated to '255' 00066 * characters in the browser information */ 00067 #pragma warning(disable:4800) // Forcing value to bool 00068 #pragma warning(disable:4805) // unsafe mix of bool and int. 00069 00070 #if (_MSC_VER < 1300) 00071 #pragma warning(disable:4248) /* MSVC6 gives bogus "protected constructor" 00072 * for csHash::*Iterator, even though csHash 00073 * is friend. */ 00074 #pragma warning(disable:4284) /* At least some versions of MSVC6 (though 00075 * not all) complain about 00076 * csList<int>::operator->() returning a 00077 * pointer to a base type. In general, this 00078 * is a valid complaint because you can not 00079 * legally apply -> to a pointer to a base 00080 * type, however, in the context of a 00081 * template, such as csList<>, the complaint 00082 * is useless if it occurs at declaration 00083 * time. It would be meaningful if it 00084 * complained at invocation time, though. 00085 */ 00086 #pragma warning(disable:4503) /* 'identifier' : decorated name length 00087 * exceeded, name was truncated */ 00088 #endif 00089 00090 #pragma warning(default:4265) /* class has virtual functions, but 00091 * destructor is not virtual */ 00092 00093 #pragma inline_depth (255) 00094 #pragma inline_recursion (on) 00095 #pragma auto_inline (on) 00096 00097 #define CS_FORCEINLINE __forceinline 00098 00099 #pragma intrinsic (memset, memcpy, memcmp) 00100 #pragma intrinsic (strcpy, strcmp, strlen, strcat) 00101 #pragma intrinsic (abs, fabs) 00102 00103 #if defined(__CRYSTAL_SPACE__) && !defined(CS_DEBUG) 00104 #pragma code_seg("CSpace") // Just for fun :) 00105 // However, doing this in debug builds prevents Edit & Continue from 00106 // functioning properly :/ 00107 #endif 00108 00109 // VC8 quirks 00110 #if (_MSC_VER >= 1400) 00111 // Also note quirk in csconfig.h 00112 00113 // Nothing else atm. 00114 #endif 00115 #endif 00116 00117 #ifndef WINVER 00118 #define WINVER 0x0400 00119 #endif 00120 00121 // Although MSVC6 generally supports templated functions within templated 00122 // classes, nevertheless it crashes and burns horribly when arguments to those 00123 // functions are function-pointers or functors. In fact, such usage triggers a 00124 // slew of bugs, mostly "internal compiler error" but also several other 00125 // Worse, the bugs manifest in "random" locations throughout the project, often 00126 // in completely unrelated code. Consequently, instruct csArray<> to avoid 00127 // such usage for MSVC6. 00128 #if defined(CS_COMPILER_MSVC) && (_MSC_VER < 1300) 00129 #define CSARRAY_INHIBIT_TYPED_KEYS 00130 #endif 00131 00132 // So many things require this. IF you have an issue with something defined 00133 // in it then undef that def here. 00134 00135 #if defined(CS_COMPILER_GCC) 00136 00137 // From the w32api header files: 00138 00139 #if defined(__i686__) && !defined(_M_IX86) 00140 #define _M_IX86 600 00141 #elif defined(__i586__) && !defined(_M_IX86) 00142 #define _M_IX86 500 00143 #elif defined(__i486__) && !defined(_M_IX86) 00144 #define _M_IX86 400 00145 #elif defined(__i386__) && !defined(_M_IX86) 00146 #define _M_IX86 300 00147 #endif 00148 #if defined(_M_IX86) && !defined(_X86_) 00149 #define _X86_ 00150 #endif 00151 00152 #ifdef __GNUC__ 00153 #ifndef NONAMELESSUNION 00154 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 00155 #define _ANONYMOUS_UNION __extension__ 00156 #define _ANONYMOUS_STRUCT __extension__ 00157 #else 00158 #if defined(__cplusplus) 00159 #define _ANONYMOUS_UNION __extension__ 00160 #endif /* __cplusplus */ 00161 #endif /* __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) */ 00162 #endif /* NONAMELESSUNION */ 00163 #endif /* __GNUC__ */ 00164 00165 #ifndef _ANONYMOUS_UNION 00166 #define _ANONYMOUS_UNION 00167 #define _UNION_NAME(x) x 00168 #define DUMMYUNIONNAME u 00169 #define DUMMYUNIONNAME2 u2 00170 #define DUMMYUNIONNAME3 u3 00171 #define DUMMYUNIONNAME4 u4 00172 #define DUMMYUNIONNAME5 u5 00173 #define DUMMYUNIONNAME6 u6 00174 #define DUMMYUNIONNAME7 u7 00175 #define DUMMYUNIONNAME8 u8 00176 #else 00177 #define _UNION_NAME(x) 00178 #define DUMMYUNIONNAME 00179 #define DUMMYUNIONNAME2 00180 #define DUMMYUNIONNAME3 00181 #define DUMMYUNIONNAME4 00182 #define DUMMYUNIONNAME5 00183 #define DUMMYUNIONNAME6 00184 #define DUMMYUNIONNAME7 00185 #define DUMMYUNIONNAME8 00186 #endif 00187 #ifndef _ANONYMOUS_STRUCT 00188 #define _ANONYMOUS_STRUCT 00189 #define _STRUCT_NAME(x) x 00190 #define DUMMYSTRUCTNAME s 00191 #define DUMMYSTRUCTNAME2 s2 00192 #define DUMMYSTRUCTNAME3 s3 00193 #else 00194 #define _STRUCT_NAME(x) 00195 #define DUMMYSTRUCTNAME 00196 #define DUMMYSTRUCTNAME2 00197 #define DUMMYSTRUCTNAME3 00198 #endif 00199 00200 #else 00201 00202 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00203 defined(_M_IX86) 00204 #define _X86_ 00205 #endif 00206 00207 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00208 defined(_M_AMD64) 00209 #define _AMD64_ 00210 #endif 00211 00212 #if !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && \ 00213 defined(_M_IA64) && !defined(_IA64_) 00214 #define _IA64_ 00215 #endif 00216 00217 #endif 00218 00219 #ifndef __CYGWIN32__ 00220 #include <excpt.h> 00221 #endif 00222 #include <stdarg.h> 00223 #include <windef.h> 00224 #include <winbase.h> 00225 #include <malloc.h> 00226 #include <sys/types.h> 00227 #include <sys/stat.h> 00228 #ifdef CS_HAVE_SYS_PARAM_H 00229 #include <sys/param.h> 00230 #endif 00231 #ifndef __CYGWIN32__ 00232 #include <direct.h> 00233 #endif 00234 00235 00236 #ifndef WINGDIAPI 00237 #define WINGDIAPI DECLSPEC_IMPORT 00238 #endif 00239 00240 /* 00241 LONG_PTR is used in the Win32 canvases, but it's only defined in newer 00242 Platform or DirectX SDKs (in BaseTsd.h). 00243 Ergo, on older SDKs, we have to define it ourselves. One indicator for the 00244 presence of LONG_PTR seems to be if the __int3264 macro is #defined. 00245 So, if it's not, we define LONG_PTR. 00246 */ 00247 #ifndef __int3264 00248 typedef LONG LONG_PTR; 00249 typedef ULONG ULONG_PTR; 00250 typedef DWORD DWORD_PTR; 00251 #endif 00252 00253 #if defined(_DEBUG) || defined(CS_DEBUG) 00254 #include <assert.h> 00255 #ifndef CS_DEBUG 00256 #define CS_DEBUG 00257 #endif 00258 00259 #if defined(CS_COMPILER_MSVC) 00260 #include <crtdbg.h> 00261 00262 #if defined(CS_EXTENSIVE_MEMDEBUG) 00263 #define malloc(size) \ 00264 _malloc_dbg ((size), _NORMAL_BLOCK, __FILE__, __LINE__) 00265 #define free(ptr) _free_dbg ((ptr), _NORMAL_BLOCK) 00266 #define realloc(ptr, size) \ 00267 _realloc_dbg ((ptr), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00268 #define calloc(num, size) \ 00269 _calloc_dbg ((num), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00270 00271 // heap consistency check is on by default, leave it 00272 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00273 _CrtSetDbgFlag ( \ 00274 _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF) 00275 #else 00276 // turn heap consistency check off 00277 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00278 _CrtSetDbgFlag ( \ 00279 (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) | \ 00280 _CRTDBG_LEAK_CHECK_DF) 00281 #endif 00282 #endif 00283 00284 #endif 00285 00286 #ifdef CS_WIN32_MSVC_DEBUG_GOOP 00287 #define CS_INITIALIZE_PLATFORM_APPLICATION CS_WIN32_MSVC_DEBUG_GOOP 00288 #endif 00289 00290 // The 2D graphics driver used by software renderer on this platform 00291 #define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.directdraw" 00292 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glwin32" 00293 00294 // The sound driver 00295 #define CS_SOUND_DRIVER "crystalspace.sound.driver.waveout" 00296 00297 // SCF symbol export facility. 00298 #ifndef CS_STATIC_LINKED 00299 // No need to export the symbols when statically linking into one big binary. 00300 # undef CS_EXPORTED_FUNCTION 00301 # define CS_EXPORTED_FUNCTION extern "C" __declspec(dllexport) 00302 #endif 00303 00304 #if defined (CS_COMPILER_BCC) 00305 # define strcasecmp stricmp 00306 # define strncasecmp strnicmp 00307 #endif 00308 00309 #if defined (CS_COMPILER_MSVC) 00310 # define strcasecmp _stricmp 00311 # define strncasecmp _strnicmp 00312 #endif 00313 00314 #if defined (CS_COMPILER_MSVC) 00315 # if defined(_MSC_VER) && (_MSC_VER < 1300) 00316 # include <assert.h> 00317 static inline longlong strtoll(char const* s, char** sN, int base) 00318 { 00319 assert(sN == 0); 00320 assert(base == 10); 00321 return _atoi64(s); 00322 } 00323 # else 00324 # define strtoll _strtoi64 00325 # endif 00326 #endif 00327 00328 // Maximal path length 00329 #ifndef CS_MAXPATHLEN 00330 # ifdef _MAX_FNAME 00331 # define CS_MAXPATHLEN _MAX_FNAME 00332 # else 00333 # define CS_MAXPATHLEN 260 /* not 256 */ 00334 # endif 00335 #endif 00336 #define CS_PATH_DELIMITER ';' 00337 #define CS_PATH_SEPARATOR '\\' 00338 00339 #if defined (__CYGWIN32__) 00340 # define CS_MKDIR(path) mkdir(path, 0755) 00341 #else 00342 # define CS_MKDIR(path) _mkdir(path) 00343 #endif 00344 00345 // Directory read functions, file access, etc. 00346 #include <io.h> 00347 #ifndef F_OK 00348 # define F_OK 0 00349 #endif 00350 #ifndef R_OK 00351 # define R_OK 2 00352 #endif 00353 #ifndef W_OK 00354 # define W_OK 4 00355 #endif 00356 00357 #define CS_PROVIDES_EXPAND_PATH 1 00358 inline void csPlatformExpandPath(const char* path, char* buffer, int nbuf) {} 00359 00360 struct dirent 00361 { 00362 char d_name [CS_MAXPATHLEN + 1]; // File name, 0 terminated 00363 size_t d_size; // File size (bytes) 00364 long dwFileAttributes; // File attributes (Windows-specific) 00365 }; 00366 00367 // Although CS_COMPILER_GCC has opendir(), readdir(), etc., we prefer the CS 00368 // versions of these functions. 00369 #define CS_WIN32_USE_CUSTOM_OPENDIR 00370 00371 # if defined(CS_WIN32_USE_CUSTOM_OPENDIR) 00372 struct DIR; 00373 # ifdef CS_CRYSTALSPACE_LIB 00374 extern "C" CS_EXPORT_SYM DIR *opendir (const char *name); 00375 extern "C" CS_EXPORT_SYM dirent *readdir (DIR *dirp); 00376 extern "C" CS_EXPORT_SYM int closedir (DIR *dirp); 00377 extern "C" CS_EXPORT_SYM bool isdir (const char *path, dirent *de); 00378 # else 00379 extern "C" CS_IMPORT_SYM DIR *opendir (const char *name); 00380 extern "C" CS_IMPORT_SYM dirent *readdir (DIR *dirp); 00381 extern "C" CS_IMPORT_SYM int closedir (DIR *dirp); 00382 extern "C" CS_IMPORT_SYM bool isdir (const char *path, dirent *de); 00383 # endif // CS_BUILD_SHARED_LIBS 00384 #endif 00385 00386 #if defined (CS_COMPILER_BCC) || defined (__CYGWIN32__) 00387 # define GETPID() getpid() 00388 #else 00389 # define GETPID() _getpid() 00390 #endif 00391 00392 #ifdef __CYGWIN32__ 00393 # include <unistd.h> 00394 # define CS_TEMP_FILE "cs%lu.tmp", (unsigned long)getpid() 00395 # define CS_TEMP_DIR "/tmp" 00396 #else 00397 # include <process.h> 00398 # define CS_TEMP_FILE "%x.cs", (int)GETPID() 00399 # define CS_TEMP_DIR win32_tempdir() 00400 // This is the function called by CS_TEMP_DIR macro 00401 static inline char *win32_tempdir() 00402 { 00403 char *tmp; 00404 if ((tmp = getenv ("TMP")) != 0) 00405 return tmp; 00406 if ((tmp = getenv ("TEMP")) != 0) 00407 return tmp; 00408 return ""; 00409 } 00410 #endif 00411 00412 // Microsoft Visual C++ compiler includes a very in-efficient 'memcpy'. 00413 // This also replaces the older 'better_memcpy', which was also not as 00414 // efficient as it could be ergo... heres a better solution. 00415 #if defined(CS_COMPILER_MSVC) && (_MSC_VER < 1300) 00416 #include <memory.h> 00417 #define memcpy fast_mem_copy 00418 static inline void* fast_mem_copy (void *dest, const void *src, int count) 00419 { 00420 __asm 00421 { 00422 mov eax, count 00423 mov esi, src 00424 mov edi, dest 00425 xor ecx, ecx 00426 00427 // Check for 'short' moves 00428 cmp eax, 16 00429 jl do_short 00430 00431 // Move enough bytes to align 'dest' 00432 sub ecx, edi 00433 and ecx, 3 00434 je skip 00435 sub eax, ecx 00436 rep movsb 00437 00438 skip: 00439 mov ecx, eax 00440 and eax, 3 00441 shr ecx, 2 00442 rep movsd 00443 test eax, eax 00444 je end 00445 00446 do_short: 00447 mov ecx, eax 00448 rep movsb 00449 00450 end: 00451 } 00452 00453 return dest; 00454 } 00455 #endif 00456 00457 #ifdef CS_COMPILER_BCC 00458 // Major hack due to pow failures in CS for Borland, removing this 00459 // causes millions of strings to print out -- Brandon Ehle 00460 #define pow(arga, argb) ( (!arga && !argb)?0:pow(arga, argb) ) 00461 // Dunno why this is in CS -- Brandon Ehle 00462 #define DEBUG_BREAK 00463 #endif 00464 00465 #if defined (CS_PROCESSOR_X86) 00466 # define CS_LITTLE_ENDIAN 00467 #else 00468 # error "Please define a suitable CS_XXX_ENDIAN macro in win32/csosdefs.h!" 00469 #endif 00470 00471 #if defined(CS_COMPILER_BCC) 00472 // The Borland C++ compiler does not accept a 'main' routine 00473 // in a program which already contains WinMain. This is a work-around. 00474 #undef main 00475 #define main csMain 00476 #endif 00477 00478 // cygwin has no _beginthread and _endthread functions 00479 #ifdef __CYGWIN32__ 00480 #ifndef _beginthread 00481 #define _beginthread(func, stack, ptr) CreateThread (0, 0, \ 00482 LPTHREAD_START_ROUTINE(func), ptr, CREATE_SUSPENDED, 0) 00483 #endif 00484 #ifndef _endthread 00485 #define _endthread() {} 00486 #endif 00487 #endif 00488 00489 // Fake up setenv(), if necessary 00490 #ifndef CS_HAVE_SETENV 00491 #ifdef CS_CRYSTALSPACE_LIB 00492 CS_EXPORT_SYM int setenv (const char* name, const char* value, 00493 bool overwrite); 00494 #else 00495 CS_IMPORT_SYM int setenv (const char* name, const char* value, 00496 bool overwrite); 00497 #endif 00498 #endif 00499 00500 // just to avoid windows.h inclusion 00501 #define csSW_SHOWNORMAL 1 00502 00503 #if defined(CS_COMPILER_GCC) && defined(__STRICT_ANSI__) 00504 // Need those... 00505 extern int _argc; 00506 extern char** _argv; 00507 #define CS_WIN32_ARGC _argc 00508 #define CS_WIN32_ARGV _argv 00509 #elif defined(CS_COMPILER_BCC) 00510 #define CS_WIN32_ARGC _argc 00511 #define CS_WIN32_ARGV _argv 00512 #else 00513 #define CS_WIN32_ARGC __argc 00514 #define CS_WIN32_ARGV __argv 00515 #endif 00516 00517 00518 #ifdef __CYGWIN32__ 00519 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION) 00520 #define CS_IMPLEMENT_PLATFORM_APPLICATION 00521 #endif 00522 00523 #else // __CYGWIN32__ 00524 00525 /* 00526 if the EXE is compiled as a GUI app, 00527 a WinMain is needed. But if compiled 00528 as a console app it's not used but main() is 00529 instead. 00530 */ 00531 00532 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION) 00533 #ifndef __STRICT_ANSI__ 00534 #define csMain main 00535 #else 00536 /* Work around "error: ISO C++ forbids taking address of function `::main'" 00537 * when compiling -ansi -pedantic */ 00538 #define csMain mainWithAnotherNameBecauseISOCPPForbidsIt 00539 #endif 00540 #define CS_IMPLEMENT_PLATFORM_APPLICATION \ 00541 int csMain (int argc, char* argv[]); \ 00542 int WINAPI WinMain (HINSTANCE hApp, HINSTANCE prev, LPSTR cmd, int show)\ 00543 { \ 00544 (void)hApp; \ 00545 (void)show; \ 00546 (void)prev; \ 00547 (void)cmd; \ 00548 int ret = csMain (CS_WIN32_ARGC, CS_WIN32_ARGV); \ 00549 return ret; \ 00550 } 00551 #ifdef __STRICT_ANSI__ 00552 #define main mainWithAnotherNameBecauseISOCPPForbidsIt 00553 #endif 00554 #endif // CS_IMPLEMENT_PLATFORM_APPLICATION 00555 00556 #endif // __CYGWIN32__ 00557 00558 #if !defined(CS_STATIC_LINKED) 00559 00560 #if !defined(CS_IMPLEMENT_PLATFORM_PLUGIN) 00561 #define CS_IMPLEMENT_PLATFORM_PLUGIN \ 00562 int _cs_main(int argc, char* argv[]) \ 00563 { \ 00564 return 0; \ 00565 } \ 00566 extern "C" BOOL WINAPI \ 00567 DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/) \ 00568 { \ 00569 return TRUE; \ 00570 } \ 00571 CS_EXPORTED_FUNCTION const char* plugin_compiler() \ 00572 { \ 00573 return CS_COMPILER_NAME; \ 00574 } 00575 #endif // CS_IMPLEMENT_PLATFORM_PLUGIN 00576 00577 #endif // CS_STATIC_LINKED 00578 00579 // Check for support of native aligned allocation 00580 #if defined(CS_COMPILER_MSVC) && defined(_MSC_VER) && (_MSC_VER >= 1300) 00581 #define csAlignedMalloc(size, align) _aligned_malloc(size, align) 00582 #define csAlignedFree(ptr) _aligned_free(ptr) 00583 #define CS_HAVE_CSALIGNED_MALLOC 00584 #endif 00585 00586 #include "sanity.inc" 00587 00588 #endif // __CS_CSOSDEFS_H__
Generated for Crystal Space by doxygen 1.4.4