-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.h
More file actions
63 lines (54 loc) · 1.87 KB
/
debug.h
File metadata and controls
63 lines (54 loc) · 1.87 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
// $Id: debug.h,v 1.10 2018-01-25 14:02:55-08 - - $
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include <bitset>
#include <climits>
#include <string>
using namespace std;
// debug -
// static class for maintaining global debug flags, each indicated
// by a single character.
// setflags -
// Takes a string argument, and sets a flag for each char in the
// string. As a special case, '@', sets all flags.
// getflag -
// Used by the DEBUGF macro to check to see if a flag has been set
// Not to be called by user code.
class debugflags {
private:
using flagset = bitset<UCHAR_MAX + 1>;
static flagset flags;
public:
static void setflags (const string& optflags);
static bool getflag (char flag);
static void where (char flag, const char* file, int line,
const char* pretty_function);
};
// DEBUGF -
// Macro which expands into trace code. First argument is a
// trace flag char, second argument is output code that can
// be sandwiched between <<. Beware of operator precedence.
// Example:
// DEBUGF ('u', "foo = " << foo);
// will print two words and a newline if flag 'u' is on.
// Traces are preceded by filename, line number, and function.
#ifdef NDEBUG
#define DEBUGF(FLAG,CODE) ;
#define DEBUGS(FLAG,STMT) ;
#else
#define DEBUGF(FLAG,CODE) { \
if (debugflags::getflag (FLAG)) { \
debugflags::where (FLAG, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
cerr << CODE << endl; \
} \
}
#define DEBUGS(FLAG,STMT) { \
if (debugflags::getflag (FLAG)) { \
debugflags::where (FLAG, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
STMT; \
} \
}
#endif
#endif