00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "debughelper.h"
00023 #ifdef DBGHELPER_USES_PRINTF
00024 #include <stdio.h>
00025 #else
00026 #include <QtCore/QtDebug>
00027 #endif
00028
00029 using namespace GluonCore;
00030
00031 int DbgHelper::indent = 0;
00032 int DbgHelper::colorIndex = 0;
00033
00034 static void DbgHelper_output( int color, int indent, const QString& prefix, const QString& funcName )
00035 {
00036 QString text = QString( 4 * indent, ' ' ) + QString( prefix + funcName );
00037
00038 if( color >= 0 )
00039 {
00040 text.prepend( "\x1b[3" + QString::number( 1 + color ) + 'm' );
00041 text.append( "\x1b[39m" );
00042 }
00043
00044 #ifndef DBGHELPER_USES_PRINTF
00045 qDebug() << text;
00046 #else
00047 fprintf( stderr, "%s\n", qPrintable( text ) );
00048 #endif
00049 }
00050
00051 DbgHelper::DbgHelper()
00052 {
00053 noFunctionName = true;
00054
00055 #ifdef NO_COLOR
00056 myColor = -1;
00057 #else
00058 myColor = colorIndex;
00059 colorIndex = ( colorIndex + 1 ) % 7;
00060 #endif
00061 }
00062
00063 DbgHelper::DbgHelper( const QString& t )
00064 {
00065 noFunctionName = false;
00066 txt = t;
00067
00068 #ifdef NO_COLOR
00069 myColor = -1;
00070 #else
00071 myColor = colorIndex;
00072 colorIndex = ( colorIndex + 1 ) % 7;
00073 #endif
00074 DbgHelper_output( myColor, indent, "BEGIN ", txt );
00075
00076 ++indent;
00077 }
00078
00079 void DbgHelper::addText( const QString& t )
00080 {
00081 DbgHelper_output( myColor, indent, "", t );
00082 }
00083
00084 DbgHelper::~DbgHelper()
00085 {
00086 if( !noFunctionName )
00087 {
00088 --indent;
00089 DbgHelper_output( myColor, indent, "END ", txt );
00090 }
00091 }