-
Notifications
You must be signed in to change notification settings - Fork 12
/
command_debug.h
80 lines (61 loc) · 2.36 KB
/
command_debug.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// commands_debug.h
//
#pragma once
#include "config.h"
#if CB_DEBUG_TAG_COMMANDS
#include <algorithm>
#include <cassert>
#include <string>
#if CB_DEBUG_COMMANDS_PRINT
#include <sstream>
#endif
namespace cb
{
namespace detail
{
struct packet_debug
{
static const int kSize = 128;
void setTag(const std::string& str)
{
assert(str.size() < kSize);
std::copy(str.begin(), str.end(), tag);
tag[str.size()] = '\0';
}
void setTag(const std::string& str1, const std::string& str2)
{
size_t size = str1.size() + str2.size() + 3;
assert(size < kSize);
const std::string str = str1 + " : " + str2;
std::copy(str.begin(), str.end(), tag);
tag[size] = '\0';
}
void setTag(const std::string& str1, const std::string& str2, const std::string& str3)
{
size_t size = str1.size() + str2.size() + 3 + str3.size() + 3;
assert(size < kSize);
const std::string str = str1 + " : " + str2 + " : " + str3;
std::copy(str.begin(), str.end(), tag);
tag[size] = '\0';
}
char tag[kSize];
};
} // namespace detail
} // namespace cb
#define CB_DEBUG_STRINGIFY(x) #x
#define CB_DEBUG_TOSTRING(x) CB_DEBUG_STRINGIFY(x)
#define CB_DECLARE_COMMAND_DEBUG() cb::detail::packet_debug debug;
#define CB_DEBUG_COMMAND_TAG(cmd) \
cb::CommandPacket::command(cmd).debug.setTag(std::string(__FUNCTION__), CB_DEBUG_TOSTRING(__LINE__), \
cb::CommandPacket::commandName(cmd));
#define CB_DEBUG_COMMAND_TAG_MSG(cmd, msg) \
cb::CommandPacket::command(cmd).debug.setTag(std::string(__FUNCTION__), CB_DEBUG_TOSTRING(__LINE__), \
cb::CommandPacket::commandName(cmd) + " : " + msg);
#define CB_DEBUG_COMMAND_SET_MSG(cmd, msg) cb::CommandPacket::command(cmd).debug.setTag(msg);
#else
#define CB_DECLARE_COMMAND_DEBUG()
#define CB_DEBUG_COMMAND_TAG(cmd)
#define CB_DEBUG_COMMAND_TAG_MSG(cmd, msg)
#define CB_DEBUG_COMMAND_SET_MSG(cmd, msg)
#endif // #ifdef CB_DEBUG_TAG_COMMANDS