OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESDebug.h
Go to the documentation of this file.
1 // BESDebug.h
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
36 #ifndef I_BESDebug_h
37 #define I_BESDebug_h 1
38 
39 #include <iostream>
40 #include <map>
41 #include <string>
42 
43 using std::cerr ;
44 using std::endl ;
45 using std::ostream ;
46 using std::map ;
47 using std::string ;
48 
49 #include "BESUtil.h"
50 
64 #define BESDEBUG( x, y ) do { if( BESDebug::IsSet( x ) ) *(BESDebug::GetStrm()) << "[" << BESDebug::GetPidStr() << "] " << y ; } while( 0 )
65 
83 #define BESISDEBUG( x ) BESDebug::IsSet( x )
84 
85 class BESDebug
86 {
87 private:
88  static map<string,bool> _debug_map ;
89  static ostream * _debug_strm ;
90  static bool _debug_strm_created ;
91  typedef map<string,bool>::const_iterator _debug_citer ;
92  typedef map<string,bool>::iterator _debug_iter ;
93 public:
104  static void Set( const string &flagName, bool value )
105  {
106  if( flagName == "all" && value )
107  {
108  _debug_iter i = _debug_map.begin() ;
109  _debug_iter e = _debug_map.end() ;
110  for( ; i != e; i++ )
111  {
112  (*i).second = true ;
113  }
114  }
115  _debug_map[flagName] = value ;
116  }
124  static void Register( const string &flagName )
125  {
126  _debug_citer a = _debug_map.find( "all" ) ;
127  _debug_citer i = _debug_map.find( flagName ) ;
128  if( i == _debug_map.end() )
129  {
130  if( a == _debug_map.end() )
131  {
132  _debug_map[flagName] = false ;
133  }
134  else
135  {
136  _debug_map[flagName] = true ;
137  }
138  }
139  }
145  static bool IsSet( const string &flagName )
146  {
147  _debug_citer i = _debug_map.find( flagName ) ;
148  if( i != _debug_map.end() )
149  return (*i).second ;
150  else
151  i = _debug_map.find( "all" ) ;
152  if( i != _debug_map.end() )
153  return (*i).second ;
154  else
155  return false ;
156  }
163  static ostream * GetStrm()
164  {
165  return _debug_strm ;
166  }
167 
168  static string GetPidStr() ;
169 
185  static void SetStrm( ostream *strm, bool created )
186  {
187  if( _debug_strm_created && _debug_strm )
188  {
189  _debug_strm->flush();
190  delete _debug_strm ;
191  _debug_strm = NULL ;
192  }
193  else if( _debug_strm )
194  {
195  _debug_strm->flush() ;
196  }
197  if( !strm )
198  {
199  _debug_strm = &cerr ;
200  _debug_strm_created = false ;
201  }
202  else
203  {
204  _debug_strm = strm ;
205  _debug_strm_created = created ;
206  }
207  }
208  static void SetUp( const string &values ) ;
209  static void Help( ostream &strm ) ;
210 } ;
211 
212 #endif // I_BESDebug_h
213 
214 /*
215 int
216 main( int argc, char **argv )
217 {
218  int some_number = 1 ;
219  BESDEBUG( "something", "Shouldn't be seeing this part 1: "
220  << some_number++ << endl ) ;
221  BESDebug::Set( "something", false ) ;
222  BESDEBUG( "something", "Shouldn't be seeing this part 2: "
223  << some_number++ << endl ) ;
224  BESDebug::Set( "something", true ) ;
225  BESDEBUG( "something", "Should be seeing this: "
226  << some_number++ << endl ) ;
227 
228  return 0 ;
229 }
230 */
231