メインページ | アルファベット順一覧 | データ構造 | ファイル一覧 | データフィールド | グローバル | 関連ページ

# macro.h

説明を見る。

    00001
    00009 #ifndef DKUTIL_CSTD_MACRO_H
    00010 #define DKUTIL_CSTD_MACRO_H
    00011
    00012
    00014 #define SWAP_NUM(a,b) \
    00015     (a) = (b) - (a) ;\
    00016     (b) -= (a) ;\
    00017     (a) += (b)
    00018
    00022 #define SWAP_NUM_EX(a,b,ex) \
    00023     (ex)(a) = (ex)((b) - (a) ); \
    00024     (ex)(b) = (ex)((b) - (a) ); \
    00025     (ex)(a) = (ex)((a) + (b) )
    00026
    00034
    00035 #define SM_OFFSET(p_type,field)     ((unsigned int)&(((p_type)NULL)->field))
    00036
    00038 #define SET_RECT(rect, l, t, r, b) \
    00039 {\
    00040     rect##.left   = l;\
    00041     rect##.top    = t;\
    00042     rect##.right  = r;\
    00043     rect##.bottom = b;\
    00044 }
    00045
    00046
    00048 #define DKUTIL_ARRAY_NUMOF(array) (sizeof(array)/sizeof(array[0]))
    00049
    00050 #define DKUTIL_NAMELINK(X,Y) X##Y
    00051
    00052 #define DKUTIL_MAKESIGNATURE(X) DKUTIL_NAMELINK(X,__LINE__)
    00053
    00054 #define DKUTIL_MAKE_UINT_ID(id) ((((UINT)(id) & 0xFF) << 24) |     \
    00055                   (((UINT)(id) & 0xFF00) << 8) |    \
    00056                   (((UINT)(id) & 0xFF0000) >> 8) |  \
    00057                   (((UINT)(id) & 0xFF000000) >> 24))
    00058
    00060 #define DKUTIL_FLAG_DOWN(x,n) {x &= ~n;}//{(x & n) ? x |= (x^n) : 0;}//{x |= (x^n);}
    00061
    00062 #define DKUTIL_FLAG_UP(x,n) {x |= n;}
    00063
    00065
    00066 #define DKUTIL_FLAG_UP_N(x,n) DKUTIL_FLAG_UP(x,(1 << n))
    00067
    00068
    00069 #define DKUTIL_FLAG_DOWN_N(x,n) DKUTIL_FLAG_DOWN(x,( 1<<n ))
    00070 //#define DKUTIL_FLAG_DOWN_N(x,n) {x &= (x^ ( 1<<n ) );}
    00071 //#define DKUTIL_FLAG_UP_N(x,n) {x |= (1 << n);}
    00072
    00073
    00074 #ifdef __cplusplus
    00075
    00105
    00106 #define SET_VA_LIST(buff,buffnum,origin) \
    00107 {\
    00108     va_list VaList;\
    00109     va_start( VaList , origin ) ;\
    00110     int r;\
    00111     r = _vsnprintf( buff ,buffnum - 1, origin , VaList );\
    00112     if(0 > r){\
    00113         buff[buffnum - 1] = '\0';\
    00114     }else{\
    00115         buff[r+1] = '\0';\
    00116     }\
    00117     va_end( VaList ); \
    00118 }
    00119
    00120
    00121 #   define DKUTIL_SAFE_REALLOC(b,s) ::realloc(b,s)
    00122 #   define DKUTIL_SAFE_MALLOC(s) ::malloc(s)
    00123 #   define DKUTIL_SAFE_FREE(a) if(a){::free(a);a=NULL;}
    00124
    00126 #   define DKUTIL_STRUCTURE_INIT(s) ::memset(&(s),0,sizeof(s))
    00127
    00128 #   define DKUTIL_MEMZERO(mem,size) ::memset(mem,0,size)
    00129
    00130 #else // for c lang
    00131
    00132
    00133
    00134 #define DKUTIL_SAFE_REALLOC(b,s) realloc(b,s)
    00135 #define DKUTIL_SAFE_MALLOC(s) malloc(s)
    00136 #define DKUTIL_SAFE_FREE(a) if(a){free(a);a=NULL;}
    00137 #define DKUTIL_STRUCTURE_INIT(s) memset(&(s),0,sizeof(s))
    00138
    00139 #   define DKUTIL_MEMZERO(mem__,size__) memset(mem__,0,size__)
    00140 #endif
    00141
    00143 #define DKUTIL_ARRAY_ZERO(arr) DKUTIL_MEMZERO(arr,sizeof(arr))
    00144
    00145 #define NULL_CHAR_ARRAY(s) DKUTIL_ARRAY_ZERO(s)
    00146
    00147 #define SET_VA_LIST_C(VaList,r,buff,buffnum,origin) \
    00148 {\
    00149     va_start( VaList , origin ) ;\
    00150     r = _vsnprintf( buff ,buffnum - 1, origin , VaList );\
    00151     if(0 > r){\
    00152         buff[buffnum - 1] = '\0';\
    00153     }else{\
    00154         buff[r+1] = '\0';\
    00155     }\
    00156     va_end( VaList ); \
    00157 }
    00158
    00159 #define DKUTIL_BIT_TO_BYTE(a) (a / 8)
    00160
    00161 #endif //end of include once
    00162