Inferno
0.2
|
00001 #ifndef HIT_COUNT_H 00002 #define HIT_COUNT_H 00003 00004 #include <string> 00005 #include <map> 00006 #include "standard.hpp" 00007 00008 class HitCount 00009 { 00010 public: 00011 struct Category 00012 { 00013 string file; // source file the HIT is in 00014 string function; // function the HIT is in 00015 unsigned line; // line the HIT is on 00016 unsigned step; // current step number 00017 const Traceable *instance; // "this" pointer of the function, differentiates between master and slaves 00018 }; 00019 00020 private: 00021 Map<Category, unsigned> counter; 00022 typedef pair<Category, unsigned> pc; 00023 unsigned current_step; 00024 static bool enable; 00025 00026 public: 00027 static HitCount instance; 00028 void Hit( string file, unsigned line, string function, const Traceable *caller_this ) 00029 { 00030 Category c; 00031 c.file = file; 00032 c.function = function; 00033 c.line = line; 00034 c.step = current_step; 00035 c.instance = caller_this; 00036 int count=0; 00037 if( counter.IsExist( c ) ) 00038 count = counter[c]; 00039 count++; 00040 counter[c] = count; 00041 } 00042 00043 void Usage(); 00044 void Check(); 00045 void Dump(); 00046 00047 void SetStep( int i ) 00048 { 00049 current_step = i; 00050 } 00051 00052 int GetStep() 00053 { 00054 return current_step; 00055 } 00056 00057 static void Enable( bool e ); ///< enable/disable hit counting, only for top level function to call, overridden by flags 00058 inline static bool IsEnabled() { return enable; } 00059 }; 00060 00061 extern bool operator<( const HitCount::Category &l, const HitCount::Category &r ); 00062 00063 #define HIT if(HitCount::IsEnabled()) HitCount::instance.Hit( __FILE__, __LINE__, INFERNO_CURRENT_FUNCTION, this ) 00064 00065 #endif 00066