[go: up one dir, main page]

Menu

[r11]: / gizmod3 / libH / Debug.hpp  Maximize  Restore  History

Download this file

167 lines (135 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
*********************************************************************
*************************************************************************
***
*** \file Debug.hpp
*** \brief Debug class header file
***
*****************************************
*****************************************
**/
/*
Copyright (c) 2006, Tim Burrell
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __Debug_h
#define __Debug_h
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <string>
//////////////////////////////////////////////////////////////////////////////
// Namespace
///////////////////////////////////////
/**
* \namespace H
* \brief H namespace
*
* This class belongs to libH
*/
namespace H {
//////////////////////////////////////////////////////////////////////////////
// Class Definition
///////////////////////////////////////
/**
* \class Debug
* \brief Debug stream class
*
* Debug stream class that implements cdbg (with varying verbosity levels)
* Use cdbg1 to send a debug message that will only be seen if the user has set
* debug level 1 or higher. The default is level 0.
*/
class Debug {
public:
/// Get whether or not debug is enabled
inline static bool getDebugEnabled() { return mDebug; };
/// Get the verbosity level
inline static bool getDebugVerbosity() { return mVerbosity; };
/// Set whether or not debug is enabled
inline static void setDebugEnabled(bool Enable) { mDebug = Enable; };
/// Set the verbosity level
inline static void setDebugVerbosity(int Verbosity) { mVerbosity = Verbosity; };
inline friend const Debug& operator << (const Debug & dbg, const char * s);
inline friend const Debug& operator << (const Debug & dbg, const std::string & s);
inline friend const Debug& operator << (const Debug & dbg, const char c);
inline friend const Debug& operator << (const Debug & dbg, const int d);
inline friend const Debug& operator << (const Debug & dbg, const double lf);
inline friend const Debug& operator << (const Debug & dbg, std::ostream&(*f)(std::ostream&)); // for endl
Debug(int ThisVerbosity);
virtual ~Debug();
private:
inline static bool testPrint(const Debug& dbg) { return ((dbg.mDebug) && (dbg.mVerbosity >= dbg.mThisVerbosity)); };
static bool mDebug; ///< is debug mode enabled?
int mThisVerbosity; ///< verbosity level of this debug object
static int mVerbosity; ///< global verbosity level set by the user
};
//////////////////////////////////////////////////////////////////////////////
/**
* Debug insertion operator for string
*/
inline const Debug& operator << (const Debug & dbg, const std::string & s) {
if (Debug::testPrint(dbg))
std::cout << s;
return dbg;
}
/**
* Debug insertion operator for const char *
*/
inline const Debug& operator << (const Debug & dbg, const char * s) {
if (Debug::testPrint(dbg))
std::cout << s;
return dbg;
}
/**
* Debug insertion operator for char
*/
inline const Debug& operator << (const Debug & dbg, const char c) {
if (Debug::testPrint(dbg))
std::cout << c;
return dbg;
}
/**
* Debug insertion operator for int
*/
inline const Debug& operator << (const Debug & dbg, const int i) {
if (Debug::testPrint(dbg))
std::cout << i;
return dbg;
}
/**
* Debug insertion operator for double
*/
inline const Debug& operator << (const Debug & dbg, const double lf) {
if (Debug::testPrint(dbg))
std::cout << lf;
return dbg;
}
/**
* Debug insertion operator for endl et al
*/
inline const Debug& operator << (const Debug & dbg, std::ostream&(* f)(std::ostream &)) {
if (Debug::testPrint(dbg))
std::cout << f;
return dbg;
}
static const Debug cdbg(0);
static const Debug cdbg1(1);
static const Debug cdbg2(2);
static const Debug cdbg3(3);
static const Debug cdbg4(4);
static const Debug cdbg5(5);
} // H namespace
//////////////////////////////////////////////////////////////////////////////
#endif // __Debug_h