-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.h
58 lines (50 loc) · 1.38 KB
/
log.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
#ifndef SRC_LOG_H_
#define SRC_LOG_H_
#include <iostream>
#include <vector>
#include <sstream>
namespace wvm
{
// 打印整数类型的数据
template <typename T>
inline void logValue(const T &value, std::ostream &os)
{
os << value;
}
// 打印字符类型的数据
inline void logValue(char value, std::ostream &os)
{
os << "'" << value << "'";
}
// 打印std::vector<uint8_t>类型的数据
inline void logValue(const std::vector<uint8_t> &value, std::ostream &os)
{
os << "[ ";
for (const auto &item : value)
{
os << static_cast<int>(item) << " ";
}
os << "]";
}
// 可变参数模板,用于处理不同类型的参数
template <typename T>
inline void logValues(std::ostream &os, const T &value)
{
logValue(value, os);
}
template <typename T, typename... Args>
inline void logValues(std::ostream &os, const T &value, const Args &...args)
{
logValue(value, os);
logValues(os, args...);
}
}
// 定义LOG宏
#define LOG(...) \
do \
{ \
std::ostringstream oss; \
wvm::logValues(oss, __VA_ARGS__); \
std::cout << oss.str() << std::endl; \
} while (0)
#endif // SRC_LOG_H_