GpCoreTools/Trace.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GpCoreTools.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
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 General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2007-12-26
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef TRACE_H
00028 #define TRACE_H
00029 
00030 #include <vector>
00031 
00032 #include "GpCoreToolsDLLExport.h"
00033 #include "TraceStamp.h"
00034 
00035 namespace GpCoreTools {
00036 
00037 // Uncomment next line to get a backtrace in case of crash
00038 #define TRACE_ENABLED
00039 
00040 #ifdef TRACE_ENABLED
00041 
00042 #define TRACE \
00043   static TraceStamp _traceStamp_(__PRETTY_FUNCTION__, __LINE__); \
00044   Trace _trace_0(&_traceStamp_);
00045 
00046 // Better to use ##__COUNTER__ macro but not working with gcc 4.1.3, maybe gcc 4.3
00047 #define TRACE_N(index) \
00048   static TraceStamp _traceStamp_##index(__PRETTY_FUNCTION__, __LINE__); \
00049   Trace _trace_##index(&_traceStamp_##index);
00050 
00051 class GPCORETOOLS_EXPORT Trace
00052 {
00053 public:
00054   Trace(const TraceStamp * stamp);
00055   ~Trace();
00056 
00057   static std::vector<const TraceStamp *> * mainStack() {return &_mainStack;}
00058   static std::string backTrace(const std::vector<const TraceStamp *> * stack);
00059 private:
00060   std::vector<const TraceStamp *> * _myStack;
00061   static std::vector<const TraceStamp *> _mainStack;
00062 };
00063 
00064 #else
00065 #define TRACE
00066 #endif
00067 
00068 } // namespace GpCoreTools
00069 
00070 #endif // TRACE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines