HTGS  v2.0
The Hybrid Task Graph Scheduler
debug_message.hpp
Go to the documentation of this file.
1 
2 // NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the software in any medium, provided that you keep intact this entire notice. You may improve, modify and create derivative works of the software or any portion of the software, and you may copy and distribute such modifications or works. Modified works should carry a notice stating that you changed the software and should note the date and nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the source of the software.
3 // NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE.
4 // You are solely responsible for determining the appropriateness of using and distributing the software and you assume all risks associated with its use, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of operation. This software is not intended to be used in any situation where a failure could cause risk of injury or damage to property. The software developed by NIST employees is not subject to copyright protection within the United States.
5 
13 #ifndef HTGS_DEBUG_MESSAGE_HPP
14 #define HTGS_DEBUG_MESSAGE_HPP
15 
16 #include <iosfwd>
17 #include <iostream>
18 
19 #ifndef NDEBUG
20 
25 #define HTGS_ASSERT(condition, message) \
26  do { \
27  if (! (condition)) { \
28  std::cerr << message << ": Assertion `" #condition "` failed in " << __FILE__ \
29  << ":" << __LINE__ << ": " << std::endl; \
30  std::terminate(); \
31  } \
32  } while (false)
33 #else
34 #define HTGS_ASSERT(condition, message) do { } while (false)
35 #endif
36 
41 #define HTGS_VERBOSE 1
42 
43 
54 #define HTGS_DEBUG_MSG_LEVEL(msg, level) if (!HTGS_DEBUG_ENABLED || HTGS_DEBUG_LEVEL < level) {} \
55  else htgs_dbglog() << __FILE__ << ":" << __LINE__ << " " << msg
56 
65 #define HTGS_DEBUG(msg) HTGS_DEBUG_MSG_LEVEL(msg, 0)
66 
75 #define HTGS_DEBUG_VERBOSE(msg) HTGS_DEBUG_MSG_LEVEL(msg, HTGS_VERBOSE)
76 
81 #ifdef HTGS_DEBUG_LEVEL_VERBOSE
82 #define HTGS_DEBUG_LEVEL HTGS_VERBOSE
83 #else
84 #define HTGS_DEBUG_LEVEL 0
85 #endif
86 
91 #ifdef HTGS_DEBUG_FLAG
92 #define HTGS_DEBUG_ENABLED 1
93 #else
94 #define HTGS_DEBUG_ENABLED 0
95 #endif
96 
100 struct htgs_dbglog {
102  std::ostream &os_;
103  mutable bool has_endl_;
104  htgs_dbglog(std::ostream &os = std::cerr) : os_(os), has_endl_(false) {}
105  ~htgs_dbglog() { if (!has_endl_) os_ << std::endl; }
106  template<typename T>
107  static bool has_endl(const T &) { return false; }
108  static bool has_endl(char c) { return (c == '\n'); }
109  static bool has_endl(std::string s) { return has_endl(*s.rbegin()); }
110  static bool has_endl(const char *s) { return has_endl(std::string(s)); }
111  template<typename T>
112  static bool same_manip(T &(*m)(T &), T &(*e)(T &)) { return (m == e); }
113  const htgs_dbglog &operator<<(std::ostream &(*m)(std::ostream &)) const {
114  has_endl_ = same_manip(m, std::endl);
115  os_ << m;
116  return *this;
117  }
118  template<typename T>
119  const htgs_dbglog &operator<<(const T &v) const {
120  has_endl_ = has_endl(v);
121  os_ << v;
122  return *this;
123  }
125 };
126 
127 #endif //HTGS_DEBUG_MESSAGE_HPP
Debug logging structure for processing various types of arguments for std::cerr.
Definition: debug_message.hpp:100