-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcake_Debug.hpp
58 lines (48 loc) · 1.1 KB
/
cake_Debug.hpp
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
#pragma once
BEGIN_CAKE_NAMESPACE
inline void Debug::print(char inChar)
{
mPrintCallback(inChar);
}
inline void Debug::print(const char* inString)
{
if (inString != nullptr && mPrintCallback != nullptr)
{
do
{
mPrintCallback(*inString);
}
while (*inString++);
}
}
inline void Debug::printNumber(long inNum)
{
const bool negative = inNum < 0;
unsigned long num = negative ? -1 * inNum : inNum;
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
char *str = &buf[sizeof(buf) - 1];
*str = 0;
do
{
const long digit = num;
num /= 10;
const char c = digit - 10 * num;
*--str = c < 10 ? c + '0' : c + 'a' - 10;
}
while(num);
if (negative)
print('-');
print(str);
}
inline void Debug::log(const char* inString)
{
print(inString);
print('\n');
print('\r');
}
// -----------------------------------------------------------------------------
void Debug::setPrintCallback(PrintCallback inCallback)
{
mPrintCallback = inCallback;
}
END_CAKE_NAMESPACE