00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00036 #ifndef I_BESDebug_h
00037 #define I_BESDebug_h 1
00038
00039 #include <iostream>
00040 #include <map>
00041 #include <string>
00042
00043 using std::cerr ;
00044 using std::endl ;
00045 using std::ostream ;
00046 using std::map ;
00047 using std::string ;
00048
00049 #include "BESUtil.h"
00050
00064 #define BESDEBUG( x, y ) if( BESDebug::IsSet( x ) ) *(BESDebug::GetStrm()) << "[" << BESDebug::GetPidStr() << "] " << y
00065
00083 #define BESISDEBUG( x ) BESDebug::IsSet( x )
00084
00085 class BESDebug
00086 {
00087 private:
00088 static map<string,bool> _debug_map ;
00089 static ostream * _debug_strm ;
00090 static bool _debug_strm_created ;
00091 static string _pid_str ;
00092 typedef map<string,bool>::const_iterator _debug_citer ;
00093 typedef map<string,bool>::iterator _debug_iter ;
00094 public:
00105 static void Set( const string &flagName, bool value )
00106 {
00107 if( flagName == "all" && value )
00108 {
00109 _debug_iter i = _debug_map.begin() ;
00110 _debug_iter e = _debug_map.end() ;
00111 for( ; i != e; i++ )
00112 {
00113 (*i).second = true ;
00114 }
00115 }
00116 _debug_map[flagName] = value ;
00117 }
00125 static void Register( const string &flagName )
00126 {
00127 _debug_citer a = _debug_map.find( "all" ) ;
00128 _debug_citer i = _debug_map.find( flagName ) ;
00129 if( i == _debug_map.end() )
00130 {
00131 if( a == _debug_map.end() )
00132 {
00133 _debug_map[flagName] = false ;
00134 }
00135 else
00136 {
00137 _debug_map[flagName] = true ;
00138 }
00139 }
00140 }
00146 static bool IsSet( const string &flagName )
00147 {
00148 _debug_citer i = _debug_map.find( flagName ) ;
00149 if( i != _debug_map.end() )
00150 return (*i).second ;
00151 else
00152 i = _debug_map.find( "all" ) ;
00153 if( i != _debug_map.end() )
00154 return (*i).second ;
00155 else
00156 return false ;
00157 }
00164 static ostream * GetStrm()
00165 {
00166 return _debug_strm ;
00167 }
00168
00173 static string GetPidStr()
00174 {
00175 if( _pid_str.empty() )
00176 {
00177 char mypid[12] ;
00178 BESUtil::fastpidconverter( mypid, 10 ) ;
00179 _pid_str = mypid ;
00180 }
00181 return _pid_str ;
00182 }
00198 static void SetStrm( ostream *strm, bool created )
00199 {
00200 if( _debug_strm_created && _debug_strm )
00201 {
00202 _debug_strm->flush();
00203 delete _debug_strm ;
00204 _debug_strm = NULL ;
00205 }
00206 else if( _debug_strm )
00207 {
00208 _debug_strm->flush() ;
00209 }
00210 if( !strm )
00211 {
00212 _debug_strm = &cerr ;
00213 _debug_strm_created = false ;
00214 }
00215 else
00216 {
00217 _debug_strm = strm ;
00218 _debug_strm_created = created ;
00219 }
00220 }
00221 static void SetUp( const string &values ) ;
00222 static void Help( ostream &strm ) ;
00223 } ;
00224
00225 #endif // I_BESDebug_h
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244