QGpCoreTools/TraceBug.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2008-10-20
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef TRACEBUG_H
00029 #define TRACEBUG_H
00030 
00031 #include "QGpCoreToolsDLLExport.h"
00032 #include "TraceInfo.h"
00033 
00034 namespace QGpCoreTools {
00035 
00036 #define TRACE_BUG \
00037   static TraceStamp _traceBugStamp_(__PRETTY_FUNCTION__, __LINE__); \
00038   TraceBug _traceBug_0(&_traceBugStamp_); \
00039   TraceBug * _traceBug_=&_traceBug_0; \
00040   Q_UNUSED(_traceBug_);
00041 
00042 // Better to use ##__COUNTER__ macro but not working with gcc 4.1.3, maybe gcc 4.3
00043 #define TRACE_BUG_N(index) \
00044   static TraceStamp _traceBugStamp_##index(__PRETTY_FUNCTION__, __LINE__); \
00045   TraceBug _traceBug_##index(&_traceBugStamp_##index); \
00046   _traceBug_=&_traceBug_##index;
00047 
00048 #define TRACE_BUG_POINTER(val) \
00049   _traceBug_->append( # val,val);
00050 
00051 #define TRACE_BUG_INT(val) \
00052   _traceBug_->append( # val,val);
00053 
00054 #define TRACE_BUG_BOOL(val) \
00055   _traceBug_->append( # val,val);
00056 
00057 #define TRACE_BUG_DOUBLE(val) \
00058   _traceBug_->append( # val,val);
00059 
00060 #define TRACE_BUG_STRING(val) \
00061   _traceBug_->append( # val,val);
00062 
00063 class TraceStamp;
00064 
00065 class QGPCORETOOLS_EXPORT TraceBug
00066 {
00067 public:
00068   TraceBug(const TraceStamp * stamp);
00069   ~TraceBug();
00070 
00071   inline void append(const char * valName, const void * val);
00072   inline void append(const char * valName, QVariant val);
00073 
00074   static QStack<TraceBug *> * mainStack() {return &_mainStack;}
00075   static QString backTrace(const QStack<TraceBug *> * stack);
00076 private:
00077   QString toString() const;
00078 
00079   QStack<TraceBug *> * _myStack;
00080   static QStack<TraceBug *> _mainStack;
00081 
00082   const TraceStamp * _stamp;
00083   QList<TraceInfo> _infos;
00084 };
00085 
00086 inline void TraceBug::append(const char * valName, const void * val)
00087 {
00088   _infos.append(TraceInfo(valName, val));
00089 }
00090 
00091 inline void TraceBug::append(const char * valName, QVariant val)
00092 {
00093   _infos.append(TraceInfo(valName, val));
00094 }
00095 
00096 } // namespace QGpCoreTools
00097 
00098 #endif // TRACEBUG_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines