debug.h
Go to the documentation of this file.
1
/* Copyright 2020 CNRS-AIST JRL */
2
3
#pragma once
4
5
#ifndef NO_LOG
6
inline
constexpr
bool
NO_LOG_
= 0;
7
#else
8
inline
constexpr
bool
NO_LOG_
= 1;
9
#endif
10
11
#ifdef NDEBUG
12
inline
constexpr
bool
DEBUG_OUTPUT
= 0;
13
#else
14
inline
constexpr
bool
DEBUG_OUTPUT
= 1;
15
#endif
16
17
#define JRLQP_PP_ID(x) x
18
19
#define JRLQP_PP_APPLY(macro, ...) JRLQP_PP_ID(macro(__VA_ARGS__))
20
22
#define JRLQP_PP_NARG(...) JRLQP_PP_ID(JRLQP_PP_NARG_(__VA_ARGS__, JRLQP_PP_RSEQ_N()))
23
#define JRLQP_PP_NARG_(...) JRLQP_PP_ID(JRLQP_PP_ARG_N(__VA_ARGS__))
24
#define JRLQP_PP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
25
#define JRLQP_PP_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
26
27
#define JRLQP_CHOOSE_AUTO_NAME_START(count) JRLQP_AUTO_NAME_ARG##count
28
29
#define JRLQP_AUTO_NAME_ARG(...) \
30
JRLQP_PP_ID(JRLQP_PP_APPLY(JRLQP_CHOOSE_AUTO_NAME_START, JRLQP_PP_NARG(__VA_ARGS__))(__VA_ARGS__))
31
32
#define JRLQP_AUTO_NAME_ARG1(x) #x, x
33
#define JRLQP_AUTO_NAME_ARG2(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG1(__VA_ARGS__))
34
#define JRLQP_AUTO_NAME_ARG3(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG2(__VA_ARGS__))
35
#define JRLQP_AUTO_NAME_ARG4(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG3(__VA_ARGS__))
36
#define JRLQP_AUTO_NAME_ARG5(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG4(__VA_ARGS__))
37
#define JRLQP_AUTO_NAME_ARG6(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG5(__VA_ARGS__))
38
#define JRLQP_AUTO_NAME_ARG7(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG6(__VA_ARGS__))
39
#define JRLQP_AUTO_NAME_ARG8(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG7(__VA_ARGS__))
40
#define JRLQP_AUTO_NAME_ARG9(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG8(__VA_ARGS__))
41
#define JRLQP_AUTO_NAME_ARG10(x, ...) #x, x, JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG9(__VA_ARGS__))
42
43
#define JRLQP_ENABLE_LOG_(macro, ...) \
44
do \
45
{ \
46
if(!NO_LOG_) \
47
{ \
48
JRLQP_PP_ID(macro(__VA_ARGS__)); \
49
} \
50
} while(0)
51
#define JRLQP_ENABLE_DEBUG_(macro, ...) \
52
do \
53
{ \
54
if(DEBUG_OUTPUT) \
55
{ \
56
JRLQP_PP_ID(macro(__VA_ARGS__)); \
57
} \
58
} while(0)
59
60
#define JRLQP_LOG_(logger, flags, ...) \
61
JRLQP_PP_ID(logger.log(static_cast<uint32_t>(flags), JRLQP_PP_ID(JRLQP_AUTO_NAME_ARG(__VA_ARGS__))))
62
#define JRLQP_LOG_AS_(logger, flags, ...) JRLQP_PP_ID(logger.log(static_cast<uint32_t>(flags), __VA_ARGS__))
63
#define JRLQP_LOG(...) JRLQP_PP_ID(JRLQP_ENABLE_LOG_(JRLQP_LOG_, __VA_ARGS__))
64
#define JRLQP_DBG(...) JRLQP_PP_ID(JRLQP_ENABLE_DEBUG_(JRLQP_LOG_, __VA_ARGS__))
65
#define JRLQP_LOG_AS(...) JRLQP_PP_ID(JRLQP_ENABLE_LOG_(JRLQP_LOG_AS_, __VA_ARGS__))
66
#define JRLQP_DBG_AS(...) JRLQP_PP_ID(JRLQP_ENABLE_DEBUG_(JRLQP_LOG_AS_, __VA_ARGS__))
67
68
#define JRLQP_LOG_COMMENT(logger, flag, ...) \
69
JRLQP_PP_ID(JRLQP_ENABLE_LOG_(logger.comment, static_cast<uint32_t>(flag), __VA_ARGS__))
70
#define JRLQP_DBG_COMMENT(logger, flag, ...) \
71
JRLQP_PP_ID(JRLQP_ENABLE_DEBUG_(logger.comment, static_cast<uint32_t>(flag), __VA_ARGS__))
72
73
#define JRLQP_LOG_NEW_ITER(logger, it) JRLQP_ENABLE_LOG_(logger.startIter, it)
74
#define JRLQP_DBG_NEW_ITER(logger, it) JRLQP_ENABLE_DEBUG_(logger.startIter, it)
75
76
#define JRLQP_LOG_RESET(logger) JRLQP_ENABLE_LOG_(logger.startIter, -1)
77
#define JRLQP_DBG_RESET(logger) JRLQP_ENABLE_DEBUG_(logger.startIter, -1)
78
79
#define JRLQP_DEBUG_ONLY(expr) \
80
do \
81
{ \
82
if(DEBUG_OUTPUT) \
83
{ \
84
expr; \
85
} \
86
} while(0)
DEBUG_OUTPUT
constexpr bool DEBUG_OUTPUT
Definition:
debug.h:14
NO_LOG_
constexpr bool NO_LOG_
Definition:
debug.h:6
include
jrl-qp
utils
debug.h
Generated by
1.8.17