00001 #ifndef __COMPUTIL_UTILITY_H
00002 #define __COMPUTIL_UTILITY_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "basetype.h"
00027 #include "ram.h"
00028 #include "errorlog.h"
00029 #include <assert.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036
00037 typedef unsigned int uint;
00038
00039
00040
00041 #define BrandoError(str) geErrorLog_AddString(-1,str,NULL)
00042
00043 #ifndef NULL
00044 #define NULL (0)
00045 #endif
00046
00047 #define sizeofpointer sizeof(void *)
00048
00049 #define PaddedSize(a) (((a)+3) & (~3))
00050
00051 #define IsOdd(a) ( ((uint32)a)&1 )
00052 #define SignOf(a) (((a) < 0) ? -1 : 1)
00053
00054 #ifndef max
00055 #define max(a,b) ((a)>(b)?(a):(b))
00056 #endif
00057
00058 #ifndef min
00059 #define min(a,b) ((a)<(b)?(a):(b))
00060 #endif
00061
00062 #define minmax(x,lo,hi) ( (x)<(lo)?(lo):( (x)>(hi)?(hi):(x)) )
00063 #define putminmax(x,lo,hi) x = minmax(x,lo,hi)
00064 #define putmin(x,lo) x = min(x,lo)
00065 #define putmax(x,hi) x = max(x,hi)
00066 #define max3(a,b,c) max(max(a,b),c)
00067 #define max4(a,b,c,d) max(a,max3(b,c,d))
00068 #define min3(a,b,c) min(min(a,b),c)
00069 #define min4(a,b,c,d) min(a,min3(b,c,d))
00070
00071 #ifndef mabs
00072 #define mabs(i) ((i) < 0 ? -(i) : (i))
00073 #endif
00074
00075 #define isinrange(x,lo,hi) ( (x) >= (lo) && (x) <= (hi) )
00076
00077 #define getuint32(bptr) ( ((((uint8 *)(bptr))[0])<<24) + (((uint8 *)(bptr))[1]<<16) + (((uint8 *)(bptr))[2]<<8) + (((uint8 *)(bptr))[3]) )
00078 #define getuint16(bptr) ( (((uint8 *)(bptr))[0]<<8) + (((uint8 *)(bptr))[1]) )
00079
00080
00081
00082 #ifndef strofval
00083 #define strofval(x) (#x)
00084 #endif
00085
00086 #ifndef new
00087 #define new(type) geRam_AllocateClear(sizeof(type))
00088 #endif
00089
00090 #ifndef destroy
00091 #define destroy(mem) do { if ( mem ) { geRam_Free(mem); (mem) = NULL; } } while(0)
00092 #endif
00093
00094 #ifndef newarray
00095 #define newarray(type,num) geRam_AllocateClear((num)*sizeof(type))
00096 #endif
00097
00098 #ifndef memclear
00099 #define memclear(mem,size) memset(mem,0,size);
00100 #endif
00101
00102
00103
00104 #ifdef __cplusplus
00105 }
00106 #endif
00107
00108 #endif // __COMPUTIL_UTILITY_H
00109