-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_print.h
More file actions
65 lines (47 loc) · 1.18 KB
/
debug_print.h
File metadata and controls
65 lines (47 loc) · 1.18 KB
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
#ifndef DEBUG_PRINT_H
#define DEBUG_PRINT_H
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <typeinfo>
#include <limits>
#include "dtypes.h"
#include "meta.h"
namespace Debug {
//-----
template<typename T> struct bytecaster{
using type = meta::Eval::IF_ELSE<(typeid(T).hash_code() == typeid(u8).hash_code()),u16,
meta::Eval::IF_ELSE<(typeid(T).hash_code() == typeid(s8).hash_code()),s16,
T>>;
};
//-----
template<typename T> std::string to_string(std::string name, T x){
std::stringstream ss;
ss << name << ": " << x;
return ss.str();
}
#define PRNVAR(_X) (to_string<bytecaster<decltype(_X)>::type>((#_X),(_X)))
//-----
template<typename T> std::string to_hstring(std::string name, T x){
std::stringstream ss;
bool is_int = std::numeric_limits<T>::is_integer;
if(is_int){
ss << name << ": " << "0x" << std::hex << x;
}else{
ss << name << ": " << x;
}
return ss.str();
}
#define PRNHEXVAR(_X) (to_hstring<bytecaster<decltype(_X)>::type>((#_X),(_X)))
//-----
#define DBGOUT(str) {cout<<(str)<<"\n";}
//-----
/*
class debug_print
{
public:
debug_print();
};*/
}//namespace
#endif // DEBUG_PRINT_H