BESDebug.h

Go to the documentation of this file.
00001 // BESDebug.h
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
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 
00061 #define BESDEBUG( x, y ) { if( BESDebug::IsSet( x ) ) *(BESDebug::GetStrm()) << y ; }
00062 
00080 #define BESISDEBUG( x ) BESDebug::IsSet( x )
00081 
00082 class BESDebug
00083 {
00084 private:
00085     static map<string,bool>     _debug_map ;
00086     static ostream *            _debug_strm ;
00087     static bool                 _debug_strm_created ;
00088     typedef map<string,bool>::const_iterator _debug_citer ;
00089 public:
00100     static void                 Set( const string &flagName, bool value )
00101                                 {
00102                                     _debug_map[flagName] = value ;
00103                                 }
00111     static void                 Register( const string &flagName )
00112                                 {
00113                                     _debug_citer i = _debug_map.find( flagName ) ;
00114                                     if( i == _debug_map.end() )
00115                                     {
00116                                         _debug_map[flagName] = false ;
00117                                     }
00118                                 }
00124     static bool                 IsSet( const string &flagName )
00125                                 {
00126                                     _debug_citer i = _debug_map.find( flagName ) ;
00127                                     if( i != _debug_map.end() )
00128                                         return (*i).second ;
00129                                     else
00130                                         i = _debug_map.find( "all" ) ;
00131                                         if( i != _debug_map.end() )
00132                                             return (*i).second ;
00133                                         else
00134                                             return false ;
00135                                 }
00142     static ostream *            GetStrm()
00143                                 {
00144                                     return _debug_strm ;
00145                                 }
00161     static void                 SetStrm( ostream *strm, bool created )
00162                                 {
00163                                     if( _debug_strm_created && _debug_strm )
00164                                     {
00165                                         delete _debug_strm ;
00166                                         _debug_strm = NULL ;
00167                                     }
00168                                     if( !strm )
00169                                     {
00170                                         _debug_strm = &cerr ;
00171                                         _debug_strm_created = false ;
00172                                     }
00173                                     else
00174                                     {
00175                                         _debug_strm = strm ;
00176                                         _debug_strm_created = created ;
00177                                     }
00178                                 }
00179     static void                 SetUp( const string &values ) ;
00180     static void                 Help( ostream &strm ) ;
00181 } ;
00182 
00183 #endif // I_BESDebug_h
00184 
00185 /*
00186 int
00187 main( int argc, char **argv )
00188 {
00189     int some_number = 1 ;
00190     BESDEBUG( "something", "Shouldn't be seeing this part 1: " << some_number++ << endl )
00191     BESDebug::Set( "something", false ) ;
00192     BESDEBUG( "something", "Shouldn't be seeing this part 2: " << some_number++ << endl )
00193     BESDebug::Set( "something", true ) ;
00194     BESDEBUG( "something", "Should be seeing this: " << some_number++ << endl )
00195 
00196     return 0 ;
00197 }
00198 */
00199 

Generated on Wed Jan 2 06:01:18 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.4