Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

ExCTrace.h

Go to the documentation of this file.
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.4 2002/08/21 12:03:03 data Exp $
00050  *
00051  */
00052 
00053 #ifndef EXCTRACE_H__
00054 #define EXCTRACE_H__
00055 
00056 #include <string>
00057 #include <iostream>
00058 #include <fstream>
00059 
00060 
00061 /*
00062         Traceable call stack
00063         Before compiling make your choice betwene
00064         1) NORMAL
00065         2) TRACE
00066         3) DEBUG
00067         4) LOG
00068         
00069         NORMAL :
00070                 Guard and UnGard are defined as nothing use only when you 
00071                 have finish your programe
00072         TRACE :
00073                 Each function call will be show on consol and each 
00074                 function out to
00075         DEBUG :
00076                 If any exception occure you will show on consol the 
00077                 call stack and where the programme bug ...
00078         LOG     :
00079                 Same as Debug but all is redirect to log.txt
00080 */
00081 
00082 #ifndef UNIX_SRC
00083         // under WIN32 change here
00084         // UNIX users use the configure script
00085         #define DEBUG
00086 #endif
00087 #define EXC throw 1;
00088  
00089 //#ifndef UNIX_SRC
00090         #ifdef NORMAL
00091                 #define Guard(function) 
00092                 #define UnGuard
00093                 #define Trace
00094                 #define Error
00095         #else 
00096         #ifdef LOG
00097                 static ofstream logfile("callstack.log",ios::app);\
00098                 std::cout=logfile;
00099                 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00100                                                                                 try {
00101                 #define UnGuard } catch (...) {\
00102                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00103                                                                                 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00104                                                                                 std::cout<<"* Date   : "<<asctime(ttb);\
00105                                                                                 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00106                                                                                 std::cout<<"* Line   : "<<__LINE__<<std::endl;\
00107                                                                                 std::cout<<"* File   : "<<__FILE__<<std::endl;\
00108                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00109                                                                                 std::cout<<"***************************************************"<<std::endl;\
00110                                                                                 throw; }
00111         #elif defined DEBUG
00112                 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00113                                                                                 try {
00114                 #define UnGuard } catch (...) {\
00115                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00116                                                                                 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00117                                                                                 std::cout<<"* Date   : "<<asctime(ttb);\
00118                                                                                 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00119                                                                                 std::cout<<"* Line   : "<<__LINE__<<std::endl;\
00120                                                                                 std::cout<<"* File   : "<<__FILE__<<std::endl;\
00121                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00122                                                                                 std::cout<<"***************************************************"<<std::endl;\
00123                                                                                 throw; }
00124         #elif defined TRACE
00125                 #ifdef UNIX_SRC
00126                         #include <pthread.h>
00127                         extern pthread_mutex_t mutex;
00128                         extern int trace_level;
00129                         #define Guard(fct) if (&mutex == NULL) pthread_mutex_init(&mutex, NULL);\
00130                                 static char* __FUNCTION_NAME__ = #fct;\
00131                                 pthread_mutex_lock (&mutex);\
00132                                 trace_level++;\
00133                                 pthread_mutex_unlock (&mutex);\
00134                                 std::cout<<">>>> " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;
00135                         #define UnGuard std::cout<<"<<<< " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;\
00136                                 pthread_mutex_lock (&mutex);\
00137                                 trace_level--;\
00138                                 pthread_mutex_unlock (&mutex);
00139                 #else
00140                         #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00141                                                                                         std::cout<<">>>> Module : "<<__FUNCTION_NAME__<<std::endl;
00142                         #define UnGuard                                 std::cout<<"<<<< Module : "<<__FUNCTION_NAME__<<std::endl;
00143                 #endif // !UNIX_SRC
00144         #endif //TRACE
00145         
00146         #define Trace(why) static char * __WHY__ = #why;\
00147                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00148                                                                                 std::cout<<"***********************TRACE***********************"<<std::endl;\
00149                                                                                 std::cout<<"* Date      : "<<asctime(ttb);\
00150                                                                                 std::cout<<"* Module    : "<<__FUNCTION_NAME__<<std::endl;\
00151                                                                                 std::cout<<"* Line      : "<<__LINE__<<std::endl;\
00152                                                                                 std::cout<<"* File      : "<<__FILE__<<std::endl;\
00153                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00154                                                                                 std::cout<<"* Cause     : "<<__WHY__<<std::endl;\
00155                                                                                 std::cout<<"* Error     : "<<errno<<std::endl;\
00156                                                                                 std::cout<<"***************************************************"<<std::endl;
00157         
00158         #endif // !NORMAL
00159 //#endif
00160                                                         
00161 #endif // EXCTRACE_H__

Generated on Tue Dec 10 18:20:05 2002 for ExNihilo by doxygen1.3-rc1