Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

Tracer.h

Go to the documentation of this file.
00001 //=============================================================================
00002 // Tracer.h
00003 //  - This class provides an elegant way to manage printing the stack as 
00004 //  different functions are called and indents their start and stop tags to
00005 //  make seeing recusion easy
00006 //  
00007 //  Created 10/5/02 By Daniel Larimer
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 /* TRACER_EXPORTS */
00020 #else
00021 #define PEXPR_API
00022 #endif /* WIN32 */
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 //  Function Name: Tracer::leave
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 //    cout<<"Exit: "<<m_stack[m_stack.size()-1].first<<endl;
00086     m_stack.pop_back();
00087     return rtn_value;
00088 }
00089 #endif

Generated on Tue Jun 15 12:49:28 2004 for pexpr by doxygen 1.3.4