QGpCoreTools/Trace.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 : 2007-12-26
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef TRACE_H
00029 #define TRACE_H
00030 
00031 #include "QGpCoreToolsDLLExport.h"
00032 #include "TraceStamp.h"
00033 
00034 namespace QGpCoreTools {
00035 
00036 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
00037 #define TRACE_ENABLED
00038 #else
00039 #define TRACE_DISABLED
00040 #endif
00041 
00042 #ifdef TRACE_ENABLED
00043 
00044 #define TRACE \
00045   static TraceStamp _traceStamp_(__PRETTY_FUNCTION__, __LINE__); \
00046   Trace _trace_0(&_traceStamp_);
00047 
00048 // Better to use ##__COUNTER__ macro but not working with gcc 4.1.3, maybe gcc 4.3
00049 #define TRACE_N(index) \
00050   static TraceStamp _traceStamp_##index(__PRETTY_FUNCTION__, __LINE__); \
00051   Trace _trace_##index(&_traceStamp_##index);
00052 
00053 class QGPCORETOOLS_EXPORT Trace
00054 {
00055 public:
00056   Trace(const TraceStamp * stamp);
00057   ~Trace();
00058 
00059   static QStack<const TraceStamp *> * mainStack() {return &_mainStack;}
00060   static QString backTrace(const QStack<const TraceStamp *> * stack);
00061 private:
00062   QStack<const TraceStamp *> * _myStack;
00063   static QStack<const TraceStamp *> _mainStack;
00064 };
00065 
00066 #else
00067 #define TRACE
00068 #endif
00069 
00070 } // namespace QGpCoreTools
00071 
00072 #endif // TRACE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines