SourceForge.jp

dkutilFunction02.h

説明を見る。
00001 
00002 
00020 #ifndef _dkutilFunction02__
00021 #define _dkutilFunction02__
00022 
00023 //#include "../common/common_allinclude.h"
00024 //#include "dkutilLog.h"
00025 //#include "../wrapper/dkutilDataWrapper.h"
00026 #include "dkutilFunction01.h"
00027 #include "dkutilString.h"
00028 //#include "dkutilMap.h"
00029 
00030 
00031 namespace dkutil{
00032 
00033 inline GUID &CreateGUID(){
00034     static GUID guid={0};//ここ、staticにしてないと他の関数に迷惑がかかります^^;
00035     ::CoCreateGuid(&guid);
00036     return guid;
00037 }
00038 inline size_t GUIDStringBuffSize(){
00039     return strlen(ULONG_MAX_STR) + //ulong member
00040     ( strlen(USHRT_MAX_STR) * 2 ) + //ushort member
00041     ( strlen(UCHAR_MAX_STR) * 8 ) + 1;//uchar member
00042 }
00043 inline int GUIDToCharArray(GUID &guid,char *buff,size_t buffsize){
00044     /* GUID member
00045     unsigned long        Data1; 
00046   unsigned short       Data2; 
00047   unsigned short       Data3; 
00048   unsigned char        Data4[8]; 
00049      = buffsize is ULONG_MAX + ( USHRT_MAX * 2 ) UCHAR_MAX * 8 ??
00050     */
00051     size_t size = GUIDStringBuffSize();
00052     //NULL文字も考慮して > である!
00053     if(size > buffsize){    return -1;}
00054     
00055     _snprintf(buff,buffsize,"%u%u%u%u%u%u%u%u%u%u%u",//"%d%d%d%d%d%d%d%d%d%d%d%d",
00056         guid.Data1,guid.Data2,guid.Data3,
00057         guid.Data4[0],guid.Data4[1],guid.Data4[2],
00058         guid.Data4[3],guid.Data4[4],
00059         guid.Data4[5],guid.Data4[6],guid.Data4[7]
00060         );
00061     return 0;
00062 }
00063 inline int GUIDToString(std::string &get_my_string,GUID &guid=CreateGUID())
00064 {
00065     size_t size = GUIDStringBuffSize();
00066     char *ptr = (char *)::malloc(size);
00067     if(!ptr) return -1;
00068     ::memset(ptr,0,size);
00069     int result = -1;
00070     if(0 != GUIDToCharArray(guid,ptr,size))
00071         goto END;
00072     get_my_string = ptr;
00073     result = 0;
00074 END:
00075     if(ptr){::free(ptr);ptr=NULL;}
00076     return result;
00077 }
00078 /*
00080 template<typename T>
00081 class IntegerToCharPtr{
00082     char m_buff[20 + 1];
00083     IntegerToCharPtr(){
00084         ::memset(m_buff,0,sizeof(m_buff));
00085     }
00086     size_t size(){return 20 + 1;}
00087     inline char *IntegerToCharPtr(T t){
00088         //18446744073709551615 = 20桁
00089         _snprintf(m_buff,size(),"%s",t);
00090         return m_buff;
00091     }
00092     char *operator()(T t){
00093         return IntegerToCharPtr(t);
00094     }
00095 };
00096 inline int CharArrayToGUIDString(char *ptr,size_t permit_size,std::string &str){
00097     size_t size = strlen("{D9AD457A-007F-4DB6-8B06-CAACC44933A3}") + 1;
00098     if(size > permit_size) return -1;
00099     str = {
00100     return 0;
00101 }
00102 */
00104 inline char *StringToCharPtr(const std::string &str){
00105     return const_cast<char *>(str.c_str());
00106 }
00107 inline const char *StringToConstCharPtr(const std::string &str){
00108     return str.c_str();
00109 }
00110 
00114 inline int MemoryLeakCheckAfterSoftwareEnded(){
00115 #if defined(USE_DKINGYO_MEMORYLEAK_CHECK) && defined(_MSC_VER)
00116     return _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
00117 #else
00118     return -1;
00119 #endif
00120 }
00121 
00122 inline bool OpenExplorer(const char *pURL){
00123     size_t size = strlen(pURL) + MAX_PATH + 1;
00124     char *tmp = (char *)malloc(size);
00125     if(!tmp) return false;
00126 
00127     _snprintf(tmp,size,"Explorer /root,%s",pURL);
00128     int r = ::WinExec(tmp,SW_SHOWDEFAULT);
00129     if(tmp){::free(tmp);tmp=NULL;}
00130     return (r != 0);
00131 }
00132 
00133 inline int CurrentDirectoryPlusFileName(char *buff,size_t buffsize,char *filename)
00134 {
00135     if(buffsize < MAX_PATH) return -1;
00136     ::memset(buff,0,buffsize);
00137     GetCurrentDirectory(buffsize,buff);
00138     {
00139         char *sp =  strtail(buff);
00140         /*
00141         buff = 0
00142         buffsize = 1
00143         sp = 2
00144         0-----ここらへんは文字で埋まっていると思って^^------2--空領域---1
00145         0x00                                                            MAX_PATH
00146 
00147         なので、buff + buffsize == &buff[buffsize]
00148         sp = buff + sp == &buff[sp]
00149         buffsize - sp == 空領域
00150         */
00151         //NULL文字 考慮 で <=
00152         if((size_t)((buff + buffsize) - (sp)) <= strlen(filename) + 1)
00153         {
00154             return -1;
00155         }
00156         //つける。
00157         sp[0] = '\\';
00158         //あとは文字列追加
00159         strncat(&sp[1],filename,(buff + buffsize) - (sp));
00160     }
00161     return 0;
00162 }
00163 
00164 
00165 #if 0
00166 
00167 template<class UTIL=DKConfigUtility>
00168 class Opener_base{
00169 public:
00170     struct FileType{
00171         FileType(char *gfilter,char *gtitle,char *gdefext){
00172             NULL_CHAR_ARRAY(filter);
00173             NULL_CHAR_ARRAY(title);
00174             NULL_CHAR_ARRAY(defext);
00175             dkstrcpy(filter,sizeof(filter),gfilter,strlen(gfilter));
00176             dkstrcpy(title,sizeof(title),gtitle,strlen(gtitle));
00177             dkstrcpy(defext,sizeof(defext),defext,strlen(defext));
00178         }
00179         char filter[512];
00180         char title[512];
00181         char defext[512];
00182     };
00183 
00184     enum{
00185         idALLFILE,
00186         idPNG,
00187         idBMP,
00188         idJPEG,
00189         idWAVE,
00190         idMIDI,
00191         idMP3,
00192         idOGG,
00193         idTXT,
00194         idHTML,
00195     };
00196     typedef map_ex<int,FileType> MAP_TYPE;
00197 private:
00198     
00199     static MAP_TYPE mmap;
00200     static bool isOnce;
00201     UTIL mutil;
00202     void MappingFileExtention(){
00203         //スレッドロック
00204         if(isOnce==false){
00205             DKUTIL_MULTITHREAD_SYNDROME_LOCK(mutil);
00206             
00207             if(isOnce==false){
00208 
00209                 int id = idALLFILE;
00210                 mmap.SetData(id,
00211                     FileType("All files(*.*)\0*.*\0\0","All File Select","All Files"));
00212                 id=idPNG;
00213                 mmap.SetData(id,
00214                     FileType("png(*.png)\0*.png\0\0","Png File Select","Png File"));
00215                 id=  idBMP;
00216                 mmap.SetData(id,
00217                     FileType("bmp(*.bmp)\0*.bmp\0\0","Bitmap File Select","BMP File"));
00218                 id = idJPEG;
00219                 mmap.SetData(id,
00220                     FileType("jpg(*.jpg*.jpeg)\0*.jpg;*.jpeg\0\0","JPEG File Select","Jpeg File"));
00221                 id = idTXT;
00222                 mmap.SetData(id,
00223                     FileType("txt(*.txt)\0*.txt\0\0","Text File Select","Text File"));
00224                 isOnce=true;
00225             }
00226             //ロック解除
00227             DKUTIL_MULTITHREAD_SYNDROME_UNLOCK(mutil);
00228         }
00229     }
00230 public:
00231     explicit Opener_base(){MappingFileExtention();}
00232     inline bool Open(char *filename,size_t id=idALLFILE,HWND hwnd=NULL)const
00233     {
00234         //MappingFileExtention();
00235         MAP_TYPE::const_iterator it = mmap.find(id);
00236         if(it == mmap.end())
00237             return false;
00238         const FileType &f = it->second;
00239         //char path[MAX_PATH]="";
00240         //dOpenFileDialog(filename,path,filter,defext,hwnd);
00241         if(false == FileOpenDialog(filename,f.title,f.filter,f.defext,hwnd))
00242             return false;
00243         return true;
00244     }
00245     inline bool operator ()(char *filename,size_t id=idALLFILE,HWND hwnd=NULL)const{
00246         return Open(filename,id,hwnd);
00247     }
00248     /*inline bool operator ()(char *filename)const{
00249         return Open(filename,idALLFILE,NULL);
00250     }*/
00251     
00252 
00253 };
00254 
00255 //static 宣言
00256 template<class UTIL>
00257 Opener_base<UTIL>::MAP_TYPE Opener_base<UTIL>::mmap;
00258 
00259 template<class UTIL>
00260 bool Opener_base<UTIL>::isOnce=false;
00261 
00262 typedef Opener_base<> Opener; 
00263 
00264 
00265 #endif
00266 #if 0
00267 class FlagManager{
00268 BOOST_PROTECTED:
00269     char *m_mem;
00270 public:
00271     FlagManager(UINT num){
00272         m_mem=NULL;
00273         Init(num);
00274     }
00275     virtual ~FlagManager(){
00276         End();
00277     }
00278     int Init(UINT num){
00279         size_t size = (num / 8) + 1;
00280         m_mem=(char *)malloc(size);
00281         if(!m_mem){return -1;}
00282         return 0;
00283     }
00284     int End(){
00285         if(m_mem){::free(m_mem);m_mem=NULL;}
00286     }
00287     int SetFlag(UINT n,bool flag){
00288         if(n < 8)
00289             m_mem &
00290     bool GetFlag(UINT n)
00291     UINT PermitSize()
00292     bool isOK(){return (m_mem != NULL);}
00293 };
00294 #endif
00295 
00296 
00297 
00298 inline int dMessageBox(char *title,int flag,char *str,...){
00299     char s[1024];
00300     SET_VA_LIST(s,1024,str);
00301     return MessageBox(NULL,s,title,flag);
00302 }
00303 
00304 inline bool DataCompar(char *data1,size_t size1,char *data2,size_t size2)
00305 {
00306     if(size1 != size2){
00307         return false;
00308     }
00309     for(size_t i = 0;i<size1;i++){
00310         if(data1[i] != data2[i]){
00311             return false;
00312         }
00313     }
00314     return true;
00315 }
00316 
00317 /*
00318 class To{
00319     inline const char *operator()(int in,int system,char *buff,size_t buffsize)
00320     {
00321     }
00322 }
00323     */  
00324 
00325 
00326 /*
00328 template<class T>
00329 inline bool isStringXXX(char *str,T func,size_t len = strlen(str))
00330 {
00331     for(int i=0;i<len;i++){
00332         if(!func(str[i])) return false;
00333     }
00334     return true;
00335 }
00336 
00337 inline bool isStringDigit(char *str,size_t len = strlen(str)){
00338     return isStringXXX(str,isDigit,len);
00339 }
00340 
00341 inline bool isStringAlpha(char *s,size_t len = strlen(str)){
00342     return isStringXXX(str,isAlpha,len);
00343 }
00344 */  
00345 
00346 
00347 
00348 
00349 
00350 
00352 /*
00353 template<typename SIZE>
00354 class DirBuffer{
00355     static char WindowsDir[SIZE];
00356 public:
00357     DirBuffer(){Reset();}
00358     void Reset(){::memset(WindowsDir,0,sizeof(WindowsDir));}
00359     size_t Size(){return SIZE;}
00360     char *GetBuff(){return WindowsDir;}
00361 };*/
00362 
00363 
00364 //extern void ChangeNewLineCode_AutoToWindows(const char *text,char *buff,size_t size);
00365 
00366 
00367 
00368 extern void TestFunction02();
00369 
00370 }
00371 
00372 #endif

dkutil 1.02リリース前 d金魚専用マニュアルバージョンに対してSun Dec 28 21:23:08 2003に生成されました。 doxygen 1.3.5