Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

common.h

Go to the documentation of this file.
00001 /*
00002 This program is distributed under the terms of the 'MIT license'. The text
00003 of this licence follows...
00004 
00005 Copyright (c) 2004-2005 J.D.Medhurst (a.k.a. Tixy)
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023 THE SOFTWARE.
00024 */
00025 
00037 #ifndef __COMMON_H__
00038 #define __COMMON_H__
00039 
00040 
00041 #if _DEBUG
00042 #undef DEBUG
00043 #define DEBUG   
00044 #endif
00045 
00046 #if defined(_MSC_VER)
00047 // Compiling for Microsoft Visual C++...
00048 #define BREAKPOINT  { _asm int 3 }          
00049 #define IMPORT      __declspec(dllexport)   
00050 #define EXPORT      __declspec(dllexport)   
00051 #define ASSERT(c)   {if(!(c)) BREAKPOINT;}  
00052 typedef __int64 longlong;
00053 typedef unsigned __int64 ulonglong;
00054 
00055 // disable annoying warnings from MSVC...
00056 #pragma warning( disable : 4244 )   /* conversion from x to y, possible loss of data */
00057 #pragma warning( disable : 4514 )   /* unreferenced inline function has been removed */
00058 #pragma warning( disable : 4146 )   /* unary minus operator applied to unsigned type, result still unsigned */
00059 #pragma warning( disable : 4710 )   /* function x not inlined */
00060 #pragma warning( disable : 4355 )   /* 'this' : used in base member initializer list */
00061 #pragma warning( disable : 4512 )   /* assignment operator could not be generated */
00062 #pragma warning( disable : 4800 )   /* forcing value to bool 'true' or 'false' (performance warning) */
00063 
00064 #elif defined(__EPOC32__) || defined(__WINS__)
00065 // Compiling for Symbian OS...
00066 
00067 #define COMPILE_FOR_SYMBIAN
00068 #include <e32std.h>
00069 
00070 #if !defined(__BREAKPOINT)
00071 
00072 #if defined(__WINS__)
00073 
00074 #if defined(__WINSCW__)
00075 #define BREAKPOINT { _asm byte 0xcc }       
00076 #else
00077 #define BREAKPOINT { _asm int 3 }           
00078 #endif
00079 
00080 #else
00081 #define BREAKPOINT                          
00082 #endif
00083 
00084 #else
00085 #define BREAKPOINT  {__BREAKPOINT()}        
00086 #endif
00087 
00088 #define IMPORT      IMPORT_C                
00089 #define EXPORT      EXPORT_C                
00091 #undef ASSERT
00092 #define ASSERT(c)   {if(!(c)) BREAKPOINT;}  
00094 #if !defined(DEBUG) && defined(_DEBUG)
00095 #define DEBUG                               
00096 #endif
00097 
00098 typedef TInt64 longlong;
00099 typedef TUint64 ulonglong;
00100 
00101 
00102 #else
00103 // Compiling for unknown system...
00104 #define BREAKPOINT                          
00105 #define IMPORT                              
00106 #define EXPORT                              
00107 #define ASSERT(c) (void)(c)                 
00108 typedef long long longlong;
00109 typedef unsigned long long ulonglong;
00110 
00111 #endif
00112 
00113 
00114 #ifdef DEBUG
00115 #define ASSERT_DEBUG(c) ASSERT(c)   
00116 #else
00117 #define ASSERT_DEBUG(c)             
00118 #endif
00119 
00120 
00121 #ifndef ASSERT_COMPILE
00122 
00123 #define ASSERT_COMPILE(c) void assert_compile(int assert_compile[(c)?1:-1])
00124 #endif
00125 
00126 
00127 #ifndef NULL
00128 #define NULL 0      
00129 #endif
00130 
00131 
00141 typedef unsigned char       uint8_t;        
00142 typedef unsigned short      uint16_t;       
00143 typedef unsigned int        uint32_t;       
00144 typedef ulonglong           uint64_t;       
00145 typedef signed char         int8_t;         
00146 typedef signed short        int16_t;        
00147 typedef signed int          int32_t;        
00148 typedef longlong            int64_t;        
00149 typedef int                 intptr_t;       
00150 typedef unsigned int        uintptr_t;      
00151 typedef int64_t             intmax_t;       
00152 typedef uint64_t            uintmax_t;      
00153 typedef uintptr_t           size_t;         
00154 typedef intptr_t            ptrdiff_t;       // End of group
00157 
00158 ASSERT_COMPILE(sizeof(uintptr_t)==sizeof(void*));
00159 ASSERT_COMPILE(sizeof(intptr_t)==sizeof(void*));
00160 
00161 
00165 #define INT_BITS (sizeof(int)*8)
00166 
00167 
00172 #define LOG2(x) ((unsigned)(\
00173     (unsigned)(x)<=(unsigned)(1<< 0) ?  0 : (unsigned)(x)<=(unsigned)(1<< 1) ?  1 : (unsigned)(x)<=(unsigned)(1<< 2) ?  2 : (unsigned)(x)<=(unsigned)(1<< 3) ?  3 : \
00174     (unsigned)(x)<=(unsigned)(1<< 4) ?  4 : (unsigned)(x)<=(unsigned)(1<< 5) ?  5 : (unsigned)(x)<=(unsigned)(1<< 6) ?  6 : (unsigned)(x)<=(unsigned)(1<< 7) ?  7 : \
00175     (unsigned)(x)<=(unsigned)(1<< 8) ?  8 : (unsigned)(x)<=(unsigned)(1<< 9) ?  9 : (unsigned)(x)<=(unsigned)(1<<10) ? 10 : (unsigned)(x)<=(unsigned)(1<<11) ? 11 : \
00176     (unsigned)(x)<=(unsigned)(1<<12) ? 12 : (unsigned)(x)<=(unsigned)(1<<13) ? 13 : (unsigned)(x)<=(unsigned)(1<<14) ? 14 : (unsigned)(x)<=(unsigned)(1<<15) ? 15 : \
00177     (unsigned)(x)<=(unsigned)(1<<16) ? 16 : (unsigned)(x)<=(unsigned)(1<<17) ? 17 : (unsigned)(x)<=(unsigned)(1<<18) ? 18 : (unsigned)(x)<=(unsigned)(1<<19) ? 19 : \
00178     (unsigned)(x)<=(unsigned)(1<<20) ? 20 : (unsigned)(x)<=(unsigned)(1<<21) ? 21 : (unsigned)(x)<=(unsigned)(1<<22) ? 22 : (unsigned)(x)<=(unsigned)(1<<23) ? 23 : \
00179     (unsigned)(x)<=(unsigned)(1<<24) ? 24 : (unsigned)(x)<=(unsigned)(1<<25) ? 25 : (unsigned)(x)<=(unsigned)(1<<26) ? 26 : (unsigned)(x)<=(unsigned)(1<<27) ? 27 : \
00180     (unsigned)(x)<=(unsigned)(1<<28) ? 28 : (unsigned)(x)<=(unsigned)(1<<29) ? 29 : (unsigned)(x)<=(unsigned)(1<<30) ? 30 : (unsigned)(x)<=(unsigned)(1<<31) ? 31 : \
00181     32))
00182 
00183 
00184 #if __GNUC__<4
00185 
00188 #define offsetof(type,member)   ((size_t)(&((type*)256)->member)-256)
00189 #else
00190 #define offsetof(type,member)   __builtin_offsetof(type,member)
00191 #endif
00192 
00193 
00194 #if defined(__GNUC__) && defined(_ARM)
00195 
00199 #define dummy_return(type) register type _r0 asm("r0"); asm("" : "=r"(_r0)); return _r0
00200 
00201 #endif
00202 
00203 
00204 #ifndef COMPILE_FOR_SYMBIAN
00205 
00209 inline void* operator new(size_t, void* ptr) throw()
00210     { return ptr; }
00211 
00215 inline void operator delete(void*, void*) throw()
00216     { }
00217 
00218 #endif // !COMPILE_FOR_SYMBIAN
00219 
00220 
00221 #endif

Generated by  doxygen 1.4.4