Boost.UI
User Interface Boost library
log.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Kolya Kosenko
2 
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5 
7 
8 #ifndef BOOST_UI_LOG_HPP
9 #define BOOST_UI_LOG_HPP
10 
11 #include <boost/ui/config.hpp>
12 
13 #ifdef BOOST_HAS_PRAGMA_ONCE
14 #pragma once
15 #endif
16 
17 #include <boost/ui/string.hpp>
18 
19 #include <sstream> // for std::ostringstream
20 
21 namespace boost {
22 namespace ui {
23 
26 
27 class BOOST_UI_DECL log_string
28 {
29 public:
31  log_string(uistring& str);
32 
34  log_string& spaces(bool show = true) { m_spaces = show; return *this; }
35  log_string& nospaces() { return spaces(false); }
37 
39  log_string& quotes(bool show = true) { m_quotes = show; return *this; }
40  log_string& noquotes() { return quotes(false); }
42 
44  log_string& location(const char* file, int line = -1, const char* fn = NULL);
45 
47 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
48  log_string& operator<<(char value);
49  log_string& operator<<(const char* value)
50  { return operator<<(std::string(value)); }
51  log_string& operator<<(const std::string& value);
52 #endif
53  log_string& operator<<(wchar_t value);
54  log_string& operator<<(const wchar_t* value)
55  { return operator<<(std::wstring(value)); }
56  log_string& operator<<(const std::wstring& value);
57  log_string& operator<<(const uistring& value);
58 
59 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
60  template <class T>
61  log_string& operator<<(const T& value)
62  {
63  std::ostringstream ss;
64  ss << std::boolalpha << value;
65  raw(ss.str());
66  return *this;
67  }
68 #endif
69 
72  log_string& raw(const uistring& value);
73 
74 private:
75  void append_space();
76 
77  uistring& m_string;
78  bool m_spaces;
79  bool m_quotes;
80 };
81 
84 
85 class BOOST_UI_DECL log : public log_string
86 {
87 public:
88  log() : log_string(m_string), m_level(debug_level) {}
89  ~log();
90 
91  class fatal;
92  class error;
93  class warning;
94  class info;
95  class verbose;
96  class debug;
97  class trace;
98 
99 protected:
100 #ifndef DOXYGEN
101  enum level_values
102  {
103  fatal_level, error_level, warning_level, info_level,
104  verbose_level, debug_level, trace_level
105  };
106 
107  log(level_values level) : log_string(m_string), m_level(level) {}
108 #endif
109 
110 private:
111  void flush();
112 
113  uistring m_string;
114  level_values m_level;
115 };
116 
120 #define BOOST_UI_LOG ::boost::ui::log().location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
121 
124 class log::fatal : public log
125 {
126 public:
127  fatal() : log(fatal_level) {}
128 };
129 
132 class log::error : public log
133 {
134 public:
135  error() : log(error_level) {}
136 };
137 
140 class log::warning : public log
141 {
142 public:
143  warning() : log(warning_level) {}
144 };
145 
148 class log::info : public log
149 {
150 public:
151  info() : log(info_level) {}
152 };
153 
156 class log::verbose : public log
157 {
158 public:
159  verbose() : log(verbose_level) {}
160 };
161 
164 class log::debug : public log
165 {
166 public:
167  debug() : log(debug_level) {}
168 };
169 
172 class log::trace : public log
173 {
174 public:
175  trace() : log(trace_level) {}
176 };
177 
178 } // namespace ui
179 } // namespace boost
180 
181 #endif // BOOST_UI_LOG_HPP
boost::ui::uistring
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
boost::ui::log
Logging stream class.
Definition: log.hpp:85
config.hpp
Configuration options.
boost::ui::log_string
Logging stream class with output into provided uistring.
Definition: log.hpp:27
boost
Boost C++ libraries namespace.
Definition: window.hpp:19
boost::ui::log_string::noquotes
log_string & noquotes()
Adds quotes near string and character output values.
Definition: log.hpp:40
boost::ui::log::verbose
Shows verbose information if application was started with –verbose option.
Definition: log.hpp:156
boost::ui::operator<<
std::basic_ostream< char, Traits > & operator<<(std::basic_ostream< char, Traits > &os, const uistring &str)
Writes string into the stream.
Definition: string_io.hpp:31
boost::ui::log::info
Shows information dialog in idle time.
Definition: log.hpp:148
string.hpp
String class and operations.
boost::ui::log::fatal
Shows error and abort immediately.
Definition: log.hpp:124
boost::ui::log_string::operator<<
log_string & operator<<(const T &value)
Logs value.
Definition: log.hpp:61
boost::ui::log_string::nospaces
log_string & nospaces()
Inserts white space delitimers between output values.
Definition: log.hpp:35
boost::ui::log::warning
Shows warning dialog in idle time.
Definition: log.hpp:140
boost::ui::log_string::spaces
log_string & spaces(bool show=true)
Inserts white space delitimers between output values.
Definition: log.hpp:34
boost::ui::log::debug
Shows information in debug log.
Definition: log.hpp:164
boost::ui::log::trace
Shows information in debug log.
Definition: log.hpp:172
boost::ui::log::error
Shows error dialog in idle time.
Definition: log.hpp:132
boost::ui::log_string::operator<<
log_string & operator<<(const wchar_t *value)
Logs value.
Definition: log.hpp:54
boost::ui::log_string::quotes
log_string & quotes(bool show=true)
Adds quotes near string and character output values.
Definition: log.hpp:39
boost::ui::log_string::operator<<
log_string & operator<<(const char *value)
Logs value.
Definition: log.hpp:49