GpCoreTools/TraceBug.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: 2008-10-20
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef TRACEBUG_H
00028 #define TRACEBUG_H
00029 
00030 #include <vector>
00031 #include <list>
00032 
00033 #include "Variant.h"
00034 #include "GpCoreToolsDLLExport.h"
00035 #include "TraceInfo.h"
00036 
00037 namespace GpCoreTools {
00038 
00039 #define TRACE_BUG \
00040   static TraceStamp _traceBugStamp_(__PRETTY_FUNCTION__, __LINE__); \
00041   TraceBug _traceBug_0(&_traceBugStamp_); \
00042   TraceBug * _traceBug_=&_traceBug_0;
00043 
00044 // Better to use ##__COUNTER__ macro but not working with gcc 4.1.3, maybe gcc 4.3
00045 #define TRACE_BUG_N(index) \
00046   static TraceStamp _traceBugStamp_##index(__PRETTY_FUNCTION__, __LINE__); \
00047   TraceBug _traceBug_##index(&_traceBugStamp_##index); \
00048   _traceBug_=&_traceBug_##index;
00049 
00050 #define TRACE_POINTER(val) \
00051   _traceBug_->append( # val,val);
00052 
00053 #define TRACE_INT(val) \
00054   _traceBug_->append( # val,val);
00055 
00056 #define TRACE_BOOL(val) \
00057   _traceBug_->append( # val,val);
00058 
00059 #define TRACE_DOUBLE(val) \
00060   _traceBug_->append( # val,val);
00061 
00062 #define TRACE_STRING(val) \
00063   _traceBug_->append( # val,val);
00064 
00065 class TraceStamp;
00066 
00067 class GPCORETOOLS_EXPORT TraceBug
00068 {
00069 public:
00070   TraceBug(const TraceStamp * stamp);
00071   ~TraceBug();
00072 
00073   inline void append(const char * valName, const void * val);
00074   inline void append(const char * valName, Variant val);
00075 
00076   static std::vector<TraceBug *> * mainStack() {return &_mainStack;}
00077   static std::string backTrace(const std::vector<TraceBug *> * stack);
00078 private:
00079   std::string toString() const;
00080 
00081   std::vector<TraceBug *> * _myStack;
00082   static std::vector<TraceBug *> _mainStack;
00083 
00084   const TraceStamp * _stamp;
00085   std::list<TraceInfo> _infos;
00086 };
00087 
00088 inline void TraceBug::append(const char * valName, const void * val)
00089 {
00090   _infos.push_back(TraceInfo(valName, val) );
00091 }
00092 
00093 inline void TraceBug::append(const char * valName, Variant val)
00094 {
00095   _infos.push_back(TraceInfo(valName, val) );
00096 }
00097 
00098 } // namespace GpCoreTools
00099 
00100 #endif // TRACEBUG_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines