SourceForge.jp

dkutilOutput.h

説明を見る。
00001 
00002 #ifndef _dkutilOutput__h_
00003 #define _dkutilOutput__h_
00004 
00005 #include "dKingyoMacro.h"
00006 #include "dkutilDefinedC.h"
00007 #include "dkutilLog.h"
00008 #if defined(__GNUG__)
00009 #   include <dkutil/config/dkutilUserConfig.h>
00010 #endif
00011 
00012 namespace dkutil{
00013     
00014 
00015 
00016 
00020 
00021 inline bool dOutputDebugString(char *str,...){
00022     char s[1024 * 2];
00023     SET_VA_LIST_INSERT_YEN_N(s,sizeof(s),str);
00024     OutputDebugString(s);
00025     //fprintf(stderr,s);
00026     return true;
00027 }
00028 
00029 inline void dODS(const char *str,...){
00030     char s[1024]="";
00031     SET_VA_LIST_INSERT_YEN_N(s,1024,str);
00032     dOutputDebugString(s);
00033     /*char s[1024];
00034     SET_VA_LIST_INSERT_YEN_N(s,1024,str);
00035     OutputDebugString(s);*/
00036 }
00037 inline void dODSNoConst(char *str,...){
00038     char s[1024]="";
00039     SET_VA_LIST_INSERT_YEN_N(s,1024,str);
00040     dOutputDebugString(s);
00041 }
00042 inline void dODSNoNewLine(const char *str,...){
00043     char s[1024]="";
00044     SET_VA_LIST(s,1024,str);
00045     OutputDebugString(s);
00046     //fprintf(stderr,s);
00047 }
00048 
00049 inline bool SuperODS(const char *str,...){
00050     char s[2048]="";
00051     SET_VA_LIST(s,sizeof(s),str);
00052     dOutputDebugString(s);
00053     printf(s);
00054     return true;
00055 }
00056 
00057 
00058 /*
00059 class Win32LastError{
00060     DKConfigUtility mUtil;
00061     static std::string mbuf;
00062 protected:
00063     void MTLockToString(std::string &mbuf,DWORD ErrorID,bool flag)
00064     {
00065         DKUTIL_LOCKTHREAD(mUitl);
00066         ToString(mbuf,ErrorID,flag);
00067         DKUTIL_UNLOCKTHREAD(mUitl);
00068     }
00069 public:
00070     Win32LastError(){}
00071     virtual ~Win32LastError(){}
00072     const char *operator()(){
00073         MTLockToString(mbuf,0,false);
00074         return mbuf.c_str();
00075     }
00076     const char *operator()(DWORD ErrorID){
00077         MTLockToString(mbuf,ErrorID,true);
00078         return mbuf.c_str();
00079     }
00080     void ToString(std::string &buf,DWORD ErrorID,bool flag=false)
00081     {
00082         mbuf.clear();
00083         LPVOID lpMsgBuf;
00084         if(flag){
00085             ::FormatMessage(
00086                 FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
00087                 NULL, 
00088                 ErrorID, 
00089                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL 
00090                 );
00091         }else{
00092             ::FormatMessage(
00093                 FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
00094                 NULL, 
00095                 GetLastError(), 
00096                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL 
00097                 );
00098         }
00099         mbuf = "ERROR Message:";
00100         mbuf += (LPCTSTR)lpMsgBuf;
00101         LocalFree( lpMsgBuf );
00102     }
00103 
00104     DWORD GetLastError(){
00105         DWORD ErrorID;
00106         DKUTIL_MULTITHREAD_SYNDROME_LOCK(mUitl);
00107         ErrorID = ::GetLastError();
00108         DKUTIL_MULTITHREAD_SYNDROME_UNLOCK(mUitl);
00109         return ErrorID;
00110     }
00111 };
00112 
00113 
00114 std::string Win32LastError::mbuf;
00115 */  
00116 class Win32LastError{
00117     DKConfigUtility mUtil;
00118     std::string mbuf;
00119 protected:
00120     void MTLockToString(std::string &mbuf,DWORD ErrorID,bool flag)
00121     {
00122         DKUTIL_LOCKTHREAD(mUtil);
00123         ToString(mbuf,ErrorID,flag);
00124         DKUTIL_UNLOCKTHREAD(mUtil);
00125     }
00126 public:
00127     Win32LastError(){}
00128     virtual ~Win32LastError(){}
00129     const char *operator()(){
00130         MTLockToString(mbuf,0,false);
00131         return mbuf.c_str();
00132     }
00133     const char *operator()(DWORD ErrorID){
00134         MTLockToString(mbuf,ErrorID,true);
00135         return mbuf.c_str();
00136     }
00137     void ToString(std::string &buf,DWORD ErrorID,bool flag=false)
00138     {
00139         mbuf.clear();
00140         LPVOID lpMsgBuf;
00141         if(flag){
00142             ::FormatMessage(
00143                 FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
00144                 NULL, 
00145                 ErrorID, 
00146                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL 
00147                 );
00148         }else{
00149             ::FormatMessage(
00150                 FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
00151                 NULL, 
00152                 GetLastError(), 
00153                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL 
00154                 );
00155         }
00156         mbuf = "ERROR Message:";
00157         mbuf += (LPCTSTR)lpMsgBuf;
00158         LocalFree( lpMsgBuf );
00159     }
00160 
00161     DWORD GetLastError(){
00162         DWORD ErrorID;
00163         DKUTIL_MULTITHREAD_SYNDROME_LOCK(mUtil);
00164         ErrorID = ::GetLastError();
00165         DKUTIL_MULTITHREAD_SYNDROME_UNLOCK(mUtil);
00166         return ErrorID;
00167     }
00168 };
00169 
00170 
00172 inline bool dkassert(const char *expression,
00173                                          const char *filename,size_t line,const char *message,...)
00174 {
00175     char s[1024]="";
00176     if(message){
00177         SET_VA_LIST_INSERT_YEN_N(s,sizeof(s),message);
00178     }else{
00179         SET_VA_LIST_INSERT_YEN_N(s,sizeof(s),"No message");
00180     }
00181     char ss[1024 * 2]="";
00182     _snprintf(ss,sizeof(ss),
00183         "DKUTIL_ASSERT(%s):\nfile:%s / \n line:%d / \n message: %s",
00184         expression,filename,line,s);
00185     dOutputDebugString(ss);
00186 #ifdef NDEBUG
00187 #   ifdef WIN32
00188     //::MessageBox(NULL,ss,"ERROR ASSERTION !!",MB_OK);
00189     {
00190         LPCTSTR name="ERROR_TEMP.txt";
00191         {
00192             //ファイルをオープン
00193             FILE *fp;
00194             if(NULL != (fp = fopen( name , "at" ))){
00195             
00196                 // エラーログファイルに書き出す
00197                 fputs( ss , fp ) ;
00198                 fclose( fp ) ;
00199             }
00200         }
00201         ::ShellExecute(NULL, "open",name, NULL, NULL, SW_SHOWNORMAL);
00202         ::DeleteFile(name);
00203     }
00204     MB("このテキストをこのソフトの開発者に渡せば、バグ発見の近道なります。\n \
00205         開発者に知らせるときはこのテキストを転記してあげましょう。");
00206     if(IDYES==::MessageBox(NULL,
00207         "このままこのソフトを起動しつづけると、更なるエラーが発生する可能性があります。\n終了しますか?",
00208         "あってはいけない エラー!!!",
00209         MB_YESNO))
00210     {
00211         exit(edk_FAILED);
00212         //terminate();
00213     }else{
00214     }
00215 #   endif   
00216 
00217 #else
00218     assert(!expression);
00219 #endif
00220     return true;
00221 }
00222 
00223 #ifndef NDEBUG
00224 #   define DKUTIL_TRUE_ASSERT(ex) ( (ex) && dkassert(#ex,__FILE__,__LINE__,NULL) )
00225 #   define DKUTIL_ASSERT(ex) ( (ex) || dkassert(#ex,__FILE__,__LINE__,NULL) )
00226 #   define DKUTIL_TRUE_ASSERT_MESSAGE(ex,mes) ( (ex) && dkassert(#ex,__FILE__,__LINE__,mes) )
00227 #   define DKUTIL_ASSERT_MESSAGE(ex,mes) ( (ex) || dkassert(#ex,__FILE__,__LINE__,mes) )
00228 #else
00229 #   define DKUTIL_TRUE_ASSERT_MESSAGE(ex,mes) ((void)0)
00230 #   define DKUTIL_ASSERT_MESSAGE(ex,mes) ((void)0)
00231 #   define DKUTIL_TRUE_ASSERT(ex) ((void)0)
00232 #   define DKUTIL_ASSERT(ex) ((void)0)
00233 #endif
00234 
00235 
00236 #   define SET_VA_LIST_DMB(a1,a2) SET_VA_LIST(a1,sizeof(a1),a2) 
00237 inline void dMB(char *str,...){
00238     char s[1024]="";
00239     SET_VA_LIST_DMB(s,str);
00240     ::MessageBox(NULL,s,"Message",MB_OK);
00241 }
00242 inline void dMB(HWND hWnd,char *title,UINT uType,char *str,...){
00243     char s[1024];
00244     SET_VA_LIST_DMB(s,str);
00245     ::MessageBox(hWnd,s,title,uType);
00246 }
00247 inline void dMB(char *title,char *str,...){
00248     char s[1024];
00249     SET_VA_LIST_DMB(s,str);
00250     ::MessageBox(NULL,s,title,MB_OK);
00251 }
00252 inline void dMB(UINT uType,char *str,...){
00253     char s[1024];
00254     SET_VA_LIST_DMB(s,str);
00255     ::MessageBox(NULL,s,"Message",uType);
00256 }
00257 
00258 inline void dMB(const char *s){
00259     ::MessageBox(NULL,s,"Message",MB_OK);
00260 }
00261 #   undef SET_VA_LIST_DMB
00262 
00263     
00264 }//end of dkutil namespace
00265 
00266 #endif //end of include once
00267 

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