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-2009 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 ASSERT(c)   {if(!(c)) BREAKPOINT;}  
00050 typedef __int64 longlong;
00051 typedef unsigned __int64 ulonglong;
00052 
00053 // disable annoying warnings from MSVC...
00054 #pragma warning( disable : 4244 )   /* conversion from x to y, possible loss of data */
00055 #pragma warning( disable : 4514 )   /* unreferenced inline function has been removed */
00056 #pragma warning( disable : 4146 )   /* unary minus operator applied to unsigned type, result still unsigned */
00057 #pragma warning( disable : 4710 )   /* function x not inlined */
00058 #pragma warning( disable : 4355 )   /* 'this' : used in base member initializer list */
00059 #pragma warning( disable : 4512 )   /* assignment operator could not be generated */
00060 #pragma warning( disable : 4800 )   /* forcing value to bool 'true' or 'false' (performance warning) */
00061 
00062 #elif defined(__EPOC32__) || defined(__WINS__)
00063 // Compiling for Symbian OS...
00064 
00065 #define COMPILE_FOR_SYMBIAN
00066 #include <e32std.h>
00067 
00068 #if !defined(__BREAKPOINT)
00069 
00070 #if defined(__WINS__)
00071 
00072 #if defined(__WINSCW__)
00073 #define BREAKPOINT { _asm byte 0xcc }       
00074 #else
00075 #define BREAKPOINT { _asm int 3 }           
00076 #endif
00077 
00078 #else
00079 #define BREAKPOINT                          
00080 #endif
00081 
00082 #else
00083 #define BREAKPOINT  {__BREAKPOINT()}        
00084 #endif
00085 
00086 #undef ASSERT
00087 #define ASSERT(c)   {if(!(c)) BREAKPOINT;}  
00089 #if !defined(DEBUG) && defined(_DEBUG)
00090 #define DEBUG                               
00091 #endif
00092 
00093 typedef TInt64 longlong;
00094 typedef TUint64 ulonglong;
00095 
00096 
00097 #else
00098 // Compiling for unknown system...
00099 #define BREAKPOINT                          
00101 extern int AssertFailed(const char* file, int line);
00102 #undef ASSERT
00103 #define ASSERT(c)   (void)((c)||AssertFailed(__FILE__,__LINE__)) 
00105 typedef long long longlong;
00106 typedef unsigned long long ulonglong;
00107 
00108 
00109 #endif
00110 
00111 
00112 #ifdef DEBUG
00113 #define ASSERT_DEBUG(c) ASSERT(c)   
00114 #else
00115 #define ASSERT_DEBUG(c)             
00116 #endif
00117 
00118 
00119 #ifndef ASSERT_COMPILE
00120 
00121 #define ASSERT_COMPILE(c) void assert_compile(int assert_compile[(c)?1:-1])
00122 #endif
00123 
00124 
00134 typedef unsigned char       uint8_t;        
00135 typedef unsigned short      uint16_t;       
00136 typedef unsigned int        uint32_t;       
00137 typedef ulonglong           uint64_t;       
00138 typedef signed char         int8_t;         
00139 typedef signed short        int16_t;        
00140 typedef signed int          int32_t;        
00141 typedef longlong            int64_t;        
00142 typedef int                 intptr_t;       
00143 typedef unsigned int        uintptr_t;      
00144 typedef int64_t             intmax_t;       
00145 typedef uint64_t            uintmax_t;      
00146 typedef uintptr_t           size_t;         
00147 typedef intptr_t            ptrdiff_t;       // End of group
00150 
00151 ASSERT_COMPILE(sizeof(uintptr_t)==sizeof(void*));
00152 ASSERT_COMPILE(sizeof(intptr_t)==sizeof(void*));
00153 
00154 
00155 #if __GNUC__<4
00156 
00159 #define offsetof(type,member)   ((size_t)(&((type*)256)->member)-256)
00160 #else
00161 #define offsetof(type,member)   __builtin_offsetof(type,member)
00162 #endif
00163 
00164 
00165 #if defined(__GNUC__) && defined(_ARM)
00166 
00170 #define dummy_return(type) register type _r0 asm("r0"); asm("" : "=r"(_r0)); return _r0
00171 
00172 #endif
00173 
00174 
00175 #ifndef COMPILE_FOR_SYMBIAN
00176 
00180 inline void* operator new(size_t, void* ptr) throw()
00181     { return ptr; }
00182 
00186 inline void operator delete(void*, void*) throw()
00187     { }
00188 
00189 #endif // !COMPILE_FOR_SYMBIAN
00190 
00191 
00192 #endif

Generated by  doxygen 1.6.1