00001
00012
00013
00014
00015
00016
00017 #ifndef DOXYGEN // doxygen can't parse this correctly
00018 #ifndef BASE_FUNCS_HH
00019 #define BASE_FUNCS_HH 1
00020
00021 namespace base {
00022
00026
00027
00028
00029
00030
00031 template<typename T> inline T Min( T a, T b ) { return (a < b) ? a : b; }
00032 template<typename T> inline T Max( T a, T b ) { return (a > b) ? a : b; }
00033 #ifndef MIN
00034 #define MIN(A,B) ( ((A) < (B)) ? (A) : (B) )
00035 #endif
00036 #ifndef MAX
00037 #define MAX(A,B) ( ((A) > (B)) ? (A) : (B) )
00038 #endif
00039
00040
00041 #define ABS(X) std::abs((X))
00042
00043
00044 #ifndef STREQ
00045 #define STREQ(A,B) ( strcmp((A),(B)) == 0 )
00046 #endif
00047 #ifndef STRNE
00048 #define STRNE(A,B) ( strcmp((A),(B)) != 0 )
00049 #endif
00050 #ifndef STREMPTY
00051 #define STREMPTY(S) ( ((S) == NULL) || ((S)[0] == '\0') )
00052 #endif
00053 #ifndef MEMEQ
00054 #define MEMEQ(S1,S2,LEN) ( memcmp((S1),(S2),(LEN)) == 0 )
00055 #endif
00056 #ifndef MENNE
00057 #define MEMNE(S1,S2,LEN) ( memcmp((S1),(S2),(LEN)) != 0 )
00058 #endif
00059 #define ELEMS(ARRAY) (uint( sizeof((ARRAY)) / sizeof((ARRAY)[0]) )) // DEPRECATED
00060
00062 #define DELETE_NULL( OBJ ) delete (OBJ), (OBJ) = NULL
00063
00066 #define CLEAR_BIT_FIELDS( BIT_FIELD_PTR ) ( *(reinterpret_cast<unsigned int*>( (BIT_FIELD_PTR) )) = 0 )
00067
00068
00069 void EXIT( int exitCode );
00070
00074
00076 INLINE void
00077 CLEAR( void* p, uint n )
00078 {
00079 memset( p, 0, n );
00080 }
00081
00083 INLINE int NEG( int x ) { return (x < 0) ? x : -x; }
00084 INLINE long int NEG( long int x ) { return (x < 0) ? x : -x; }
00085 INLINE float NEG( float x ) { return (x < 0) ? x : -x; }
00086 INLINE double NEG( double x ) { return (x < 0) ? x : -x; }
00087 INLINE long double NEG( long double x ) { return (x < 0) ? x : -x; }
00088
00089 INLINE bool
00090 IfPow2( int n )
00091 {
00092
00093
00094 return (n != 0) and ((n & (n-1)) == 0);
00095 }
00096
00097 INLINE bool IfEven( int n ) { return (n & 1) == 0; }
00098 INLINE bool IfOdd( int n ) { return (n & 1) == 1; }
00099
00100
00101 INLINE int
00102 PLUS_MINUS_1( bool plus )
00103 {
00104 return plus ? 1 : -1;
00105 }
00106
00110
00114 template<typename T>
00115 inline void
00116 Swap( T& a, T& b )
00117 {
00118 const T a2 = a;
00119 a = b;
00120 b = a2;
00121 }
00122
00126 template<typename T>
00127 bool
00128 IfSameSign( T a, T b )
00129 {
00130 return ((a < 0) and (b < 0))
00131 or ((a >= 0) and (b >= 0));
00132 }
00133
00134 }
00135
00136 #endif // BASE_FUNCS_HH
00137 #endif // DOXYGEN