| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# cssysdef.h

Go to the documentation of this file.

    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 #ifndef __CS_CSSYSDEF_H__
    00021 #define __CS_CSSYSDEF_H__
    00022
    00023 #define CSDEF_FRIEND
    00024 #include "csdef.h"
    00025 #undef CSDEF_FRIEND
    00026
    00036 /*
    00037  * Pull in platform-specific overrides of the requested functionality.
    00038  */
    00039 #include "csutil/csosdefs.h"
    00040
    00041 // Defaults for platforms that do not define their own.
    00042 #ifndef CS_VISIBILITY_DEFAULT
    00043 #  define CS_VISIBILITY_DEFAULT
    00044 #endif
    00045 #ifndef CS_VISIBILITY_HIDDEN
    00046 #  define CS_VISIBILITY_HIDDEN
    00047 #endif
    00048 #ifndef CS_EXPORT_SYM_DLL
    00049 #  define CS_EXPORT_SYM_DLL CS_VISIBILITY_DEFAULT
    00050 #endif
    00051 #ifndef CS_IMPORT_SYM_DLL
    00052 #  define CS_IMPORT_SYM_DLL extern
    00053 #endif
    00054 #ifndef CS_EXPORT_SYM
    00055 #  if defined(CS_BUILD_SHARED_LIBS)
    00056 #    define CS_EXPORT_SYM CS_VISIBILITY_DEFAULT
    00057 #  else
    00058 #    define CS_EXPORT_SYM
    00059 #  endif
    00060 #endif
    00061 #ifndef CS_IMPORT_SYM
    00062 #  define CS_IMPORT_SYM
    00063 #endif
    00064
    00065 #include "csextern.h"
    00066
    00067 /*
    00068  * Default definitions for requested functionality.  Platform-specific
    00069  * configuration files may override these.
    00070  */
    00071
    00072 #ifndef CS_FORCEINLINE
    00073 # ifdef CS_COMPILER_GCC
    00074 #  define CS_FORCEINLINE inline __attribute__((always_inline))
    00075 #  if (__GNUC__ == 3) && (__GNUC_MINOR__ == 4)
    00076     // Work around a gcc 3.4 issue where forcing inline doesn't always work
    00077 #   define CS_FORCEINLINE_TEMPLATEMETHOD inline
    00078 #  endif
    00079 # else
    00080 #  define CS_FORCEINLINE inline
    00081 # endif
    00082 #endif
    00083 #ifndef CS_FORCEINLINE_TEMPLATEMETHOD
    00084 # define CS_FORCEINLINE_TEMPLATEMETHOD CS_FORCEINLINE
    00085 #endif
    00086
    00091 #if defined(CS_COMPILER_MSVC)
    00092   #include <exception>
    00093   #if !_HAS_EXCEPTIONS
    00094     #define CS_NO_EXCEPTIONS
    00095   #endif
    00096 #elif defined(CS_COMPILER_GCC) && !defined(__EXCEPTIONS)
    00097   #define CS_NO_EXCEPTIONS
    00098 #endif
    00099
    00104 #ifndef CS_MAXPATHLEN
    00105 #define CS_MAXPATHLEN 1024
    00106 #endif
    00107 #include <stdio.h>
    00108 #ifdef CS_HAVE_SYS_PARAM_H
    00109 #include <sys/param.h>
    00110 #endif
    00111
    00118 #if defined(CS_COMPILER_GCC) && !defined(__STRICT_ANSI__)
    00119 // In GCC we are able to declare stack vars of dynamic size directly
    00120 #  define CS_ALLOC_STACK_ARRAY(type, var, size) \
    00121      type var [size]
    00122 #else
    00123 #  include <stdlib.h>
    00124 #  define CS_ALLOC_STACK_ARRAY(type, var, size) \
    00125      type *var = (type *)alloca ((size) * sizeof (type))
    00126 #  if defined(CS_COMPILER_GCC) && defined(__STRICT_ANSI__) && !defined(alloca)
    00127 #    define alloca(x) __builtin_alloca(x)
    00128 #  endif
    00129 #endif
    00130
    00134 #ifndef CS_TEMP_DIR
    00135 #  if defined(CS_PLATFORM_UNIX)
    00136 #    define CS_TEMP_DIR "/tmp/"
    00137 #  else
    00138 #    define CS_TEMP_DIR ""
    00139 #  endif
    00140 #endif
    00141
    00145 #ifndef CS_TEMP_FILE
    00146 #  if defined(CS_PLATFORM_UNIX)
    00147 #    define CS_TEMP_FILE "cs%lud.tmp", (unsigned long)getpid()
    00148 #  else
    00149 #    define CS_TEMP_FILE "$cs$.tmp"
    00150 #  endif
    00151 #endif
    00152
    00176 #define CS_HEADER_GLOBAL(X,Y) CS_HEADER_GLOBAL_COMPOSE(X,Y)
    00177 #define CS_HEADER_GLOBAL_COMPOSE(X,Y) <X/Y>
    00178
    00191 #define CS_HEADER_LOCAL(X,Y) CS_HEADER_LOCAL_COMPOSE1(X,Y)
    00192 #define CS_HEADER_LOCAL_COMPOSE1(X,Y) CS_HEADER_LOCAL_COMPOSE2(X/Y)
    00193 #define CS_HEADER_LOCAL_COMPOSE2(X) #X
    00194
    00195
    00201 #if !defined(CS_EXPORTED_FUNCTION)
    00202 #  if defined(CS_STATIC_LINKED)
    00203 #    define CS_EXPORTED_FUNCTION extern "C"
    00204 #  else
    00205 #    define CS_EXPORTED_FUNCTION extern "C" CS_EXPORT_SYM_DLL
    00206 #  endif
    00207 #endif
    00208
    00220 #if !defined(CS_EXPORTED_NAME)
    00221 #  define CS_EXPORTED_NAME(Prefix, Suffix) Prefix ## Suffix
    00222 #endif
    00223
    00224 #ifndef CS_IMPLEMENT_PLATFORM_PLUGIN
    00225 #  define CS_IMPLEMENT_PLATFORM_PLUGIN
    00226 #endif
    00227
    00228 #ifndef CS_IMPLEMENT_PLATFORM_APPLICATION
    00229 #  define CS_IMPLEMENT_PLATFORM_APPLICATION
    00230 #endif
    00231
    00238 #ifndef CS_INITIALIZE_PLATFORM_APPLICATION
    00239 #  define CS_INITIALIZE_PLATFORM_APPLICATION /* */
    00240 /*
    00241   This definition may seem odd, but it's here for doxygen's sake, which
    00242   apparently fails to document empty macro definitions.
    00243  */
    00244 #endif
    00245
    00246 typedef void (*csStaticVarCleanupFN) (void (*p)());
    00247 extern csStaticVarCleanupFN csStaticVarCleanup;
    00248
    00249 #ifndef CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION
    00250 #  define CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION(Name)              \
    00251 void Name (void (*p)())                                                \
    00252 {                                                                      \
    00253   static void (**a)() = 0;                                             \
    00254   static int lastEntry = 0;                                            \
    00255   static int maxEntries = 0;                                           \
    00256                                                                        \
    00257   if (p != 0)                                                          \
    00258   {                                                                    \
    00259     if (lastEntry >= maxEntries)                                       \
    00260     {                                                                  \
    00261       maxEntries += 10;                                                \
    00262       if (a == 0)                                                      \
    00263         a = (void (**)())malloc(maxEntries * sizeof(void*));           \
    00264       else                                                             \
    00265         a = (void (**)())realloc(a, maxEntries * sizeof(void*));       \
    00266     }                                                                  \
    00267     a[lastEntry++] = p;                                                \
    00268   }                                                                    \
    00269   else if (a != 0)                                                     \
    00270   {                                                                    \
    00271     for (int i = lastEntry - 1; i >= 0; i--)                           \
    00272       a[i] ();                                                         \
    00273     free (a);                                                          \
    00274     a = 0;                                                             \
    00275     lastEntry = 0;                                                     \
    00276     maxEntries = 0;                                                    \
    00277   }                                                                    \
    00278 }
    00279 #endif
    00280
    00281 #ifndef CS_DEFINE_STATIC_VARIABLE_REGISTRATION
    00282 #  define CS_DEFINE_STATIC_VARIABLE_REGISTRATION(func) \
    00283     csStaticVarCleanupFN csStaticVarCleanup = &func
    00284 #endif
    00285
    00286 #ifndef CS_DECLARE_STATIC_VARIABLE_REGISTRATION
    00287 #  define CS_DECLARE_STATIC_VARIABLE_REGISTRATION(func) \
    00288     void func (void (*p)())
    00289 #endif
    00290
    00291 #ifndef CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION
    00292 #  define CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION               \
    00293     CS_CRYSTALSPACE_EXPORT                                              \
    00294     CS_DECLARE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil);
    00295 #endif
    00296
    00297 /* scfStaticallyLinked - Flag indicating whether external linkage was used when
    00298  * building the application. Determines whether SCF scans for plugins at
    00299  * startup.
    00300  */
    00304 #if defined(CS_BUILD_SHARED_LIBS)
    00305 #  define CS_DEFINE_STATICALLY_LINKED_FLAG
    00306 #elif defined(CS_STATIC_LINKED)
    00307 #  define CS_DEFINE_STATICALLY_LINKED_FLAG  bool scfStaticallyLinked = true;
    00308 #else
    00309 #  define CS_DEFINE_STATICALLY_LINKED_FLAG  bool scfStaticallyLinked = false;
    00310 #endif
    00311
    00312
    00332 #ifndef CS_IMPLEMENT_FOREIGN_DLL
    00333 #  if defined(CS_BUILD_SHARED_LIBS)
    00334 #    define CS_IMPLEMENT_FOREIGN_DLL                                        \
    00335        CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION(csStaticVarCleanup_local); \
    00336        CS_DEFINE_STATICALLY_LINKED_FLAG                                     \
    00337        CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_local);
    00338 #  else
    00339 #    define CS_IMPLEMENT_FOREIGN_DLL                                        \
    00340        CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION                      \
    00341        CS_DEFINE_STATICALLY_LINKED_FLAG                                     \
    00342        CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil);
    00343 #  endif
    00344 #endif
    00345
    00354 #if defined(CS_STATIC_LINKED)
    00355
    00356 #  ifndef CS_IMPLEMENT_PLUGIN
    00357 #  define CS_IMPLEMENT_PLUGIN                                           \
    00358           CS_IMPLEMENT_PLATFORM_PLUGIN
    00359 #  endif
    00360
    00361 #elif !defined(CS_BUILD_SHARED_LIBS)
    00362
    00363 #  ifndef CS_IMPLEMENT_PLUGIN
    00364 #  define CS_IMPLEMENT_PLUGIN                                           \
    00365           CS_IMPLEMENT_PLATFORM_PLUGIN                                  \
    00366           CS_DEFINE_STATICALLY_LINKED_FLAG                              \
    00367           CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION               \
    00368           CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil);
    00369 #  endif
    00370
    00371 #else
    00372
    00373 #  ifndef CS_IMPLEMENT_PLUGIN
    00374 #  define CS_IMPLEMENT_PLUGIN                                           \
    00375    CS_DEFINE_STATICALLY_LINKED_FLAG                                     \
    00376    CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION(csStaticVarCleanup_local)  \
    00377    CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_local);   \
    00378    CS_IMPLEMENT_PLATFORM_PLUGIN
    00379 #  endif
    00380
    00381 #endif
    00382
    00391 #ifndef CS_IMPLEMENT_APPLICATION
    00392 #  define CS_IMPLEMENT_APPLICATION                                      \
    00393   CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION                       \
    00394   CS_DEFINE_STATICALLY_LINKED_FLAG                                      \
    00395   CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil);   \
    00396   CS_IMPLEMENT_PLATFORM_APPLICATION
    00397 #endif
    00398
    00402 #ifndef CS_REGISTER_STATIC_FOR_DESTRUCTION
    00403 #define CS_REGISTER_STATIC_FOR_DESTRUCTION(getterFunc)\
    00404         csStaticVarCleanup (getterFunc);
    00405 #endif
    00406
    00410 #ifndef CS_STATIC_VARIABLE_CLEANUP
    00411 #define CS_STATIC_VARIABLE_CLEANUP  \
    00412         csStaticVarCleanup (0);
    00413 #endif
    00414
    00427 #ifndef CS_IMPLEMENT_STATIC_VAR_EXT
    00428 #define CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,kill_how) \
    00429 namespace {                                                            \
    00430 static Type *getterFunc ## _v=0;                                        \
    00431 static Type* getterFunc ();                                             \
    00432 static void getterFunc ## _kill ();                                     \
    00433 static void getterFunc ## _kill_array ();                               \
    00434 void getterFunc ## _kill ()                                             \
    00435 {                                                                       \
    00436   (void)(&getterFunc ## _kill_array);                                   \
    00437   delete getterFunc ## _v;                                              \
    00438   getterFunc ## _v = 0;                                                 \
    00439 }                                                                       \
    00440 void getterFunc ## _kill_array ()                                       \
    00441 {                                                                       \
    00442   (void)(&getterFunc ## _kill);                                         \
    00443   delete [] getterFunc ## _v;                                           \
    00444   getterFunc ## _v = 0;                                                 \
    00445 }                                                                       \
    00446 Type* getterFunc ()                                                     \
    00447 {                                                                       \
    00448   if (!getterFunc ## _v)                                                \
    00449   {                                                                     \
    00450     getterFunc ## _v = new Type initParam;                              \
    00451     csStaticVarCleanup (getterFunc ## kill_how);                        \
    00452   }                                                                     \
    00453   return getterFunc ## _v;                                              \
    00454 }                                                                       \
    00455 }
    00456 #endif
    00457
    00458 #ifndef CS_IMPLEMENT_STATIC_VAR
    00459 #define CS_IMPLEMENT_STATIC_VAR(getterFunc,Type,initParam) \
    00460  CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill)
    00461 #endif
    00462
    00463 #ifndef CS_IMPLEMENT_STATIC_VAR_ARRAY
    00464 #define CS_IMPLEMENT_STATIC_VAR_ARRAY(getterFunc,Type,initParam) \
    00465  CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill_array)
    00466 #endif
    00467
    00475 #ifndef CS_DECLARE_STATIC_CLASSVAR
    00476 #define CS_DECLARE_STATIC_CLASSVAR(var,getterFunc,Type)       \
    00477 static Type *var;                                             \
    00478 static Type *getterFunc ();                                   \
    00479 static void getterFunc ## _kill ();                           \
    00480 static void getterFunc ## _kill_array ();
    00481 #endif
    00482
    00483 #ifndef CS_DECLARE_STATIC_CLASSVAR_REF
    00484 #define CS_DECLARE_STATIC_CLASSVAR_REF(var,getterFunc,Type)   \
    00485 static Type *var;                                             \
    00486 static Type &getterFunc ();                                   \
    00487 static void getterFunc ## _kill ();                           \
    00488 static void getterFunc ## _kill_array ();
    00489 #endif
    00490
    00501 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_EXT
    00502 #define CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,\
    00503   kill_how)                                                     \
    00504 Type *Class::var = 0;                                           \
    00505 void Class::getterFunc ## _kill ()                              \
    00506 {                                                               \
    00507   delete getterFunc ();                                         \
    00508   var = 0;                                                      \
    00509 }                                                               \
    00510 void Class::getterFunc ## _kill_array ()                        \
    00511 {                                                               \
    00512   delete [] getterFunc ();                                      \
    00513   var = 0;                                                      \
    00514 }                                                               \
    00515 Type* Class::getterFunc ()                                      \
    00516 {                                                               \
    00517   if (!var)                                                     \
    00518   {                                                             \
    00519     var = new Type initParam;                                   \
    00520     csStaticVarCleanup (getterFunc ## kill_how);                \
    00521   }                                                             \
    00522   return var;                                                   \
    00523 }
    00524 #endif
    00525
    00526 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR
    00527 #define CS_IMPLEMENT_STATIC_CLASSVAR(Class,var,getterFunc,Type,initParam) \
    00528   CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,_kill)
    00529 #endif
    00530
    00531 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY
    00532 #define CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY(Class,var,getterFunc,Type,\
    00533   initParam) \
    00534   CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,\
    00535     _kill_array)
    00536 #endif
    00537
    00538 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT
    00539 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,\
    00540   initParam,kill_how) \
    00541 Type *Class::var = 0;                                          \
    00542 void Class::getterFunc ## _kill ()                             \
    00543 {                                                              \
    00544   delete &getterFunc ();                                       \
    00545   var = 0;                                                     \
    00546 }                                                              \
    00547   void Class::getterFunc ## _kill_array ()                     \
    00548 {                                                              \
    00549   delete [] &getterFunc ();                                    \
    00550   var = 0;                                                     \
    00551 }                                                              \
    00552 Type &Class::getterFunc ()                                     \
    00553 {                                                              \
    00554   if (!var)                                                    \
    00555   {                                                            \
    00556     var = new Type initParam;                                  \
    00557     csStaticVarCleanup (getterFunc ## kill_how);               \
    00558   }                                                            \
    00559   return *var;                                                 \
    00560 }
    00561 #endif
    00562
    00563 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF
    00564 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF(Class,var,getterFunc,Type,initParam)\
    00565   CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,\
    00566     initParam,_kill)
    00567 #endif
    00568
    00569 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY
    00570 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY(Class,var,getterFunc,Type,\
    00571   initParam) \
    00572   CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,\
    00573     _kill_array)
    00574 #endif
    00575
    00580 #if defined(CS_COMPILER_GCC)
    00581 #  define CS_FUNCTION_NAME              __PRETTY_FUNCTION__
    00582 #elif defined(__FUNCTION__)
    00583 #  define CS_FUNCTION_NAME              __FUNCTION__
    00584 #else
    00585 #  define CS_FUNCTION_NAME              "<?\?\?>"
    00586 #endif
    00587
    00588 /* Include now, if it's included later, the malloc re#definition below may
    00589  * interfere with that header. */
    00590 #include <stdlib.h>
    00591 #ifdef CS_HAVE_MALLOC_H
    00592 #include <malloc.h>
    00593 #endif
    00594 #include <new>
    00595
    00602 CS_FORCEINLINE void* platform_malloc (size_t n)
    00603 { return malloc (n); }
    00604 CS_FORCEINLINE void platform_free (void* p)
    00605 { return free (p); }
    00606 CS_FORCEINLINE void* platform_realloc (void* p, size_t n)
    00607 { return realloc (p, n); }
    00608 CS_FORCEINLINE void* platform_calloc (size_t n, size_t s)
    00609 { return calloc (n, s); }
    00610
    00611 namespace CS
    00612 {
    00613   struct AllocPlatform {};
    00614   extern CS_CRYSTALSPACE_EXPORT const AllocPlatform allocPlatform;
    00615 }
    00620 extern CS_CRYSTALSPACE_EXPORT void* operator new (size_t s,
    00621   const CS::AllocPlatform&) throw();
    00626 extern CS_CRYSTALSPACE_EXPORT void* operator new[] (size_t s,
    00627   const CS::AllocPlatform&) throw();
    00628 extern CS_CRYSTALSPACE_EXPORT void operator delete (void* p,
    00629   const CS::AllocPlatform&) throw();
    00630 extern CS_CRYSTALSPACE_EXPORT void operator delete[] (void* p,
    00631   const CS::AllocPlatform&) throw();
    00633
    00634 #ifndef CS_NO_PTMALLOC
    00635
    00636
    00640 extern CS_CRYSTALSPACE_EXPORT void* ptmalloc (size_t n);
    00641 extern CS_CRYSTALSPACE_EXPORT void ptfree (void* p);
    00642 extern CS_CRYSTALSPACE_EXPORT void* ptrealloc (void* p, size_t n);
    00643 extern CS_CRYSTALSPACE_EXPORT void* ptcalloc (size_t n, size_t s);
    00645
    00651 CS_FORCEINLINE void* cs_malloc (size_t n)
    00652 { return ptmalloc (n); }
    00653 CS_FORCEINLINE void cs_free (void* p)
    00654 { ptfree (p); }
    00655 CS_FORCEINLINE void* cs_realloc (void* p, size_t n)
    00656 { return ptrealloc (p, n); }
    00657 CS_FORCEINLINE void* cs_calloc (size_t n, size_t s)
    00658 { return ptcalloc (n, s); }
    00660
    00678
    00683 #define CS_NO_NEW_OVERRIDE
    00684 #define CS_NO_MALLOC_OVERRIDE
    00685
    00686 #ifndef CS_NO_MALLOC_OVERRIDE
    00687 #define malloc          cs_malloc
    00688 #define free            cs_free
    00689 #define realloc         cs_realloc
    00690 #define calloc          cs_calloc
    00691 #endif // CS_NO_MALLOC_OVERRIDE
    00692
    00693 #ifndef CS_NO_NEW_OVERRIDE
    00694
    00695 #if !defined(CS_MEMORY_TRACKER) && !defined(CS_MEMORY_TRACKER_IMPLEMENT) \
    00696   && !defined(CS_EXTENSIVE_MEMDEBUG) && !defined(CS_EXTENSIVE_MEMDEBUG_IMPLEMENT)
    00697
    00698 #ifndef CS_NO_EXCEPTIONS
    00699 CS_FORCEINLINE void* operator new (size_t s) throw (std::bad_alloc)
    00700 {
    00701   void* p = ptmalloc (s);
    00702   if (!p) throw std::bad_alloc();
    00703   return p;
    00704 }
    00705 CS_FORCEINLINE void* operator new[] (size_t s) throw (std::bad_alloc)
    00706 {
    00707   void* p = ptmalloc (s);
    00708   if (!p) throw std::bad_alloc();
    00709   return p;
    00710 }
    00711 #else
    00712 CS_FORCEINLINE void* operator new (size_t s) throw ()
    00713 {
    00714   return ptmalloc (s);
    00715 }
    00716 CS_FORCEINLINE void* operator new[] (size_t s) throw ()
    00717 {
    00718   return ptmalloc (s);
    00719 }
    00720 #endif
    00721
    00722 CS_FORCEINLINE void operator delete (void* p) throw()
    00723 { ptfree (p); }
    00724 CS_FORCEINLINE void operator delete[] (void* p) throw()
    00725 { ptfree (p); }
    00726
    00727 CS_FORCEINLINE void* operator new (size_t s, const std::nothrow_t&) throw()
    00728 { return ptmalloc (s); }
    00729 CS_FORCEINLINE void* operator new[] (size_t s, const std::nothrow_t&) throw()
    00730 { return ptmalloc (s); }
    00731 CS_FORCEINLINE void operator delete (void* p, const std::nothrow_t&) throw()
    00732 { ptfree (p); }
    00733 CS_FORCEINLINE void operator delete[] (void* p, const std::nothrow_t&) throw()
    00734 { ptfree (p); }
    00735
    00736 #endif /* !defined(CS_MEMORY_TRACKER) && !defined(CS_MEMORY_TRACKER_IMPLEMENT)
    00737   && !defined(CS_EXTENSIVE_MEMDEBUG) && !defined(CS_EXTENSIVE_MEMDEBUG_IMPLEMENT) */
    00738 #endif // CS_NO_NEW_OVERRIDE
    00739
    00740 #else // CS_NO_PTMALLOC
    00741 CS_FORCEINLINE void* cs_malloc (size_t n)
    00742 { return platform_malloc (n); }
    00743 CS_FORCEINLINE void cs_free (void* p)
    00744 { platform_free (p); }
    00745 CS_FORCEINLINE void* cs_realloc (void* p, size_t n)
    00746 { return platform_realloc (p, n); }
    00747 CS_FORCEINLINE void* cs_calloc (size_t n, size_t s)
    00748 { return platform_calloc (n, s); }
    00749 #endif // CS_NO_PTMALLOC
    00750
    00751
    00752 #ifdef CS_USE_CUSTOM_ISDIR
    00753 static inline bool isdir (const char *path, struct dirent *de)
    00754 {
    00755   int pathlen = strlen (path);
    00756   char* fullname = new char[pathlen + 2 + strlen (de->d_name)];
    00757   memcpy (fullname, path, pathlen + 1);
    00758   if ((pathlen) && (fullname[pathlen-1] != CS_PATH_SEPARATOR))
    00759   {
    00760     fullname[pathlen++] = CS_PATH_SEPARATOR;
    00761     fullname[pathlen] = 0;
    00762   }
    00763   strcat (&fullname [pathlen], de->d_name);
    00764   struct stat st;
    00765   stat (fullname, &st);
    00766   delete[] fullname;
    00767   return ((st.st_mode & S_IFMT) == S_IFDIR);
    00768 }
    00769 #endif
    00770
    00771
    00772 // The following define should only be enabled if you have defined
    00773 // a special version of overloaded new that accepts two additional
    00774 // parameters: a (void*) pointing to the filename and an int with the
    00775 // line number. This is typically used for memory debugging.
    00776 // In csutil/memdebug.cpp there is a memory debugger which can (optionally)
    00777 // use this feature. Note that if CS_EXTENSIVE_MEMDEBUG is enabled while
    00778 // the memory debugger is not the memory debugger will still provide the
    00779 // needed overloaded operators so you can leave CS_EXTENSIVE_MEMDEBUG on in
    00780 // that case and the only overhead will be a little more arguments to 'new'.
    00781 // Do not enable CS_EXTENSIVE_MEMDEBUG if your platform or your own code
    00782 // defines its own 'new' operator, since this version will interfere with your
    00783 // own.
    00784 // CS_MEMORY_TRACKER is treated like CS_EXTENSIVE_MEMDEBUG here.
    00785 // Same for CS_REF_TRACKER.
    00786 #ifndef CS_DEBUG
    00787 #  undef CS_EXTENSIVE_MEMDEBUG
    00788 #  undef CS_REF_TRACKER
    00789 #else
    00790 #  if defined(CS_EXTENSIVE_MEMDEBUG) && defined(CS_MEMORY_TRACKER)
    00791 #    error Do not use CS_EXTENSIVE_MEMDEBUG and CS_MEMORY_TRACKER together!
    00792 #  endif
    00793 #endif
    00794 #if defined(CS_EXTENSIVE_MEMDEBUG) || defined(CS_MEMORY_TRACKER)
    00795 extern void* CS_CRYSTALSPACE_EXPORT operator new (size_t s,
    00796   void* filename, int line);
    00797 inline void operator delete (void* p, void*, int) { operator delete (p); }
    00798 extern void* CS_CRYSTALSPACE_EXPORT operator new[] (size_t s,
    00799   void* filename, int line);
    00800 inline void operator delete[] (void* p, void*, int) { operator delete[] (p); }
    00801
    00802 inline void* operator new (size_t s)
    00803 { return operator new (s, (void*)__FILE__, 0); }
    00804 inline void* operator new[] (size_t s)
    00805 { return operator new (s, (void*)__FILE__, 0); }
    00806
    00807 #define CS_EXTENSIVE_MEMDEBUG_NEW new ((void*)CS_FUNCTION_NAME, __LINE__)
    00808 #define new CS_EXTENSIVE_MEMDEBUG_NEW
    00809 #endif
    00810
    00811 #ifdef CS_DEBUG
    00812 #  if !defined (CS_DEBUG_BREAK)
    00813 #    if defined (CS_PLATFORM_WIN32)
    00814 #      define CS_DEBUG_BREAK ::DebugBreak()
    00815 #    elif defined (CS_PROCESSOR_X86)
    00816 #      if defined (CS_COMPILER_GCC)
    00817 #        define CS_DEBUG_BREAK asm ("int $3")
    00818 #      else
    00819 #        define CS_DEBUG_BREAK _asm int 3
    00820 #      endif
    00821 #    else
    00822 #      define CS_DEBUG_BREAK { static int x = 0; x /= x; }
    00823 #    endif
    00824 #  endif
    00825 #  if !defined (CS_ASSERT_MSG)
    00826     namespace CS
    00827     {
    00828       namespace Debug
    00829       {
    00830         extern void CS_CRYSTALSPACE_EXPORT AssertMessage (const char* expr,
    00831           const char* filename, int line, const char* msg = 0);
    00832       } // namespace Debug
    00833     } // namespace CS
    00834 #   define CS_ASSERT_MSG(msg,x)                                         \
    00835       if (!(x)) CS::Debug::AssertMessage (#x, __FILE__, __LINE__, msg);
    00836 #  endif
    00837 #  if !defined (CS_ASSERT)
    00838 #    define CS_ASSERT(x)        CS_ASSERT_MSG(0, x)
    00839 #  endif
    00840 #else
    00841 #  undef  CS_DEBUG_BREAK
    00842 #  define CS_DEBUG_BREAK
    00843 #  undef  CS_ASSERT
    00844 #  define CS_ASSERT(x)          (void)0
    00845 #  undef  CS_ASSERT_MSG
    00846 #  define CS_ASSERT_MSG(m,x)    (void)0
    00847 #endif
    00848
    00875 #if !defined(CS_DEPRECATED_METHOD) || defined(DOXYGEN_RUN)
    00876 #  if defined(CS_COMPILER_MSVC)
    00877 #    define CS_DEPRECATED_METHOD        __declspec(deprecated)
    00878       /* Unfortunately, MSVC is overzealous with warnings; it even emits one
    00879          when a deprecated method is overridden, e.g. when implementing an
    00880          interface method.
    00881          To work around this, use msvc_deprecated_warn_off.h/
    00882          msvc_deprecated_warn_on.h. */
    00883 #  else
    00884 #    define CS_DEPRECATED_METHOD
    00885 #  endif
    00886 #endif
    00887
    00892 #if !defined(CS_DEPRECATED_METHOD_MSG) || defined(DOXYGEN_RUN)
    00893 #  if defined(CS_COMPILER_MSVC) && _MSC_VER >= 1400
    00894 #    define CS_DEPRECATED_METHOD_MSG(msg) __declspec(deprecated(msg))
    00895 #  else
    00896 #    define CS_DEPRECATED_METHOD_MSG(msg) CS_DEPRECATED_METHOD
    00897 #  endif
    00898 #endif
    00899
    00910 #if !defined(CS_DEPRECATED_TYPE) || defined(DOXYGEN_RUN)
    00911 #  if defined(CS_COMPILER_MSVC)
    00912 #    define CS_DEPRECATED_TYPE __declspec(deprecated)
    00913 #  else
    00914 #    define CS_DEPRECATED_TYPE
    00915 #  endif
    00916 #endif
    00917
    00922 #if !defined(CS_DEPRECATED_TYPE_MSG) || defined(DOXYGEN_RUN)
    00923 #  if defined(CS_COMPILER_MSVC) && _MSC_VER >= 1400
    00924 #    define CS_DEPRECATED_TYPE_MSG(msg) __declspec(deprecated(msg))
    00925 #  else
    00926 #    define CS_DEPRECATED_TYPE_MSG(msg) CS_DEPRECATED_TYPE
    00927 #  endif
    00928 #endif
    00929
    00941 #if !defined(CS_CONST_METHOD) || defined(DOXYGEN_RUN)
    00942 #define CS_CONST_METHOD
    00943 #endif
    00944
    00957 #if !defined(CS_PURE_METHOD) || defined(DOXYGEN_RUN)
    00958 #define CS_PURE_METHOD
    00959 #endif
    00960
    00961 // Check if the csosdefs.h defined either CS_LITTLE_ENDIAN or CS_BIG_ENDIAN
    00962 #if !defined (CS_LITTLE_ENDIAN) && !defined (CS_BIG_ENDIAN)
    00963 #  error No CS_XXX_ENDIAN macro defined in your OS-specific csosdefs.h!
    00964 #endif
    00965
    00966 /*
    00967  * This is a bit of overkill but if you're sure your CPU doesn't require
    00968  * strict alignment add your CPU to the !defined below to get slightly
    00969  * smaller and faster code in some cases.
    00970  *
    00971  * \todo In the future, this should be moved to csconfig.h and determined as
    00972  * part of the configuration process.
    00973  */
    00974 #if defined (CS_PROCESSOR_SPARC)
    00975 #  define CS_STRICT_ALIGNMENT
    00976 #endif
    00977
    00978 // Adjust some definitions contained in csconfig.h
    00979 #if !defined (CS_PROCESSOR_X86) || !defined (CS_HAVE_NASM)
    00980 #  undef CS_HAVE_MMX
    00981 #  undef CS_HAVE_NASM
    00982 #endif
    00983
    00984 // Use special knowledge of IEEE float format in some cases for CPU's that are
    00985 // known to support it
    00986 #if !defined (CS_IEEE_DOUBLE_FORMAT)
    00987 #  if defined (CS_PROCESSOR_X86) || \
    00988       defined (CS_PROCESSOR_POWERPC) || \
    00989       defined (CS_PROCESSOR_MIPS) || \
    00990       defined (CS_PROCESSOR_SPARC) || \
    00991       defined (CS_PROCESSOR_ALPHA) || \
    00992       defined (CS_PROCESSOR_M68K)
    00993 #    define CS_IEEE_DOUBLE_FORMAT
    00994 #  endif
    00995 #endif
    00996
    00997 // gcc can perform usefull checking for printf/scanf format strings, just add
    00998 // this define at the end of the function declaration
    00999 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
    01000 #  define CS_GNUC_PRINTF(format_idx, arg_idx) \
    01001      __attribute__((format (__printf__, format_idx, arg_idx)))
    01002 #  define CS_GNUC_SCANF(format_idx, arg_idx) \
    01003      __attribute__((format (__scanf__, format_idx, arg_idx)))
    01004 // Unfortunately, gcc doesn't support format argument checking for wide strings
    01005 #  define CS_GNUC_WPRINTF(format_idx, arg_idx) \
    01006      /*__attribute__((format (__wprintf__, format_idx, arg_idx)))*/
    01007 #  define CS_GNUC_WSCANF(format_idx, arg_idx) \
    01008      /*__attribute__((format (__wscanf__, format_idx, arg_idx)))*/
    01009 #else
    01010 #  define CS_GNUC_PRINTF(format_idx, arg_idx)
    01011 #  define CS_GNUC_SCANF(format_idx, arg_idx)
    01012 #  define CS_GNUC_WPRINTF(format_idx, arg_idx)
    01013 #  define CS_GNUC_WSCANF(format_idx, arg_idx)
    01014 #endif
    01015
    01016 // Remove __attribute__ on non GNUC compilers.
    01017 #ifndef __GNUC__
    01018 #define __attribute__(x)
    01019 #endif
    01020
    01021 // Support for alignment and packing of structures.
    01022 #if !defined(CS_STRUCT_ALIGN_4BYTE_BEGIN)
    01023 #  if defined(__GNUC__) && defined(CS_STRICT_ALIGNMENT)
    01024 #    define CS_STRUCT_ALIGN_4BYTE_BEGIN
    01025 #    define CS_STRUCT_ALIGN_4BYTE_END __attribute__ ((aligned(4)))
    01026 #  else
    01027 #    define CS_STRUCT_ALIGN_4BYTE_BEGIN
    01028 #    define CS_STRUCT_ALIGN_4BYTE_END
    01029 #  endif
    01030 #endif
    01031
    01032 #if defined(CS_COMPILER_MSVC)
    01033   #define CS_ALIGNED_MEMBER(Member, Align)                              \
    01034     __declspec(align(Align)) Member
    01035 #elif defined(CS_COMPILER_GCC)
    01036
    01048   #define CS_ALIGNED_MEMBER(Member, Align)                              \
    01049     Member __attribute((aligned(Align)))
    01050 #else
    01051   #define CS_ALIGNED_MEMBER(Member, Align)      Member
    01052 #endif
    01053
    01054 // Macro used to define static implicit pointer conversion function.
    01055 // Only use within a class declaration.
    01056 #ifndef _CS_IMPLICITPTRCAST_NAME
    01057 #  define _CS_IMPLICITPTRCAST_NAME __ImplicitPtrCast
    01058 #endif
    01059
    01081 #define CS_IMPLEMENT_IMPLICIT_PTR_CAST(classname) \
    01082   inline static classname* _CS_IMPLICITPTRCAST_NAME (classname* ptr) \
    01083   { \
    01084     return ptr;\
    01085   }
    01086
    01095 #define CS_IMPLICIT_PTR_CAST(classname, ptr) \
    01096   (classname::_CS_IMPLICITPTRCAST_NAME(ptr))
    01097
    01101 #ifdef CS_HAVE_VA_COPY
    01102 #  define CS_VA_COPY(dest, src)         va_copy(dest, src)
    01103 #else
    01104 #  ifdef CS_HAVE___VA_COPY
    01105 #    define CS_VA_COPY(dest, src)       __va_copy(dest, src)
    01106 #  else
    01107 #    define CS_VA_COPY(dest, src)       dest = src;
    01108 #  endif
    01109 #endif
    01110
    01111 #define CS_STRING_TO_WIDE_(x)   L ## x
    01112
    01119 #define CS_STRING_TO_WIDE(x)    CS_STRING_TO_WIDE_(x)
    01120
    01121 #ifdef PACKAGE_NAME
    01122 # define CS_NAMESPACE_PACKAGE_NAME       PACKAGE_NAME
    01123 #else
    01124 # define CS_NAMESPACE_PACKAGE_NAME       CS
    01125 #endif
    01126
    01150 #define CS_PLUGIN_NAMESPACE_BEGIN(name)                                     \
    01151   namespace CS_NAMESPACE_PACKAGE_NAME { namespace Plugin { namespace name
    01152 #define CS_PLUGIN_NAMESPACE_END(name)                                       \
    01153   } }
    01154 #define CS_PLUGIN_NAMESPACE_NAME(name)                                      \
    01155   CS_NAMESPACE_PACKAGE_NAME::Plugin::name
    01156
    01158 #endif // __CS_CSSYSDEF_H__