CrystalSpace

Public API Reference

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

Generated for Crystal Space by doxygen 1.3.9.1