Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

cssysdef.h

00001 /*
00002     Copyright (C) 1998-2001 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 #ifdef __CS_CSSYSDEFS_H__
00021 #error Do not include cssysdef.h from header files please!
00022 #else
00023 #define __CS_CSSYSDEFS_H__
00024 
00025 #define CSDEF_FRIEND
00026 #include "csdef.h"
00027 #undef CSDEF_FRIEND
00028 
00029 /*
00030     This include file should be included from every source file.
00031     Just before #include directive it can contain several #define's
00032     that specify what the source file requires.
00033 
00034     The following variables can be defined:
00035 
00036     #define CS_SYSDEF_PROVIDE_CASE
00037       Define the UPPERCASE() and LOWERCASE() macros.
00038 
00039     #define CS_SYSDEF_PROVIDE_PATH
00040       Include definition of PATH_SEPARATOR character, MAXPATHLEN and
00041       APPEND_SLASH macros.
00042 
00043     #define CS_SYSDEF_PROVIDE_MKDIR
00044       Include definition for MKDIR()
00045 
00046     #define CS_SYSDEF_PROVIDE_GETCWD
00047       Include definition for getcwd()
00048 
00049     #define CS_SYSDEF_PROVIDE_TEMP
00050       Include definitions for TEMP_DIR and TEMP_FILE.
00051 
00052     #define CS_SYSDEF_PROVIDE_DIR
00053       Include definitions required for opendir(), readdir(), closedir()
00054       and isdir().
00055  
00056     #define CS_SYSDEF_PROVIDE_UNLINK
00057       Include definitions required for unlink()
00058 
00059     #define CS_SYSDEF_PROVIDE_ACCESS
00060       Include definitions required for access()
00061 
00062     #define CS_SYSDEF_PROVIDE_ALLOCA
00063       Include definition for alloca() and ALLOC_STACK_ARRAY()
00064 
00065     #define CS_SYSDEF_PROVIDE_GETOPT
00066       For getopt() and GNU getopt_long()
00067 
00068     #define CS_SYSDEF_PROVIDE_SOCKETS
00069       For TCP/IP sockets definitions.  Specifically, should define the
00070       following macros, constants, typedefs, and prototypes:
00071         inet_addr(), gethostbyname(), ntohl(), etc.
00072         socket(), listen(), bind(), etc. -- the standard socket functions
00073         csNetworkSocket -- typedef or macro for socket descriptor type
00074         struct sockaddr -- standard socket address type (and cousins)
00075         socklen_t -- typedef or macro
00076         CS_NET_SOCKET_INVALID -- value representing invalid socket
00077         CS_CLOSESOCKET -- name of function to close a socket
00078         CS_IOCTLSOCKET -- name of "ioctl" function for sockets
00079         CS_GETSOCKETERROR -- name of function or variable for socket error code
00080         
00081     #define CS_SYSDEF_PROVIDE_SELECT
00082       Includes definitions required for select(), FD_* macros, and
00083       struct timeval.
00084 
00085     The system-dependent include files can undefine some or all
00086     CS_SYSDEF_PROVIDE_xxx macros to avoid further definitions in this file.
00087     For example, if a system-dependent file defines everything needed for
00088     CS_SYSDEF_PROVIDE_GETOPT it should #undefine CS_SYSDEF_PROVIDE_GETOPT to
00089     avoid including util/gnu/getopt.h at the bottom of this file.
00090 */
00091 
00092 #if defined (CS_SYSDEF_PROVIDE_DIR) && !defined (CS_SYSDEF_PROVIDE_PATH)
00093 #  define CS_SYSDEF_PROVIDE_PATH
00094 #endif
00095 
00096 /*
00097  * Pull in platform-specific overrides of the requested functionality.
00098  */
00099 #include "cssys/csosdefs.h"
00100 
00101 /*
00102  * Default definitions for requested functionality.  Platform-specific
00103  * configuration files may override these.
00104  */
00105 
00106 #ifdef CS_SYSDEF_PROVIDE_CASE
00107 // Convert a character to upper case
00108 #  ifndef UPPERCASE
00109 #    define UPPERCASE(c) ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c)
00110 #  endif
00111 // Convert a character to lower case
00112 #  ifndef LOWERCASE
00113 #    define LOWERCASE(c) ((c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c)
00114 #  endif
00115 #endif // CS_SYSDEF_PROVIDE_CASE
00116 
00117 #ifdef CS_SYSDEF_PROVIDE_PATH
00118 // Path separator character
00119 #  ifndef PATH_SEPARATOR
00120 #    if defined(__CYGWIN32__)
00121 #      define PATH_SEPARATOR '/'
00122 #    elif defined(OS_OS2) || defined(OS_DOS) || defined(OS_WIN32)
00123 #      define PATH_SEPARATOR '\\'
00124 #    else
00125 #      define PATH_SEPARATOR '/'
00126 #    endif
00127 #  endif
00128 // Maximal path length
00129 #  ifndef CS_MAXPATHLEN
00130 #    ifdef _MAX_FNAME
00131 #      define CS_MAXPATHLEN _MAX_FNAME
00132 #    else
00133 #      define CS_MAXPATHLEN 256
00134 #    endif
00135 #  endif
00136 #  define APPEND_SLASH(str,len)                 \
00137      if ((len)                                  \
00138       && (str[len - 1] != '/')                  \
00139       && (str[len - 1] != PATH_SEPARATOR))      \
00140      {                                          \
00141        str[len++] = PATH_SEPARATOR;             \
00142        str[len] = 0;                            \
00143      } /* endif */
00144 #endif // CS_SYSDEF_PROVIDE_PATH
00145 
00146 #ifdef CS_SYSDEF_PROVIDE_TEMP
00147 // Directory for temporary files
00148 #  ifndef TEMP_DIR
00149 #    if defined(OS_UNIX)
00150 #      define TEMP_DIR "/tmp/"
00151 #    else
00152 #      define TEMP_DIR ""
00153 #    endif
00154 #  endif
00155 // Name for temporary file
00156 #  ifndef TEMP_FILE
00157 #    if defined(OS_UNIX)
00158 #      include <unistd.h>
00159 #      define TEMP_FILE "cs%lud.tmp", (unsigned long)getpid()
00160 #    else
00161 #      define TEMP_FILE "$cs$.tmp"
00162 #    endif
00163 #  endif
00164 #endif // CS_SYSDEF_PROVIDE_TEMP
00165 
00166 #ifdef CS_SYSDEF_PROVIDE_MKDIR
00167 // How to make a directory (not entire path, only the last on the path)
00168 #  ifndef MKDIR
00169 #    if defined(OS_WIN32) || (defined(OS_DOS) && !defined(COMP_GCC))
00170 #      define MKDIR(path) _mkdir (path)
00171 #    else
00172 #      define MKDIR(path) mkdir (path, 0755)
00173 #    endif
00174 #  endif
00175 #endif // CS_SYSDEF_PROVIDE_MKDIR
00176 
00177 #ifdef CS_SYSDEF_PROVIDE_GETCWD
00178 #  if !defined(COMP_VC) && !defined(COMP_BC)
00179 #    include <unistd.h>
00180 #  endif
00181 #endif // CS_SYSDEF_PROVIDE_GETCWD
00182 
00183 #ifdef CS_SYSDEF_PROVIDE_DIR
00184 // For systems without opendir()
00185 // COMP_GCC has opendir, readdir 
00186 # if !defined(COMP_GCC)
00187 #  if defined(__NEED_OPENDIR_PROTOTYPE)
00188      struct DIR;
00189      struct dirent;
00190      extern "C" DIR *opendir (const char *name);
00191      extern "C" dirent *readdir (DIR *dirp);
00192      extern "C" int closedir (DIR *dirp);
00193      //extern "C" void seekdir (DIR *dirp, long off);
00194      //extern "C" long telldir (DIR *dirp);
00195      //extern "C" void rewinddir (DIR *dirp);
00196 #  endif
00197 # endif
00198 // Generic ISDIR needed for COMP_GCC
00199 #  ifdef __NEED_GENERIC_ISDIR
00200 #    if defined (OS_WIN32) || defined (OS_DOS)
00201 #      include <io.h>
00202 #    endif
00203 #    include <sys/types.h>
00204 #    if !defined(OS_WIN32)
00205 #      include <dirent.h>
00206 #    endif
00207 #    if defined(__CYGWIN32__)
00208 #      include <sys/dirent.h>
00209 #    endif
00210 #    include <sys/stat.h>
00211      static inline bool isdir (const char *path, struct dirent *de)
00212      {
00213        char fullname [CS_MAXPATHLEN];
00214        int pathlen = strlen (path);
00215        memcpy (fullname, path, pathlen + 1);
00216        APPEND_SLASH (fullname, pathlen);
00217        strcat (&fullname [pathlen], de->d_name);
00218        struct stat st;
00219        stat (fullname, &st);
00220        return ((st.st_mode & S_IFMT) == S_IFDIR);
00221      }
00222 #  endif
00223 #endif // CS_SYSDEF_PROVIDE_DIR
00224 
00225 #ifdef CS_SYSDEF_PROVIDE_UNLINK
00226 #  if !defined(COMP_VC) && !defined(COMP_BC)
00227 #    include <unistd.h>
00228 #  endif
00229 #endif
00230 
00231 #ifdef CS_SYSDEF_PROVIDE_ALLOCA
00232 // Prototypes for dynamic stack memory allocation
00233 #  if defined (COMP_VC) || defined(COMP_BC) || \
00234      (defined(COMP_GCC) && defined(OS_WIN32))
00235 #    include <malloc.h>
00236 #  elif defined(COMP_GCC) && defined(OS_DOS)
00237 #    include <stdlib.h>
00238 #  elif defined(OS_BSD)
00239 #    include <stdlib.h>
00240 #  else
00241 #    include <alloca.h>
00242 #  endif
00243 #  if defined (COMP_GCC)
00244     // In GCC we are able to declare stack vars of dynamic size directly
00245 #    define ALLOC_STACK_ARRAY(var,type,size) \
00246        type var [size]
00247 #  else
00248 #    define ALLOC_STACK_ARRAY(var,type,size) \
00249        type *var = (type *)alloca (size * sizeof (type))
00250 #  endif
00251 #endif
00252 
00253 #ifdef CS_SYSDEF_PROVIDE_ACCESS
00254 #  if !defined(COMP_VC) && !defined(COMP_BC)
00255 #    include <unistd.h>
00256 #  endif
00257 #  ifndef F_OK
00258 #    define F_OK 0
00259 #  endif
00260 #  ifndef R_OK
00261 #    define R_OK 2
00262 #  endif
00263 #  ifndef W_OK
00264 #    define W_OK 4
00265 #  endif
00266 #endif
00267 
00268 #ifdef CS_SYSDEF_PROVIDE_GETOPT
00269 #  ifndef __STDC__
00270 #    define __STDC__ 1
00271 #  endif
00272 #  include "cssys/getopt.h"
00273 #endif
00274 
00275 #ifdef CS_SYSDEF_PROVIDE_SOCKETS
00276 #  include <sys/types.h>
00277 #  include <sys/socket.h>
00278 #  if defined (OS_UNIX)
00279 #    include <unistd.h>
00280 #    define BSD_COMP 1
00281 #    include <sys/ioctl.h>
00282 #    if !defined (OS_SOLARIS) && !defined (OS_BE)
00283 #      include <arpa/inet.h>
00284 #      include <sys/time.h>
00285 #    endif
00286 #  endif
00287 #  include <netinet/in.h>
00288 #  include <netdb.h>
00289 #  if defined (CS_USE_FAKE_SOCKLEN_TYPE)
00290      typedef int socklen_t;
00291 #  endif
00292 #  if !defined (CS_IOCTLSOCKET)
00293 #    define CS_IOCTLSOCKET ioctl
00294 #  endif
00295 #  if !defined (CS_CLOSESOCKET)
00296 #    define CS_CLOSESOCKET close
00297 #  endif
00298 #  if !defined (CS_GETSOCKETERROR)
00299 #    define CS_GETSOCKETERROR errno
00300 #  endif
00301    typedef unsigned int csNetworkSocket;
00302 #  if !defined (CS_NET_SOCKET_INVALID)
00303 #    define CS_NET_SOCKET_INVALID ((csNetworkSocket)~0)
00304 #  endif
00305 #endif
00306 
00307 #ifdef CS_SYSDEF_PROVIDE_SELECT
00308 #  include <sys/select.h>
00309 #endif
00310 
00326 #define CS_HEADER_GLOBAL(X,Y) CS_HEADER_GLOBAL_COMPOSE(X,Y)
00327 #define CS_HEADER_GLOBAL_COMPOSE(X,Y) < ## X ## / ## Y ## >
00328 
00341 #define CS_HEADER_LOCAL(X,Y) CS_HEADER_LOCAL_COMPOSE1(X,Y)
00342 #define CS_HEADER_LOCAL_COMPOSE1(X,Y) CS_HEADER_LOCAL_COMPOSE2(X ## / ## Y)
00343 #define CS_HEADER_LOCAL_COMPOSE2(X) #X
00344 
00345 
00346 /*
00347  * A macro to export a function from a shared library.
00348  * Some platforms may need to override this.  For instance, Windows requires
00349  * extra `__declspec' goop when exporting a function from a plug-in module.
00350  */
00351 #if !defined(CS_EXPORTED_FUNCTION)
00352 #  define CS_EXPORTED_FUNCTION extern "C"
00353 #endif
00354 
00355 /*
00356  * A macro used to build exported function names.
00357  * Usually "Prefix" is derived from shared library name, thus for each library
00358  * we'll have different exported names.  This prevents naming collisions when
00359  * static linking is used, and on platforms where plug-in symbols are exported
00360  * by default.  However, this may be bad for platforms which need to build
00361  * special export-tables on-the-fly at compile-time since distinct names make
00362  * the job more difficult.  Such platforms may need to override the default
00363  * expansion of this macro to use only the `Suffix' and ignore the `Prefix'
00364  * when composing the name.
00365  */
00366 #if !defined(CS_EXPORTED_NAME)
00367 #  define CS_EXPORTED_NAME(Prefix, Suffix) Prefix ## Suffix
00368 #endif
00369 
00370 #ifndef CS_IMPLEMENT_PLATFORM_PLUGIN
00371 #  define CS_IMPLEMENT_PLATFORM_PLUGIN
00372 #endif
00373 
00374 #ifndef CS_IMPLEMENT_PLATFORM_APPLICATION
00375 #  define CS_IMPLEMENT_PLATFORM_APPLICATION
00376 #endif
00377 
00378 #ifndef CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION
00379 #  define CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION cs_static_var_cleanup
00380 #endif
00381 
00382 #ifndef CS_DECLARE_STATIC_VARIABLE_REGISTRATION
00383 #  define CS_DECLARE_STATIC_VARIABLE_REGISTRATION \
00384 void CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (void (*p)());
00385 #endif
00386 
00387 #ifndef CS_DECLARE_STATIC_VARIABLE_CLEANUP
00388 #  define CS_DECLARE_STATIC_VARIABLE_CLEANUP \
00389    CS_DECLARE_STATIC_VARIABLE_REGISTRATION
00390 #endif
00391 
00392 #ifndef CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION
00393 #  define CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION                    \
00394 void CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (void (*p)())        \
00395 {                                                                      \
00396   static void (**a)()=0;                                               \
00397   static int lastEntry=0;                                              \
00398   static int maxEntries=0;                                             \
00399                                                                        \
00400   if (p)                                                               \
00401   {                                                                    \
00402     if (lastEntry >= maxEntries)                                       \
00403     {                                                                  \
00404       maxEntries+=10;                                                  \
00405       a = (void (**)())realloc (a, maxEntries*sizeof(void*));          \
00406     }                                                                  \
00407     a[lastEntry++] = p;                                                \
00408   }                                                                    \
00409   else                                                                 \
00410   {                                                                    \
00411     int i;                                                             \
00412     for (i=lastEntry-1; i >= 0; i--)                                   \
00413       a[i] ();                                                         \
00414     free (a);                                                          \
00415    }                                                                   \
00416 }                                                                      
00417 #endif
00418 
00419 #ifndef CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP
00420 #  define CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP \
00421    CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION   
00422 #endif
00423 
00432 #if defined(CS_STATIC_LINKED)
00433 
00434 #  ifndef CS_IMPLEMENT_PLUGIN
00435 #  define CS_IMPLEMENT_PLUGIN        \
00436           CS_IMPLEMENT_PLATFORM_PLUGIN 
00437 #  endif
00438 
00439 #else
00440 
00441 #  ifndef CS_IMPLEMENT_PLUGIN
00442 #  define CS_IMPLEMENT_PLUGIN              \
00443    CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP    \
00444    CS_IMPLEMENT_PLATFORM_PLUGIN 
00445 #  endif
00446 
00447 #endif
00448 
00456 #ifndef CS_IMPLEMENT_APPLICATION
00457 #  define CS_IMPLEMENT_APPLICATION       \
00458    CS_IMPLEMENT_STATIC_VARIABLE_CLEANUP  \
00459    CS_IMPLEMENT_PLATFORM_APPLICATION 
00460 #endif
00461 
00465 #ifndef CS_REGISTER_STATIC_FOR_DESTRUCTION
00466 #define CS_REGISTER_STATIC_FOR_DESTRUCTION(getterFunc)\
00467         CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (getterFunc);
00468 #endif
00469 
00473 #ifndef CS_STATIC_VARIABLE_CLEANUP
00474 #define CS_STATIC_VARIABLE_CLEANUP  \
00475         CS_STATIC_VAR_DESTRUCTION_REGISTRAR_FUNCTION (0);
00476 #endif
00477 
00488 #ifndef CS_IMPLEMENT_STATIC_VAR_EXT
00489 #define CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,kill_how) \
00490 CS_DECLARE_STATIC_VARIABLE_REGISTRATION                                 \
00491 extern "C" {                                                            \
00492 static Type* getterFunc ();                                             \
00493 static void getterFunc ## _kill ();                                     \
00494 void getterFunc ## _kill ()                                             \
00495 {                                                                       \
00496   delete getterFunc ();                                                 \
00497 }                                                                       \
00498 static void getterFunc ## _kill_array ();                               \
00499 void getterFunc ## _kill_array ()                                       \
00500 {                                                                       \
00501   delete [] getterFunc ();                                              \
00502 }                                                                       \
00503 Type* getterFunc ()                                                     \
00504 {                                                                       \
00505   static Type *v=0;                                                     \
00506   if (!v)                                                               \
00507   {                                                                     \
00508     v = new Type initParam;                                             \
00509     CS_REGISTER_STATIC_FOR_DESTRUCTION (getterFunc ## kill_how);        \
00510   }                                                                     \
00511   return v;                                                             \
00512 }                                                                       \
00513 }
00514 #endif
00515 
00516 #ifndef CS_IMPLEMENT_STATIC_VAR
00517 #define CS_IMPLEMENT_STATIC_VAR(getterFunc,Type,initParam)    \
00518  CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill)    
00519 #endif
00520 
00521 #ifndef CS_IMPLEMENT_STATIC_VAR_ARRAY
00522 #define CS_IMPLEMENT_STATIC_VAR_ARRAY(getterFunc,Type,initParam)    \
00523  CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill_array)    
00524 #endif
00525 
00531 #ifndef CS_DECLARE_STATIC_CLASSVAR
00532 #define CS_DECLARE_STATIC_CLASSVAR(var,getterFunc,Type)       \
00533 static Type *var;                                             \
00534 static Type *getterFunc ();                                   
00535 #endif
00536 
00537 #ifndef CS_DECLARE_STATIC_CLASSVAR_REF
00538 #define CS_DECLARE_STATIC_CLASSVAR_REF(var,getterFunc,Type)   \
00539 static Type *var;                                             \
00540 static Type &getterFunc ();                                   
00541 #endif
00542 
00552 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_EXT
00553 #define CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,kill_how)   \
00554 Type *Class::var = 0;                                                                    \
00555 extern "C" {                                                                             \
00556 static void Class ## _ ## getterFunc ## _kill ();                                        \
00557 void Class ## _ ## getterFunc ## _kill ()                                                \
00558 {                                                                                        \
00559   delete Class::getterFunc ();                                                           \
00560 }                                                                                        \
00561 static void Class ## _ ## getterFunc ## _kill_array ();                                  \
00562 void Class ## _ ## getterFunc ## _kill_array ()                                          \
00563 {                                                                                        \
00564   delete [] Class::getterFunc ();                                                        \
00565 }                                                                                        \
00566 }                                                                                        \
00567 Type* Class::getterFunc ()                                                               \
00568 {                                                                                        \
00569   if (!var)                                                                              \
00570   {                                                                                      \
00571     var = new Type initParam;                                                            \
00572     CS_DECLARE_STATIC_VARIABLE_REGISTRATION                                              \
00573     CS_REGISTER_STATIC_FOR_DESTRUCTION (Class ## _ ## getterFunc ## kill_how);           \
00574   }                                                                                      \
00575   return var;                                                                            \
00576 }
00577 #endif
00578 
00579 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR
00580 #define CS_IMPLEMENT_STATIC_CLASSVAR(Class,var,getterFunc,Type,initParam) \
00581         CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,_kill)
00582 #endif
00583 
00584 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY
00585 #define CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY(Class,var,getterFunc,Type,initParam) \
00586         CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,_kill_array)
00587 #endif
00588 
00589 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT
00590 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,kill_how)   \
00591 Type *Class::var = 0;                                                                        \
00592 extern "C" {                                                                                 \
00593 static void Class ## _ ## getterFunc ## _kill ();                                            \
00594 void Class ## _ ## getterFunc ## _kill ()                                                    \
00595 {                                                                                            \
00596   delete &Class::getterFunc ();                                                              \
00597 }                                                                                            \
00598 static void Class ## _ ## getterFunc ## _kill_array ();                                      \
00599 void Class ## _ ## getterFunc ## _kill_array ()                                              \
00600 {                                                                                            \
00601   delete [] &Class::getterFunc ();                                                           \
00602 }                                                                                            \
00603 }                                                                                            \
00604 Type &Class::getterFunc ()                                                                   \
00605 {                                                                                            \
00606   if (!var)                                                                                  \
00607   {                                                                                          \
00608     var = new Type initParam;                                                                \
00609     CS_DECLARE_STATIC_VARIABLE_REGISTRATION                                                  \
00610     CS_REGISTER_STATIC_FOR_DESTRUCTION (Class ## _ ## getterFunc ## kill_how);               \
00611   }                                                                                          \
00612   return *var;                                                                               \
00613 }
00614 #endif
00615 
00616 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF
00617 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF(Class,var,getterFunc,Type,initParam)   \
00618         CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,_kill)
00619 #endif
00620 
00621 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY
00622 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY(Class,var,getterFunc,Type,initParam)   \
00623         CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,_kill_array)
00624 #endif
00625 
00626 // The following define should only be enabled if you have defined
00627 // a special version of overloaded new that accepts two additional
00628 // parameters: a (void*) pointing to the filename and an int with the
00629 // line number. This is typically used for memory debugging.
00630 // In csutil/memdebug.cpp there is a memory debugger which can (optionally)
00631 // use this feature. Note that if CS_EXTENSIVE_MEMDEBUG is enabled while
00632 // the memory debugger is not the memory debugger will still provide the
00633 // needed overloaded operators so you can leave CS_EXTENSIVE_MEMDEBUG on in
00634 // that case and the only overhead will be a little more arguments to 'new'.
00635 // Do not enable CS_EXTENSIVE_MEMDEBUG if your platform or your own code
00636 // defines its own 'new' operator, since this version will interfere with your
00637 // own.
00638 #ifndef CS_DEBUG
00639 #  undef CS_EXTENSIVE_MEMDEBUG
00640 #endif
00641 #ifdef CS_EXTENSIVE_MEMDEBUG
00642 extern void* operator new (size_t s, void* filename, int line);
00643 extern void* operator new[] (size_t s, void* filename, int line);
00644 #define NEW new ((void*)__FILE__, __LINE__)
00645 #define new NEW
00646 #endif
00647 
00648 #ifdef CS_DEBUG
00649 #  if !defined (DEBUG_BREAK)
00650 #    if defined (PROC_X86)
00651 #      if defined (COMP_GCC)
00652 #        define DEBUG_BREAK     asm ("int $3")
00653 #      else
00654 #        define DEBUG_BREAK     _asm int 3
00655 #      endif
00656 #    else
00657 #      define DEBUG_BREAK       { static int x = 0; x /= x; }
00658 #    endif
00659 #  endif
00660 #  if !defined (CS_ASSERT)
00661 #    if defined (COMP_VC)
00662 #      define  CS_ASSERT(x) assert(x)
00663 #    else
00664 #      include <stdio.h>
00665 #      define CS_ASSERT(x)                                              \
00666          if (!(x))                                                      \
00667          {                                                              \
00668            fprintf (stderr, __FILE__ ":%d: failed assertion '%s'\n",\
00669              int(__LINE__), #x );                                       \
00670            DEBUG_BREAK;                                                 \
00671          }
00672 #    endif
00673 #  endif
00674 #else
00675 #  undef DEBUG_BREAK
00676 #  define DEBUG_BREAK
00677 #  undef CS_ASSERT
00678 #  define CS_ASSERT(x)
00679 #endif
00680 
00681 // Check if the csosdefs.h defined either CS_LITTLE_ENDIAN or CS_BIG_ENDIAN
00682 #if !defined (CS_LITTLE_ENDIAN) && !defined (CS_BIG_ENDIAN)
00683 #  error No CS_XXX_ENDIAN macro defined in your OS-specific csosdefs.h!
00684 #endif
00685 
00686 // Adjust some definitions contained in volatile.h
00687 #if defined (PROC_X86) && !defined (DO_NASM)
00688 #  undef NO_ASSEMBLER
00689 #  define NO_ASSEMBLER
00690 #endif
00691 
00692 #if !defined (PROC_X86) || defined (NO_ASSEMBLER)
00693 #  undef DO_MMX
00694 #  undef DO_NASM
00695 #endif
00696 
00697 // Use fast QInt and QRound on CPUs that are known to support it
00698 #if !defined (CS_NO_IEEE_OPTIMIZATIONS)
00699 #  if !defined (CS_IEEE_DOUBLE_FORMAT)
00700 #    if defined (PROC_X86) || defined (PROC_M68K)
00701 #      define CS_IEEE_DOUBLE_FORMAT
00702 #    endif
00703 #  endif
00704 #endif
00705 
00706 // gcc can perform usefull checking for printf/scanf format strings, just add
00707 // this define at the end of the function declaration
00708 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00709 #  define CS_GNUC_PRINTF( format_idx, arg_idx)          \
00710      __attribute__((format (printf, format_idx, arg_idx)))
00711 #  define CS_GNUC_SCANF( format_idx, arg_idx )                          \
00712      __attribute__((format (scanf, format_idx, arg_idx)))
00713 #else
00714 #  define CS_GNUC_PRINTF( format_idx, arg_idx )
00715 #  define CS_GNUC_SCANF( format_idx, arg_idx )
00716 #endif
00717 
00719 extern void (*fatal_exit) (int errorcode, bool canreturn);
00720 
00721 #endif // __CS_CSSYSDEFS_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000