00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _TRACER_H_
00010 #define _TRACER_H_
00011 #include<string>
00012 #include<vector>
00013
00014 #ifdef WIN32
00015 #ifdef TRACER_EXPORTS
00016 #define PEXPR_API __declspec(dllexport)
00017 #else
00018 #define PEXPR_API __declspec(dllimport)
00019 #endif
00020 #else
00021 #define PEXPR_API
00022 #endif
00023
00024 using namespace std;
00025
00026 class PEXPR_API Tracer
00027 {
00028 public:
00029 static void init();
00030 Tracer( const string& enter, bool print = true );
00031 ~Tracer();
00032 static void enter( const string& function, bool print = true );
00033 static void debug ( const char* format, ... );
00034 static void error ( const char* error, ... );
00035 static void warn ( const char* warn, ... );
00036 static void stat ( const char* stat, ... );
00037 static void debug ( int level, const char* format, ... );
00038 static void error ( int level, const char* error, ... );
00039 static void warn ( int level, const char* warn, ... );
00040 static void stat ( int level, const char* stat, ... );
00041
00042 template<class ttype>
00043 static ttype& leave( ttype& rtn_value );
00044 static void leave();
00045 static int leave( int x ) { leave(); return x; }
00046 static void printTrace ( bool state ) { m_printtrace = state; }
00047 static void printDebug ( int state ) { m_printdebug = state; }
00048 static void printError ( int state ) { m_printerror = state; }
00049 static void printWarn ( int state ) { m_printwarn = state; }
00050 static void printStatus( int state ) { m_printstat = state; }
00051 static void setIndentSpaces( int num ) { m_indent = num; }
00052 private:
00053 static void printIndent();
00054
00055 static bool m_initialized;
00056 static vector< pair<string, bool> > m_stack;
00057 static bool m_printtrace;
00058 static int m_printdebug;
00059 static int m_printerror;
00060 static int m_printwarn;
00061 static int m_printstat;
00062 static int m_level;
00063 static int m_indent;
00064 };
00065
00066
00067
00073
00074 template<class ttype>
00075 ttype& Tracer::leave(ttype& rtn_value)
00076 {
00077 if( !m_printtrace || m_stack.size() == 0 ) return rtn_value;
00078 if( !m_stack.back().second )
00079 {
00080 m_stack.pop_back();
00081 return rtn_value;
00082 }
00083 printIndent();
00084 m_level--;
00085
00086 m_stack.pop_back();
00087 return rtn_value;
00088 }
00089 #endif