-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.hpp
More file actions
121 lines (101 loc) · 3.24 KB
/
logger.hpp
File metadata and controls
121 lines (101 loc) · 3.24 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @file logger.hpp
* @author d.deka (https://ddeka0.github.io/)
* @brief
* @version 0.1
* @date 2021-02-14
*
*/
#pragma once
#include <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
# include <cxxabi.h>
#endif
#include <memory>
#include <string>
#include <cstdlib>
#include <iostream>
#include <utility>
#if defined(_MSC_VER)
#define PrintF std::cout << __FUNCSIG__ <<" "<< __LINE__ << std::endl;
#else
#define PrintF std::cout << __PRETTY_FUNCTION__<<" "<< __LINE__ << std::endl;
#endif
// https://stackoverflow.com/questions/29326460/how-to-make-a-variadic-macro-for-stdcout
inline void Log(){
// std::cout is not thread safe
std::cout << std::endl;
}
template<typename First, typename ...Rest>
void Log(First && first, Rest && ...rest) {
// std::cout is not thread safe
std::cout << std::forward<First>(first)<<" ";
Log(std::forward<Rest>(rest)...);
}
// C++ language standard detection
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) \
|| (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
#include <string_view>
#include <type_traits>
template <class T>
constexpr std::string_view type_name() {
using namespace std;
#ifdef __clang__
string_view p = __PRETTY_FUNCTION__;
return string_view(p.data() + 34, p.size() - 34 - 1);
#elif defined(__GNUC__)
string_view p = __PRETTY_FUNCTION__;
# if __cplusplus < 201402
return string_view(p.data() + 36, p.size() - 36 - 1);
# else
return string_view(p.data() + 49, p.find(';', 49) - 49);
# endif
#elif defined(_MSC_VER)
string_view p = __FUNCSIG__;
return string_view(p.data() + 84, p.size() - 84 - 7);
#endif
}
template<typename T>
struct refType {
static constexpr std::string_view type = (std::is_lvalue_reference<T>::value) > 0 ? "lvalue":"ravlue";
};
#define getRefType(expr) refType<decltype(expr)>::type
#define GetKeyTypeFromInternalLogic std::string
#define GetValueTypeFromInternalLogic int
#else
template <class T>
std::string
type_name()
{
typedef typename std::remove_reference<T>::type TR;
std::unique_ptr<char, void(*)(void*)> own
(
#ifndef _MSC_VER
abi::__cxa_demangle(typeid(TR).name(), nullptr,
nullptr, nullptr),
#else
nullptr,
#endif
std::free
);
std::string r = own != nullptr ? own.get() : typeid(TR).name();
if (std::is_const<TR>::value)
r += " const";
if (std::is_volatile<TR>::value)
r += " volatile";
if (std::is_lvalue_reference<T>::value)
r += "&";
else if (std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}
template<typename T>
struct refType {
static constexpr const char* type = (std::is_lvalue_reference<T>::value) > 0 ? "lvalue":"ravlue";
};
#define getRefType(expr) refType<decltype(expr)>::type
#define GetKeyTypeFromInternalLogic std::string
#define GetValueTypeFromInternalLogic int
#endif
#define BreakLine std::cout << std::endl << std::endl;