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  typedef map<string,bool> DebugMap;
89 
90  static DebugMap _debug_map ;
91  static ostream *_debug_strm ;
92  static bool _debug_strm_created ;
93 
94  typedef DebugMap::iterator _debug_iter ;
95 
96 public:
97  typedef DebugMap::const_iterator debug_citer ;
98 
99  static const DebugMap &debug_map()
100  {
101  return _debug_map;
102  }
103 
114  static void Set(const string &flagName, bool value)
115  {
116  if (flagName == "all" && value)
117  {
118  _debug_iter i = _debug_map.begin();
119  _debug_iter e = _debug_map.end();
120  for (; i != e; i++)
121  {
122  (*i).second = true;
123  }
124  }
125  _debug_map[flagName] = value;
126  }
127 
138  static void Register(const string &flagName)
139  {
140  debug_citer a = _debug_map.find("all");
141  debug_citer i = _debug_map.find(flagName);
142  if (i == _debug_map.end())
143  {
144  if (a == _debug_map.end())
145  {
146  _debug_map[flagName] = false;
147  }
148  else
149  {
150  _debug_map[flagName] = true;
151  }
152  }
153  }
154 
160  static bool IsSet(const string &flagName)
161  {
162  debug_citer i = _debug_map.find(flagName);
163  if (i != _debug_map.end())
164  return (*i).second;
165  else
166  i = _debug_map.find("all");
167  if (i != _debug_map.end())
168  return (*i).second;
169  else
170  return false;
171  }
172 
179  static ostream * GetStrm()
180  {
181  return _debug_strm;
182  }
183 
184  static string GetPidStr();
185 
201  static void SetStrm(ostream *strm, bool created)
202  {
203  if (_debug_strm_created && _debug_strm)
204  {
205  _debug_strm->flush();
206  delete _debug_strm;
207  _debug_strm = NULL;
208  }
209  else if (_debug_strm)
210  {
211  _debug_strm->flush();
212  }
213  if (!strm)
214  {
215  _debug_strm = &cerr;
216  _debug_strm_created = false;
217  }
218  else
219  {
220  _debug_strm = strm;
221  _debug_strm_created = created;
222  }
223  }
224 
225  static void SetUp( const string &values ) ;
226  static void Help( ostream &strm ) ;
227  static bool IsContextName( const string &name ) ;
228  static string GetOptionsString() ;
229 } ;
230 
231 #endif // I_BESDebug_h
232 
233 /*
234 int
235 main( int argc, char **argv )
236 {
237  int some_number = 1 ;
238  BESDEBUG( "something", "Shouldn't be seeing this part 1: "
239  << some_number++ << endl ) ;
240  BESDebug::Set( "something", false ) ;
241  BESDEBUG( "something", "Shouldn't be seeing this part 2: "
242  << some_number++ << endl ) ;
243  BESDebug::Set( "something", true ) ;
244  BESDEBUG( "something", "Should be seeing this: "
245  << some_number++ << endl ) ;
246 
247  return 0 ;
248 }
249 */
250