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

ExCTrace.h

Go to the documentation of this file.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (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.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExCTrace.h,v 1.3 2002/08/06 16:52:58 binny Exp $
00021  *
00022  */
00023 
00024 #ifndef EXCTRACE_H__
00025 #define EXCTRACE_H__
00026 
00027 #include <string>
00028 #include <iostream>
00029 #include <fstream>
00030 
00031 //#include "ExCOptions.h"
00032 
00033 /*
00034         Traceable call stack
00035         Before compiling make your choice betwene
00036         1) NORMAL
00037         2) TRACE
00038         3) DEBUG
00039         4) LOG
00040         
00041         NORMAL :
00042                 Guard and UnGard are defined as nothing use only when you 
00043                 have finish your programe
00044         TRACE :
00045                 Each function call will be show on consol and each 
00046                 function out to
00047         DEBUG :
00048                 If any exception occure you will show on consol the 
00049                 call stack and where the programme bug ...
00050         LOG     :
00051                 Same as Debug but all is redirect to log.txt
00052 */
00053 
00054 #ifndef UNIX_SRC
00055         // under WIN32 change here
00056         // UNIX users use the configure script
00057         #define DEBUG
00058 #endif
00059 #define EXC throw 1;
00060  
00061 //#ifndef UNIX_SRC
00062         #ifdef NORMAL
00063                 #define Guard(function) 
00064                 #define UnGuard
00065                 #define Trace
00066                 #define Error
00067         #else 
00068         #ifdef LOG
00069                 static ofstream logfile("callstack.log",ios::app);\
00070                 std::cout=logfile;
00071                 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00072                                                                                 try {
00073                 #define UnGuard } catch (...) {\
00074                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00075                                                                                 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00076                                                                                 std::cout<<"* Date   : "<<asctime(ttb);\
00077                                                                                 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00078                                                                                 std::cout<<"* Line   : "<<__LINE__<<std::endl;\
00079                                                                                 std::cout<<"* File   : "<<__FILE__<<std::endl;\
00080                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00081                                                                                 std::cout<<"***************************************************"<<std::endl;\
00082                                                                                 throw; }
00083         #elif defined DEBUG
00084                 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00085                                                                                 try {
00086                 #define UnGuard } catch (...) {\
00087                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00088                                                                                 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00089                                                                                 std::cout<<"* Date   : "<<asctime(ttb);\
00090                                                                                 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00091                                                                                 std::cout<<"* Line   : "<<__LINE__<<std::endl;\
00092                                                                                 std::cout<<"* File   : "<<__FILE__<<std::endl;\
00093                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00094                                                                                 std::cout<<"***************************************************"<<std::endl;\
00095                                                                                 throw; }
00096         #elif defined TRACE
00097                 #ifdef UNIX_SRC
00098                         #include <pthread.h>
00099                         extern pthread_mutex_t mutex;
00100                         extern int trace_level;
00101                         #define Guard(fct) if (&mutex == NULL) pthread_mutex_init(&mutex, NULL);\
00102                                 static char* __FUNCTION_NAME__ = #fct;\
00103                                 pthread_mutex_lock (&mutex);\
00104                                 trace_level++;\
00105                                 pthread_mutex_unlock (&mutex);\
00106                                 std::cout<<">>>> " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;
00107                         #define UnGuard std::cout<<"<<<< " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;\
00108                                 pthread_mutex_lock (&mutex);\
00109                                 trace_level--;\
00110                                 pthread_mutex_unlock (&mutex);
00111                 #else
00112                         #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00113                                                                                         std::cout<<">>>> Module : "<<__FUNCTION_NAME__<<std::endl;
00114                         #define UnGuard                                 std::cout<<"<<<< Module : "<<__FUNCTION_NAME__<<std::endl;
00115                 #endif // !UNIX_SRC
00116         #endif //TRACE
00117         
00118         #define Trace(why) static char * __WHY__ = #why;\
00119                                                                                 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00120                                                                                 std::cout<<"***********************TRACE***********************"<<std::endl;\
00121                                                                                 std::cout<<"* Date      : "<<asctime(ttb);\
00122                                                                                 std::cout<<"* Module    : "<<__FUNCTION_NAME__<<std::endl;\
00123                                                                                 std::cout<<"* Line      : "<<__LINE__<<std::endl;\
00124                                                                                 std::cout<<"* File      : "<<__FILE__<<std::endl;\
00125                                                                                 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00126                                                                                 std::cout<<"* Cause     : "<<__WHY__<<std::endl;\
00127                                                                                 std::cout<<"* Error     : "<<errno<<std::endl;\
00128                                                                                 std::cout<<"***************************************************"<<std::endl;
00129         
00130         #endif // !NORMAL
00131 //#endif
00132                                                         
00133 #endif // EXCTRACE_H__

Generated on Tue Aug 6 20:27:10 2002 for ExNihilo by doxygen1.2.17