00001
00002
00003
00004
#ifndef GUARD_Debug_h
00005
#define GUARD_Debug_h
00006
00007
#include <iostream>
00008
#include <fstream>
00009
#include <string>
00010
#include <iomanip>
00011
00012
00013
#include <time.h>
00014
00015
00016
using namespace std;
00017
00018
static const bool debug =
true;
00019
00020
00021
00022
00023
00024
00025
00026 class Channel{
00027
friend class Trace;
00028
00029 ostream*
traceFile;
00030
public:
00031
00032
00033 Channel(ostream* o = &cout):
00034
traceFile(o)
00035 {}
00036
00037 void reset(ostream* o){
00038
traceFile = o;
00039 }
00040 };
00041
00042
00043
00044
00045
00046
00047
00048 class Trace{
00049
00050 Channel*
pChannel;
00051
00052 const char*
name;
00053
00054 bool display;
00055
00056 time_t
start,
end;
00057
public:
00058
00059
00060
00061
00062 Trace(
const char* _name,
Channel& _pChannel,
bool _display =
true){
00063
if(debug){
00064 time(&
start);
00065
name = _name;
00066
pChannel = &_pChannel;
00067
display = _display;
00068
00069
if(
pChannel->
traceFile &&
display){
00070 *
pChannel->
traceFile <<
"->\t" <<
name << endl;
00071 }
00072 }
00073 }
00074 ~
Trace(){
00075
if(debug){
00076 time(&end);
00077
00078
if(pChannel->
traceFile && display){
00079
float dif = difftime (end,start);
00080 *pChannel->
traceFile <<
"<-\t" << name << setw(10) << dif <<
" secondes" << endl;
00081 }
00082 }
00083 }
00084
00085 void print(
const char* txt){
00086
if(debug){
00087
if(
pChannel->
traceFile &&
display){
00088 *
pChannel->
traceFile <<
"\t" << txt << endl;
00089 }
00090 }
00091 }
00092
00093 void print(
const string txt){
00094
if(debug){
00095
if(
pChannel->
traceFile &&
display){
00096 *
pChannel->
traceFile <<
"\t" << txt << endl;
00097 }
00098 }
00099 }
00100
00101 };
00102
#endif