SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送
メインページ   名前空間一覧   クラス階層   構成   ファイル一覧   名前空間メンバ   構成メンバ   ファイルメンバ  

dkutilTerminator.h

解説を見る。
00001 #include "AllLoad.h"
00002 
00003 
00004 #ifndef __dkutilTerminator_Once_Include__
00005 #define __dkutilTerminator_Once_Include__
00006 
00007 namespace dkutil{//begin dkutil
00008 
00009 inline debug_string_queue *GetStrQ(){
00010     static ::dkutil::DTL::dk_singleton<debug_string_queue > getq;//エラーストリングのキュー
00011     return getq.get();
00012 }
00013 
00014 
00015 
00017 class ITermination{
00018 protected:
00019 public:
00020     ITermination(){
00021         SetDebugStringQueuePutErrorLogFileName();
00022     }
00023     virtual ~ITermination(){
00024         DefaultTermination();
00025     }
00026     void DefaultTermination(){
00027         //GetDebug()->GetStrQ();
00028         FILE *fp=NULL;
00029         if(NULL == (fp = ::fopen( SetDebugStringQueuePutErrorLogFileName() , "at" )))
00030             return;     
00031         debug_string_queue *get= GetStrQ();
00032         for(debug_string_queue::iterator i=get->begin();
00033             i != get->end();i++){
00034                 
00035                 const char *getstr=(*i).c_str();
00036                 if('\n'!=getstr[(*i).length()-1]){
00037                     (*i).append("\n");
00038                 }
00039                 char *getstr2=(char *)(*i).c_str();
00040                 ::fputs(getstr2,fp);
00041         }
00042         
00043         ::fclose(fp);
00044     }
00045     
00046     bool SetQueueErrorString(char *str,...){
00047         DWORD len=dkutil::DTL::GetKB<3>::value;
00048         char s[dkutil::DTL::GetKB<3>::value];
00049         SET_VA_LIST(s,len,str);
00050         debug_string_queue *p=GetStrQ();
00051         p->push_back(s);
00052         //p->back().copy(s,len);
00053         //std::string &st=p->back();
00054         //st.copy(s,);
00055         return true;
00056     }
00057     inline char *SetDebugStringQueuePutErrorLogFileName(char *str=NULL){
00058         static char name[MAX_PATH];
00059         static bool initedflag=false;
00060         if(initedflag==false){
00061             //atexit(DebugStringQueuePush);//キューに入れた奴は終了時に吐く
00062             strncpy(name,"DebugStringQueueLog.log",MAX_PATH);
00063             initedflag=true;
00064         }
00065         if(str !=NULL)
00066             strncpy(name,str,MAX_PATH);
00067         return name;
00068     }
00069     virtual int Termination(){return 0;}
00070     virtual int ForcedTermination(){return 0;}
00071 };
00072 
00073 
00074 
00075 //終了関数はすべてまとめるべし!!!
00076 class dKingyoTermination : public ITermination{
00077 public:
00078     struct tugTerminationFunc{
00079          tugTerminationFunc(VOIDFUNC set=NULL) : setf(set){}
00080         VOIDFUNC setf;
00081     };
00082 protected:
00083     
00084     typedef std::deque<tugTerminationFunc> TerQ;
00085     TerQ q;
00086 public:
00087     
00088     virtual void SetEndFunction(VOIDFUNC f){
00089         q.push_back( tugTerminationFunc(f) );
00090     }
00091     virtual int Termination(){
00092         //普通に終了する時
00093         tugTerminationFunc getfunc=NULL;
00094         for(TerQ::iterator i=q.begin();i!=q.end();i++){
00095                 getfunc=*i;
00096                 if((getfunc.setf) !=NULL)
00097                     getfunc.setf();
00098         }
00099         return 0;
00100     }
00101     virtual int ForcedTermination(){
00102         SetQueueErrorString("ForcedTermination 強制終了です。\n");
00103         Termination();
00104         return 0;
00105     }
00106 };
00107 
00108 inline dKingyoTermination *GetTerminator(){
00109     static dKingyoTermination data;
00110     return &data;
00111 }
00112 
00113 
00114 
00115 
00116 }//end of dkutil namespace
00117 
00118 #endif // end of once include

dKingyoUtilClass (dkutil)に対してMon Jun 9 01:32:41 2003に生成されました。 doxygen1.3