replicode
debug.h
Go to the documentation of this file.
1 #ifndef DEBUG_H
2 #define DEBUG_H
3 #include <mutex>
4 #include <iostream>
5 #include <stdint.h>
6 
7 static std::mutex s_debugSection;
8 
11 {
12 public:
13  inline DebugStream(const std::string area) {
14  s_debugSection.lock();
15  std::cout << "\033[1;34m" << area << "\033[1;37m>\033[1;32m";
16  }
17 
19  std::cout << "\033[0m" << std::endl;
20  s_debugSection.unlock();
21  }
22 
23  static std::string timestamp(const uint64_t t) {
24  uint64_t us = t % 1000;
25  uint64_t ms = t / 1000;
26  uint64_t s = ms / 1000;
27  ms = ms % 1000;
28 
29  std::string _s = std::to_string(s);
30  _s += "s:";
31  _s += std::to_string(ms);
32  _s += "ms:";
33  _s += std::to_string(us);
34  _s += "us";
35 
36  return _s;
37  }
38 
39  inline const DebugStream &operator<<(const std::string output) const { std::cout << " " << output ; return *this; }
40  inline const DebugStream &operator<<(const uint64_t output) const { std::cout << " " << output; return *this; }
41  inline const DebugStream &operator<<(const double output) const { std::cout << " " << output; return *this; }
42  inline const DebugStream &operator<<(const int64_t output) const { std::cout << " " << output; return *this; }
43  inline const DebugStream &operator<<(const uint32_t output) const { std::cout << " " << output; return *this; }
44  inline const DebugStream &operator<<(const uint16_t output) const { std::cout << " " << output; return *this; }
45  inline const DebugStream &operator<<(const uint8_t output) const { std::cout << " " << (uint64_t)output; return *this; }
46  inline const DebugStream &operator<<(const char *output) const { std::cout << " " << output; return *this; }
47  inline const DebugStream &operator<<(const void *output) const { std::cout << std::hex << " 0x" << (uint64_t)output << std::dec; return *this; }
48  inline const DebugStream &operator<<(const bool output) const { std::cout << (output ? " true" : " false"); return *this; }
49 };
50 
51 static inline const DebugStream debug(const std::string area) { return DebugStream(area); }
52 
53 #endif // DEBUG_H
~DebugStream()
Definition: debug.h:18
const DebugStream & operator<<(const int64_t output) const
Definition: debug.h:42
Thread safe debug output.
Definition: debug.h:10
const DebugStream & operator<<(const void *output) const
Definition: debug.h:47
const DebugStream & operator<<(const uint32_t output) const
Definition: debug.h:43
const DebugStream & operator<<(const std::string output) const
Definition: debug.h:39
const DebugStream & operator<<(const uint8_t output) const
Definition: debug.h:45
static std::mutex s_debugSection
Definition: debug.h:7
const DebugStream & operator<<(const uint64_t output) const
Definition: debug.h:40
const DebugStream & operator<<(const double output) const
Definition: debug.h:41
static std::string timestamp(const uint64_t t)
Definition: debug.h:23
const DebugStream & operator<<(const bool output) const
Definition: debug.h:48
const DebugStream & operator<<(const uint16_t output) const
Definition: debug.h:44
static const DebugStream debug(const std::string area)
Definition: debug.h:51
DebugStream(const std::string area)
Definition: debug.h:13
const DebugStream & operator<<(const char *output) const
Definition: debug.h:46