-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.h
58 lines (49 loc) · 1.16 KB
/
trace.h
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
/*=============================================================================
# FileName: trace.h
# Desc: 调试类
# Author: hanxi
# Email: hanxi.com@gmail.com
# HomePage: http://hanxi.cnblogs.com
# Version: 0.0.1
# LastChange: 2013-03-08 13:05:03
# History:
=============================================================================*/
#ifndef __TRACE_H_
#define __TRACE_H_
#include <iostream>
using namespace std;
class Trace {
public:
Trace (const char *name);
~Trace ();
void debug (const string &msg);
static bool traceIsActive;
private:
string *theFunctionName;
};
bool Trace::traceIsActive = false;
inline
Trace::Trace(const char* name) : theFunctionName(0)
{
if (traceIsActive) {
//Conditional creation
theFunctionName = new string(name);
cout << "[Enter function]" << *theFunctionName << endl;
}
}
inline
void Trace::debug(const string &msg)
{
if (traceIsActive) {
cout << msg << endl;
}
}
inline
Trace::~Trace()
{
if (traceIsActive) {
cout << "[Exit function]" << *theFunctionName << endl;
delete theFunctionName;
}
}
#endif