メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkcStdio.h

説明を見る。

    00001
    00015 #ifndef DKUTIL_C_STDIO_H
    00016 #define DKUTIL_C_STDIO_H
    00017
    00018
    00019 #include "dkcOSIndependent.h"
    00020
    00021 #ifdef __cplusplus
    00022 namespace dkutil{
    00030
    00031     inline int dkmemcpy(void *dest,size_t size1,const void *src,size_t size2){
    00032         if(size1 < size2) return edk_FAILED;
    00033         ::memcpy(dest,src,size2);
    00034         return edk_SUCCEEDED;
    00035     }
    00043
    00044     inline int dkmemmove( void *dest,size_t size1,const void *src, size_t size2 ){
    00045         if(size1 < size2) return edk_FAILED;
    00046         ::memmove(dest,src,size2);
    00047         return edk_SUCCEEDED;
    00048     }
    00055 #   if 0
    00056     inline int dksprintf(char *buff,size_t bufsize,char *format,...){
    00057         BOOST_STATIC_ASSERT(!"つかうなー！");
    00058         //char buff[2048]="";
    00059         size_t buffnum=bufsize;
    00060         char *origin = format;
    00061         {
    00062             va_list VaList;
    00063             va_start( VaList , origin ) ;
    00064             int r;
    00065             r = _vsnprintf( buff ,buffnum - 1, origin , VaList );
    00066             if(0 > r){
    00067                 return edk_FAILED;
    00068             }else{
    00069                 buff[r+1] = '\0';
    00070             }
    00071             va_end( VaList );
    00072         }
    00073
    00074         return edk_SUCCEEDED;
    00075     }
    00076 #   endif //end of if 0
    00077
    00092     inline int dkstrcpy(char *dest,size_t size1,const char *src,size_t srclen){
    00093         if(size1 <= srclen) return edk_FAILED;
    00094         ::strncpy(dest,src,srclen);
    00095         //if(dest[srclen] != '\0') return edk_FAILED;
    00096         dest[srclen] = '\0';//0を入れるからsrclen + 1ではない。
    00097         return edk_SUCCEEDED;
    00098     }
    00100     inline int dkstrcpy(BYTE *dest,size_t size1,const BYTE *src,size_t srclen)
    00101     {
    00102         return dkstrcpy((char *)dest,size1,(const char *)src,srclen);
    00103     }
    00112
    00113     inline int dkstrcpy_amap(char *dest,size_t size1,const char *src,size_t srclen){
    00114 #   ifndef NDEBUG
    00115         dkcmFORCE_NOT_ASSERT((0 == size1 && 0 == srclen));
    00116 #   endif
    00117         if(size1 <= srclen){//ここは<=か！？
    00118             ::strncpy(dest,src,size1);
    00119             dest[size1 - 1] = '\0';
    00120             return edk_Not_Satisfactory;
    00121         }else{
    00122             ::strncpy(dest,src,srclen);
    00123             dest[srclen] = '\0';
    00124             return edk_SUCCEEDED;
    00125         }
    00126     }
    00127     inline int dkstrcpy_amap2(char *dest,size_t size1,const char *src){
    00128         return dkstrcpy_amap(dest,size1,src,strlen(src));
    00129     }
    00142     inline int dkstrcat(char *dest,size_t destsize,size_t destlen,
    00143         const char *src,size_t srclen)
    00144     {
    00145         //destlen + srclen + NULL文字
    00146         if(destsize < destlen + srclen + 1) return edk_FAILED;
    00147         ::strncat(dest,src,srclen);
    00148         return edk_SUCCEEDED;
    00149     }
    00151     inline int dkstrcat2(char *dest,size_t destsize,const char *src){
    00152         return dkstrcat(dest,destsize,strlen(dest),src,strlen(src));
    00153     }
    00155     inline int dkstrcat_amap(char *dest,size_t destsize,size_t destlen,
    00156         const char *src,size_t srclen)
    00157     {
    00158         //destlen + srclen + NULL文字
    00159         int result = edk_SUCCEEDED;
    00160         size_t lsize = destlen + srclen + 1;
    00161         if(destsize < lsize)
    00162         {//オーバーしてたら･･･
    00163             srclen = lsize - destsize - 1;
    00164             result = edk_Not_Satisfactory;
    00165         }
    00166         ::strncat(dest,src,srclen);
    00167         //dest[destlen + srclen - 1] = '\0';
    00168         return result;
    00169     }
    00171     inline int dkstrcat_amap2(char *dest,size_t destsize,const char *src){
    00172         return dkstrcat_amap(dest,destsize,strlen(dest),src,strlen(src));
    00173     }
    00174
    00183     inline int dkmemcmp( const void *buf1,size_t buf1PermitSize,
    00184         const void *buf2, size_t count )
    00185     {
    00186         if(buf1PermitSize < count)return edk_LogicError;
    00187         if(0 !=::memcmp(buf1,buf2,count))return edk_FAILED;
    00188         return edk_SUCCEEDED;
    00189     }
    00190
    00199
    00200     template<typename TYPE_>
    00201     inline int WINAPI dkcmp_base(const TYPE_ *b1,size_t b1size,
    00202         const TYPE_ *b2,size_t b2size)
    00203     {
    00204         if(b1size < b2size) return edk_LogicError;
    00205         int result = edk_SUCCEEDED;
    00206         //とりあえずマッチするか確かめる。
    00207         for(size_t i=0;i<b2size;i++)
    00208         {
    00209             if(b1[i] != b2[i])
    00210             {
    00211                 result = edk_FAILED;
    00212                 break;
    00213             }
    00214         }
    00215         return result;
    00216     }
    00217
    00226     inline int dkstrcmp(const char *b1,size_t b1size,const char *b2,size_t b2size)
    00227     {
    00228         //検索する文字列が多いとおかしいのでエラー
    00229         if(b1size < b2size) return edk_LogicError;
    00230
    00231         int result = edk_SUCCEEDED;
    00232         if(b2size % 4 == 0)
    00233         {//無理やりintで検索
    00234             size_t fb1size = b1size / 4;
    00235             size_t fb2size = b2size / 4;
    00236             const int *fb1 = (const int *)b1;
    00237             const int *fb2 = (const int *)b2;
    00238             return dkcmp_base(fb1,fb1size,fb2,fb2size);
    00239         }
    00240         //else
    00241         //{
    00242             //basic な検索･･･。
    00243             return dkcmp_base(b1,b1size,b2,b2size);
    00244         //}
    00245     }
    00252
    00253     template<typename INTEGER_>
    00254     inline size_t beam(INTEGER_ num){
    00255
    00256         size_t b = 0 ;
    00257         for(INTEGER_ i = 10 ; num >= i ; i *= 10 ){
    00258             b ++ ;
    00259         }
    00260         return b;
    00261     }
    00262
    00264     inline void memswap( void *va, void *vb, size_t size )
    00265     {
    00266         char *ca;
    00267         char *cb;
    00268         char  cTmp;
    00269         for( ca = (char *)va, cb = (char *)vb; size > 0; size--, ca++, cb++ )
    00270         {
    00271             cTmp = *ca;
    00272             *ca  = *cb;
    00273             *cb  = cTmp;
    00274         }
    00275     }//memswap
    00276
    00277
    00278
    00281     inline void memreverse( void *array, size_t num, size_t size )
    00282     {
    00283         char *l;
    00284         char *r;
    00285
    00286         l = (char *)array;
    00287         r = (char *)array + ((num-1) * size);
    00288         for( ; l < r; l = l+size, r = r-size )
    00289             memswap( l, r, size );
    00290     }//memreverse
    00291
    00292
    00295     inline void memrrotate( void *array, size_t shift, size_t num, size_t size )
    00296     {
    00297         memreverse( array,                      num,       size ); // 012345678 -> 876543210
    00298         memreverse( array,                      shift,     size ); // 876543210 -> 678543210
    00299         memreverse( (char *)array+(size*shift), num-shift, size ); // 678543210 -> 678012345
    00300     }//memrrotate
    00301
    00302
    00305     inline void memlrotate( void *array, size_t shift, size_t num, size_t size )
    00306     {
    00307         memreverse( array,                      shift,     size ); // 012345678 -> 210345678
    00308         memreverse( (char *)array+(size*shift), num-shift, size ); // 210345678 -> 210876543
    00309         memreverse( array,                      num,       size ); // 210876543 -> 345678012
    00310     }//memlrotate
    00311 }//end of dkutil namespace
    00312 #if 0
    00313 inline int WINAPI dkc_memcpy(void *dest,size_t size1,const void *src,size_t size2){
    00314     return dkutil::dkmemcpy(dest,size1,src,size2);
    00315 }
    00316 inline int WINAPI dkc_strcpy(char *dest,size_t size1,const char *src,size_t srclen){
    00317     return dkutil::dkstrcpy(dest,size1,src,srclen);
    00318 }
    00319 inline int WINAPI dkc_strcpy(BYTE *dest,size_t size1,const BYTE *src,size_t srclen){
    00320     return dkc_strcpy((char *)dest,size1,(const char *)src,srclen);
    00321 }
    00322 inline int WINAPI dkc_strcpy_amap(char *dest,size_t size1,const char *src,size_t srclen){
    00323     return dkutil::dkstrcpy_amap(dest,size1,src,srclen);
    00324 }
    00326 inline int WINAPI dkc_strcpy_amap2(char *dest,size_t size1,const char *src){
    00327     return dkutil::dkstrcpy_amap2(dest,size1,src);
    00328 }
    00330 inline int WINAPI dkc_strcat(char *dest,size_t destsize,size_t destlen,
    00331         const char *src,size_t srclen)
    00332 {
    00333         return dkutil::dkstrcat(dest,destsize,destlen,src,srclen);
    00334 }
    00336 inline int WINAPI dkc_strcat2(char *dest,size_t destsize,const char *src){
    00337     return dkutil::dkstrcat2(dest,destsize,src);
    00338 }
    00340 inline int WINAPI dkc_strcat_amap(char *dest,size_t destsize,size_t destlen,
    00341         const char *src,size_t srclen)
    00342 {
    00343     return dkutil::dkstrcat_amap(dest,destsize,destlen,src,srclen);
    00344 }
    00346 inline int WINAPI dkc_strcat_amap2(char *dest,size_t destsize,const char *src){
    00347     return dkutil::dkstrcat_amap2(dest,destsize,src);
    00348 }
    00350 inline int WINAPI dkc_memcmp( const void *buf1,size_t buf1PermitSize,
    00351     const void *buf2, size_t count )
    00352 {
    00353     return dkutil::dkmemcmp(buf1,buf1PermitSize,buf2,count);
    00354 }
    00355 inline int WINAPI dkc_strcmp(const char *b1,size_t b1size,const char *b2,size_t b2size)
    00356 {
    00357     return dkutil::dkstrcmp(b1,b1size,b2,b2size);
    00358 }
    00359 inline size_t dkc_beam(int num){
    00360     return dkutil::beam(num);
    00361 }
    00362
    00364 inline void dkc_memswap( void *va, void *vb, size_t size )
    00365 {
    00366     dkutil::memswap(va,vb,size);
    00367 }
    00368
    00370 inline void dkc_memreverse( void *array, size_t num, size_t size )
    00371 {
    00372     dkutil::memreverse(array,num,size);
    00373 }
    00375 inline void dkc_memrrotate( void *array, size_t shift, size_t num, size_t size )
    00376 {
    00377     dkutil::memrrotate(array,shift,num,size);
    00378 }
    00379
    00381 inline void dkc_memlrotate( void *array, size_t shift, size_t num, size_t size )
    00382 {
    00383     dkutil::memlrotate(array,shift,num,size);
    00384 }
    00385 #endif//end of if 0
    00386
    00387 #else //for C lang
    00388
    00389 #endif //end of __cplusplus
    00390
    00391 //mempry用
    00392
    00393 DKC_EXTERN int WINAPI dkc_memcpy(void *dest,size_t size1,const void *src,size_t size2);
    00394
    00396 DKC_EXTERN int WINAPI dkc_memcpy_zc(void *dest,size_t size1,const void *src,size_t size2);
    00397
    00398
    00399 DKC_EXTERN int WINAPI dkc_memmove(void *dest,size_t size1,const void *src, size_t size2 );
    00400
    00401
    00403 DKC_EXTERN int WINAPI dkc_memcmp( const void *buf1,size_t buf1PermitSize,
    00404     const void *buf2, size_t count );
    00405
    00406
    00407 //char 文字列用
    00408
    00409 DKC_EXTERN int WINAPI dkc_strcpy(char *dest,size_t size1,const char *src,size_t srclen);
    00410
    00411 DKC_EXTERN int WINAPI dkc_strcpy_amap(char *dest,size_t size1,const char *src,size_t srclen);
    00413 DKC_EXTERN int WINAPI dkc_strcpy_amap2(char *dest,size_t size1,const char *src);
    00415 DKC_EXTERN int WINAPI dkc_strcat(char *dest,size_t destsize,size_t destlen,
    00416         const char *src,size_t srclen);
    00418 DKC_EXTERN int WINAPI dkc_strcat2(char *dest,size_t destsize,const char *src);
    00420 DKC_EXTERN int WINAPI dkc_strcat_amap(char *dest,size_t destsize,size_t destlen,
    00421         const char *src,size_t srclen);
    00423 DKC_EXTERN int WINAPI dkc_strcat_amap2(char *dest,size_t destsize,const char *src);
    00424
    00425 DKC_EXTERN int WINAPI dkc_strcmp(const char *b1,size_t b1size,const char *b2,size_t b2size);
    00426
    00427 //wchar文字列用
    00428 /*
    00429 なんか、バッファのバイト単位と文字単位が引数にごちゃごちゃになりそうなので保留
    00430
    00431 DKC_EXTERN int WINAPI dkc_wcsncpy( wchar_t *dest,size_t destsize, const wchar_t *src, size_t srcsize );
    00433 DKC_EXTERN int WINAPI dkc_wcsncat( wchar_t *dest,size_t destsize,size_t destlen,
    00434         const char *wchar_t,size_t srclen );
    00435 */
    00437 DKC_EXTERN int WINAPI dkc_wcscat2( wchar_t *dest,size_t destsize,
    00438         const wchar_t *src);
    00439
    00440
    00441
    00443 DKC_EXTERN size_t dkc_beam(int num);
    00444
    00446 DKC_EXTERN void dkc_memswap( void *va, void *vb, size_t size );
    00447
    00449 DKC_EXTERN void dkc_memreverse( void *array, size_t num, size_t size );
    00451 DKC_EXTERN void dkc_memrrotate( void *array, size_t shift, size_t num, size_t size );
    00452
    00454 DKC_EXTERN void dkc_memlrotate( void *array, size_t shift, size_t num, size_t size );
    00455
    00464
    00465 DKC_EXTERN int dkc_stream_swap(char *memory,size_t size,size_t point);
    00466
    00467
    00468
    00469 #if 0
    00470
    00499 DKC_EXTERN int WINAPI strnicmp(
    00500     const char *string1, const char *string2, size_t count);
    00501
    00502 #endif
    00503
    00504
    00505
    00506
    00507 #endif //end of include once