Page principale Liste des namespaces Hiérarchie des classes Liste par ordre alphabétique Liste des composants Liste des fichiers Membres des namespaces Composants Déclarations

# ExCTrace.h

Aller à la documentation de ce fichier.

    00001 /************************************************************************/
    00002 /* Ex Nihlo Engine by Hermanns Christophe                                                               */
    00003 /************************************************************************/
    00004 /* This program is free software; you can redistribute it and/or                */
    00005 /* modify it under the terms of the GNU General Public License                  */
    00006 /* as published by the Free Software Foundation; either version 2               */
    00007 /* of the License, or (at your option) any later version.                               */
    00008 /*                                                                                                                                              */
    00009 /* This program is distributed in the hope that it will be useful,              */
    00010 /* but WITHOUT ANY WARRANTY; without even the implied warranty of               */
    00011 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                 */
    00012 /*                                                                                                                                              */
    00013 /* See the GNU General Public License for more details.                                 */
    00014 /*                                                                                                                                              */
    00015 /* You should have received a copy of the GNU General Public License    */
    00016 /* along with this program; if not, write to the Free Software                  */
    00017 /* Foundation, Inc., 59 Temple Place - Suite 330,                                               */
    00018 /* Boston, MA  02111-1307, USA.                                                                                 */
    00019 /*                                                                                                                                              */
    00020 /* If you use a important part of this code please send me a mail               */
    00021 /* I just want to see where my code go thks :)                                                  */
    00022 /************************************************************************/
    00023
    00024 /************************************************************************/
    00025 /* Contact                                                              */
    00026 /************************************************************************/
    00027 /* ExNihilo Website :www.ploksoftware.org                               */
    00028 /*                                                                      */
    00029 /* Hermanns Christophe ExNihilo creator and main programmer             */
    00030 /*                                                                      */
    00031 /* Mail             : Data@ploksoftware.org                                                             */
    00032 /* ICQ              : 8030901                                                                                   */
    00033 /* MSN Messenger    : Data_7@hotmail.com                                                                */
    00034 /*                                                                      */
    00035 /* Benjamin Michotte Linux port, webmaster                              */
    00036 /*                                                                      */
    00037 /* Mail             :binny@ploksoftware.org                             */
    00038 /*                                                                      */
    00039 /************************************************************************/
    00040
    00041 /************************************************************************/
    00042 /* File Description                                                                                             */
    00043 /************************************************************************/
    00044 /* File Name   :ExCTrace.h                                                                                              */
    00045 /*                                                                                                                                              */
    00046 /* Star Date   :03/15/2002                                                                                              */
    00047 /*                                                                                                                                              */
    00048 /* Last Update :                                                        */
    00049 /* $Id: ExCTrace.h,v 1.5 2002/10/15 09:17:16 data Exp $
    00050  *
    00051  */
    00052
    00053 #ifndef EXCTRACE_H__
    00054 #define EXCTRACE_H__
    00055
    00056 #include <stdio.h>
    00057 #include <stdlib.h>
    00058 #include <iostream>
    00059 #include <fstream>
    00060 #ifndef GCC_295
    00061         #include <ostream>
    00062 #endif
    00063 #include <string.h>
    00064 #include <time.h>
    00065 #include <iostream>
    00066 #include <strstream>
    00067 #ifdef UNIX_SRC
    00068         #include <typeinfo>
    00069 #else
    00070         #include <typeinfo.h>
    00071 #endif
    00072 /*
    00073         Traceable call stack
    00074         Before compiling make your choice betwene
    00075         1) NORMAL
    00076         2) TRACE
    00077         3) DEBUG
    00078         4) LOG
    00079
    00080         NORMAL :
    00081                 Guard and UnGard are defined as nothing use only when you
    00082                 have finish your programe
    00083         TRACE :
    00084                 Each function call will be show on consol and each
    00085                 function out to
    00086         DEBUG :
    00087                 If any exception occure you will show on consol the
    00088                 call stack and where the programme bug ...
    00089         LOG     :
    00090                 Same as Debug but all is redirect to log.txt
    00091 */
    00092
    00093 #ifndef UNIX_SRC
    00094         // under WIN32 change here
    00095         // UNIX users use the configure script
    00096         #define DEBUG
    00097 #endif
    00098
    00099 #define EXC throw 1;
    00100
    00101 //#ifndef UNIX_SRC
    00102         #ifdef NORMAL
    00103                 #define Guard(function)
    00104                 #define UnGuard
    00105                 #define Trace
    00106                 #define Error
    00107         #else
    00108         #ifdef LOG
    00109         static std::ofstream logfile("callstack.log",std::ios::app);\
    00110                 std::cout=logfile;
    00111                 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
    00112                                                                                 try {
    00113                 #define UnGuard } catch (...) {\
    00114                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
    00115                                                                                 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
    00116                                                                                 std::cout<<"* Date   : "<<asctime(ttb);\
    00117                                                                                 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
    00118                                                                                 std::cout<<"* Line   : "<<__LINE__<<std::endl;\
    00119                                                                                 std::cout<<"* File   : "<<__FILE__<<std::endl;\
    00120                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
    00121                                                                                 std::cout<<"***************************************************"<<std::endl;\
    00122                                                                                 throw; }
    00123         #elif defined DEBUG
    00124                 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
    00125                                                                                 try {
    00126                 #define UnGuard } catch (...) {\
    00127                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
    00128                                                                                 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
    00129                                                                                 std::cout<<"* Date   : "<<asctime(ttb);\
    00130                                                                                 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
    00131                                                                                 std::cout<<"* Line   : "<<__LINE__<<std::endl;\
    00132                                                                                 std::cout<<"* File   : "<<__FILE__<<std::endl;\
    00133                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
    00134                                                                                 std::cout<<"***************************************************"<<std::endl;\
    00135                                                                                 throw; }
    00136         #elif defined TRACE
    00137                 #ifdef UNIX_SRC
    00138                         #include <pthread.h>
    00139                         extern pthread_mutex_t mutex;
    00140                         extern int trace_level;
    00141                         #define Guard(fct) if (&mutex == NULL) pthread_mutex_init(&mutex, NULL);\
    00142                                 static char* __FUNCTION_NAME__ = #fct;\
    00143                                 pthread_mutex_lock (&mutex);\
    00144                                 trace_level++;\
    00145                                 pthread_mutex_unlock (&mutex);\
    00146                                 std::cout<<">>>> " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;
    00147                         #define UnGuard std::cout<<"<<<< " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;\
    00148                                 pthread_mutex_lock (&mutex);\
    00149                                 trace_level--;\
    00150                                 pthread_mutex_unlock (&mutex);
    00151                 #else
    00152                         #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
    00153                                                                                         std::cout<<">>>> Module : "<<__FUNCTION_NAME__<<std::endl;
    00154                         #define UnGuard                                 std::cout<<"<<<< Module : "<<__FUNCTION_NAME__<<std::endl;
    00155                 #endif // !UNIX_SRC
    00156         #endif //TRACE
    00157
    00158         #define Trace(why) static char * __WHY__ = #why;\
    00159                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
    00160                                                                                 std::cout<<"***********************TRACE***********************"<<std::endl;\
    00161                                                                                 std::cout<<"* Date      : "<<asctime(ttb);\
    00162                                                                                 std::cout<<"* Module    : "<<__FUNCTION_NAME__<<std::endl;\
    00163                                                                                 std::cout<<"* Line      : "<<__LINE__<<std::endl;\
    00164                                                                                 std::cout<<"* File      : "<<__FILE__<<std::endl;\
    00165                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
    00166                                                                                 std::cout<<"* Cause     : "<<__WHY__<<std::endl;\
    00167                                                                                 std::cout<<"* Error     : "<<errno<<std::endl;\
    00168                                                                                 std::cout<<"***************************************************"<<std::endl;
    00169
    00170         #endif // !NORMAL
    00171 //#endif
    00172
    00173 #endif // EXCTRACE_H__