trace.h
Go to the documentation of this file.
1 #ifndef TTG_TRACE_H
2 #define TTG_TRACE_H
3 
4 #include "ttg/util/print.h"
5 
6 namespace ttg {
7  namespace detail {
8  inline bool &trace_accessor() {
9  static bool trace = false;
10  return trace;
11  }
12  } // namespace detail
13 
15  inline constexpr bool trace_enabled() {
16 #ifdef TTG_ENABLE_TRACE
17  return true;
18 #else
19  return false;
20 #endif
21  }
22 
24 
28  inline bool tracing() {
29  if constexpr (trace_enabled())
30  return detail::trace_accessor();
31  else
32  return false;
33  }
34 
36  inline void trace_on() { if constexpr (trace_enabled()) detail::trace_accessor() = true; }
38  inline void trace_off() { if constexpr (trace_enabled()) detail::trace_accessor() = false; }
39 
42  template <typename T, typename... Ts>
43  inline void trace(const T &t, const Ts &... ts) {
44  if constexpr (trace_enabled()) {
45  if (tracing()) {
46  log(t, ts...);
47  }
48  }
49  }
50 
51 } // namespace ttg
52 
53 #endif // TTG_TRACE_H
bool & trace_accessor()
Definition: trace.h:8
top-level TTG namespace contains runtime-neutral functionality
Definition: keymap.h:8
void trace_off()
disables tracing; if trace_enabled()==true this has no effect
Definition: trace.h:38
void trace_on()
enables tracing; if trace_enabled()==true this has no effect
Definition: trace.h:36
void log(const T &t, const Ts &... ts)
atomically prints to std::clog a sequence of items (separated by ttg::print_separator) followed by st...
Definition: print.h:146
bool tracing()
returns whether tracing is enabled
Definition: trace.h:28
void trace(const T &t, const Ts &... ts)
Definition: trace.h:43
constexpr bool trace_enabled()
returns whether tracing was enabled at configure time
Definition: trace.h:15