QGpCoreTools/TraceLog.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: 2010-05-24
00022 **  Authors:
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef TRACELOG_H
00028 #define TRACELOG_H
00029 
00030 #include "TraceInfo.h"
00031 #include "QGpCoreToolsDLLExport.h"
00032 
00033 namespace QGpCoreTools {
00034 
00035 #define TRACE_LOG \
00036   static TraceStamp _traceLogStamp_(__PRETTY_FUNCTION__, __LINE__); \
00037   TraceLog * _traceLog_=new TraceLog(&_traceLogStamp_); \
00038   Q_UNUSED(_traceLog_);
00039 
00040 // Better to use ##__COUNTER__ macro but not working with gcc 4.1.3, maybe gcc 4.3
00041 #define TRACE_LOG_N(index) \
00042   static TraceStamp _traceLogStamp_##index(__PRETTY_FUNCTION__, __LINE__); \
00043   _traceLog_=new TraceLog(&_traceLogStamp_);
00044 
00045 #define TRACE_LOG_POINTER(val) \
00046   _traceLog_->append( # val,val);
00047 
00048 #define TRACE_LOG_INT(val) \
00049   _traceLog_->append( # val,val);
00050 
00051 #define TRACE_LOG_BOOL(val) \
00052   _traceLog_->append( # val,val);
00053 
00054 #define TRACE_LOG_DOUBLE(val) \
00055   _traceLog_->append( # val,val);
00056 
00057 #define TRACE_LOG_STRING(val) \
00058   _traceLog_->append( # val,val);
00059 
00060 class TraceStamp;
00061 
00062 class QGPCORETOOLS_EXPORT TraceLog
00063 {
00064 public:
00065   TraceLog(const TraceStamp * stamp);
00066 
00067   inline void append(const char * valName, const void * val);
00068   inline void append(const char * valName, QVariant val);
00069 
00070   static QVector<TraceLog *> * mainVector() {return &_mainVector;}
00071   static QString backTrace(const QVector<TraceLog *> * log);
00072   static void clearMainVector() {qDeleteAll(_mainVector);}
00073 private:
00074   QString toString() const;
00075 
00076   static QVector<TraceLog *> _mainVector;
00077 
00078   const TraceStamp * _stamp;
00079   QList<TraceInfo> _infos;
00080 };
00081 
00082 inline void TraceLog::append(const char * valName, const void * val)
00083 {
00084   _infos.append(TraceInfo(valName, val));
00085 }
00086 
00087 inline void TraceLog::append(const char * valName, QVariant val)
00088 {
00089   _infos.append(TraceInfo(valName, val));
00090 }
00091 
00092 } // namespace QGpCoreTools
00093 
00094 #endif // TRACELOG_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines