-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDriver.cpp
68 lines (56 loc) · 2.16 KB
/
Driver.cpp
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
/*****************************************************************************/
/*!
\file Driver.cpp
\author Christian Sagel
\par email: c.sagel\@digipen.edu
\date 4/17/2016
\brief Driver for the Sample Zilch Engine project.
*/
/******************************************************************************/
// Packages
#include "Trace.h"
void TestTrace() {
Trace << "This is the base trace macro that uses the stream operator. \n";
}
/*============================================
Some examples of Trace macros you can write
=============================================*/
//----------------------------------------------------------------------------/
// Traces using the function name as a prefix
#define TraceFunction(message) Trace << __FUNCTION__ << ": " << message << "\n"
void TestTraceFunction() {
TraceFunction("I am tracing this function!");
}
//----------------------------------------------------------------------------/
// Now let's get "clever" regarding tracing. If for example we made every class
// that we use in our engine derive from a single base class that has a string identifier
// for the name of the object, we could do something like this!
class Object {
public:
std::string Name;
Object(const std::string& name) : Name(name) {}
};
// This macro will prefix the name of the object, then the function that
// is being called before the message
#define TraceObject(message) Trace << "[" << Name << "] "<< __FUNCTION__ << ": " << message << "\n"
class DerivedObject : public Object {
public:
DerivedObject() : Object("Coolio") {}
void TestTraceObject() {
TraceObject("Hello!");
}
};
//----------------------------------------------------------------------------/
int main(void) {
// Instantiate the trace object. It will create the file with the specified
// name and start redirectering output to it and stdio.
Debug::TraceObj.reset(new Debug::Tracer("Log.txt"));
// A simple trace, taking any string
TestTrace();
// A trace that prefixes the function name
TestTraceFunction();
// A trace that prefix the name of the object and the function name as well
auto object = DerivedObject();
object.TestTraceObject();
return 0;
}