HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
debug.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 
17 #ifndef HF_DEBUG_H
18 #define HF_DEBUG_H
19 
20 #include <iostream>
21 #include <iomanip>
22 
29 // =============================================================================
30 // Defines
31 // =============================================================================
32 
34 #define NL std::endl;std::cout.clear();std::cerr.clear()
35 
36 #define HF_LOG_LEVEL_NONE 0
37 #define HF_LOG_LEVEL_ERROR 1
38 #define HF_LOG_LEVEL_WARN 2
39 #define HF_LOG_LEVEL_INFO 3
40 #define HF_LOG_LEVEL_DEBUG 4
41 #define HF_LOG_LEVEL_TRACE 5
42 
43 // Set default log level to HF_LOG_LEVEL_INFO.
44 #ifndef HF_LOG_LEVEL
45  #define HF_LOG_LEVEL HF_LOG_LEVEL_INFO
46 #endif
47 
48 #if HF_LOG_LEVEL >= HF_LOG_LEVEL_ERROR
49  #define ERROR std::cerr.clear();std::cerr << "[ERROR] "
50 #else
51  #define ERROR std::cerr.setstate(std::ios_base::badbit);std::cerr
52 #endif
53 
54 #if HF_LOG_LEVEL >= HF_LOG_LEVEL_WARN
55  #define WARN std::cerr.clear();std::cerr << "[WARN ] "
56 #else
57  #define WARN std::cerr.setstate(std::ios_base::badbit);std::cerr
58 #endif
59 
60 #if HF_LOG_LEVEL >= HF_LOG_LEVEL_INFO
61  #define INFO std::cout.clear();std::cout << "[INFO ] "
62 #else
63  #define INFO std::cout.setstate(std::ios_base::badbit);std::cout
64 #endif
65 
66 #if HF_LOG_LEVEL >= HF_LOG_LEVEL_DEBUG
67  #define DEBUG std::cout.clear();std::cout << "[DEBUG] "
68 #else
69  #define DEBUG std::cout.setstate(std::ios_base::badbit);std::cout
70 #endif
71 
72 #if HF_LOG_LEVEL >= HF_LOG_LEVEL_TRACE
73  #define TRACE std::cout.clear();std::cout << "[TRACE] "
74 #else
75  #define TRACE std::cout.setstate(std::ios_base::badbit);std::cout
76 #endif
77 
78 #define APP std::cout.clear();std::cout
79 
81 #define LOG(X) X
82 
83 namespace HF
84 {
88  namespace Debug
89  {
90  template<typename T>
91  struct Hex
92  {
93  static_assert(std::is_unsigned<T>::value, "Type MUST be an unsigned integer");
94 
95  static constexpr size_t size = 2 * sizeof(T);
96 
97  T value;
98 
99  Hex(T _value): value(_value)
100  {}
101  };
102 
103  template<typename T>
104  inline std::ostream &operator<<(std::ostream &stream, Hex<T> hex)
105  {
106  std::ios_base::fmtflags ff = stream.flags();
107  char f = stream.fill(' ');
108 
109  stream << std::uppercase << std::right << std::hex << std::setfill('0')
110  << std::setw(hex.size) << (int) hex.value;
111 
112  stream << std::setfill(f) << std::setiosflags(ff);
113  return stream;
114  }
115 
116  } // namespace Debug
117 
118 } // namespace HF
119 
122 #endif /* HF_DEBUG_H */
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22