HTGS  v2.0
The Hybrid Task Graph Scheduler
log_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_LOG_MESSAGE_HPP
14 #define HTGS_LOG_MESSAGE_HPP
15 
16 #include <iosfwd>
17 #include <iostream>
18 
23 #define HTGS_VERBOSE 1
24 
34 #define HTGS_LG_MSG_LEVEL(msg, level) if (!HTGS_LOG_ENABLED || HTGS_LOG_LEVEL < level) {} \
35  else htgs_lglog() << " " << msg
36 
44 #define HTGS_LG(msg) HTGS_LG_MSG_LEVEL(msg, 0)
45 
53 #define HTGS_LG_VERBOSE(msg) HTGS_LG_MSG_LEVEL(msg, HTGS_VERBOSE)
54 
59 #ifdef HTGS_LOG_LEVEL_VERBOSE
60 #define HTGS_LOG_LEVEL HTGS_VERBOSE
61 #else
62 #define HTGS_LOG_LEVEL 0
63 #endif
64 
69 #ifdef HTGS_LOG_FLAG
70 #define HTGS_LOG_ENABLED 1
71 #else
72 #define HTGS_LOG_ENABLED 0
73 #endif
74 
78 struct htgs_lglog {
80  std::ostream &os_;
81  mutable bool has_endl_;
82  htgs_lglog(std::ostream &os = std::cout) : os_(os), has_endl_(false) {}
83  ~htgs_lglog() { if (!has_endl_) os_ << std::endl; }
84  template<typename T>
85  static bool has_endl(const T &) { return false; }
86  static bool has_endl(char c) { return (c == '\n'); }
87  static bool has_endl(std::string s) { return has_endl(*s.rbegin()); }
88  static bool has_endl(const char *s) { return has_endl(std::string(s)); }
89  template<typename T>
90  static bool same_manip(T &(*m)(T &), T &(*e)(T &)) { return (m == e); }
91  const htgs_lglog &operator<<(std::ostream &(*m)(std::ostream &)) const {
92  has_endl_ = same_manip(m, std::endl);
93  os_ << m;
94  return *this;
95  }
96  template<typename T>
97  const htgs_lglog &operator<<(const T &v) const {
98  has_endl_ = has_endl(v);
99  os_ << v;
100  return *this;
101  }
103 };
104 
105 #endif //HTGS_LOG_MESSAGE_HPP
Log structure for processing various types of arguments for std::cout.
Definition: log_message.hpp:78