qxLib
cout_logger_stream.inl
Go to the documentation of this file.
1 /**
2 
3  @file cout_logger_stream.inl
4  @author Khrapov
5  @date 30.07.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 
10 namespace qx
11 {
12 
13 inline cout_logger_stream::cout_logger_stream(std::optional<config> optStreamConfig) noexcept
14  : base_standard_streams_stream(optStreamConfig ? *optStreamConfig : config())
15 {
16  const config streamConfig = optStreamConfig ? *optStreamConfig : config();
17 
18  if (streamConfig.bDisableStdioSync)
19  {
20  std::ios_base::sync_with_stdio(false);
21  }
22 
23  if (streamConfig.bUntieCin)
24  {
25  std::wcin.tie(nullptr);
26  std::wcout.tie(nullptr);
27  }
28 }
29 
31 {
32  details::get_cout<char_type>::get() << std::flush;
33  details::get_cerr<char_type>::get() << std::flush;
34 }
35 
36 inline void cout_logger_stream::cout_colorized(verbosity eVerbosity, string_view svMessage, const color& rangeColor)
37 {
38  check_previous_message(eVerbosity);
39 
40  auto& outputStream =
41  !is_error(eVerbosity) ? details::get_cout<char_type>::get() : details::get_cerr<char_type>::get();
42  outputStream << terminal_color::font(rangeColor) << svMessage << terminal_color::reset();
43 }
44 
45 inline void cout_logger_stream::cout_common(verbosity eVerbosity, string_view svMessage)
46 {
47  check_previous_message(eVerbosity);
48 
49  auto& outputStream =
50  !is_error(eVerbosity) ? details::get_cout<char_type>::get() : details::get_cerr<char_type>::get();
51  outputStream << svMessage;
52 }
53 
54 } // namespace qx
A base class for logger streams based on standard streams.
void check_previous_message(verbosity eCurrentMessageVerbosity)
Check the previous message type and flush if needed.
RGBA color.
Definition: color.h:193
cout_logger_stream(std::optional< config > optStreamConfig={}) noexcept
cout_logger_stream object constructor
virtual void do_flush() override
Flush the stream.
static constexpr terminal_color reset() noexcept
Reset all colors.
static constexpr terminal_color font(const color &fontColor) noexcept
Set font color.
bool is_error(verbosity eVerbosity) noexcept
Check if the verbosity level is an error.
Definition: verbosity.h:35