ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
log4cplus.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_libdaq
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief Declaration of log4cplus helpers
9  */
10 #ifndef DAQ_LOG4CPLUS_HPP
11 #define DAQ_LOG4CPLUS_HPP
12 
13 #include <iosfwd>
14 
15 #include <log4cplus/loglevel.h>
16 
17 namespace daq {
18 
19 /**
20  * ly typed log4cplus::LogLevel (which is an alias to int)
21  */
22 struct LogLevel {
23  log4cplus::LogLevel value;
24 };
25 
26 /**
27  * Parse log level from string.
28  */
29 std::istream& operator>>(std::istream& is, LogLevel& level);
30 
31 /**
32  * Format log level to stream.
33  */
34 std::ostream& operator<<(std::ostream& os, LogLevel level);
35 
36 /**
37  * Trim string from whitespace (' ', '\n')
38  */
39 class Trim {
40 public:
41  static constexpr std::string_view WHITESPACE = " \n\t";
42  enum : uint8_t {
43  Right = 1 << 2,
44  };
45  /**
46  * Construct from exception derived from std::exception.
47  */
48  explicit Trim(std::string_view str, uint8_t spec = Right) noexcept : m_str(str), m_spec(spec){};
49 
50  /**
51  * Formats string by trimming as
52  *
53  * @param os output stream to output to.
54  * @param reporter Reporter adapter to format.
55  * @returns os
56  */
57  friend std::ostream& operator<<(std::ostream& os, Trim const& trim);
58 
59 private:
60  std::string_view m_str;
61  uint8_t m_spec;
62 };
63 } // namespace daq
64 
65 #endif // #ifndef DAQ_LOG4CPLUS_HPP
daq::Trim::Trim
Trim(std::string_view str, uint8_t spec=Right) noexcept
Construct from exception derived from std::exception.
Definition: log4cplus.hpp:48
daq::Trim::operator<<
friend std::ostream & operator<<(std::ostream &os, Trim const &trim)
Formats string by trimming as.
Definition: log4cplus.cpp:36
daq::Trim::WHITESPACE
static constexpr std::string_view WHITESPACE
Definition: log4cplus.hpp:41
daq
Definition: asyncProcess.cpp:15
daq::operator>>
std::istream & operator>>(std::istream &is, LogLevel &level)
Parse log level from string.
Definition: log4cplus.cpp:17
daq::operator<<
daqif::DaqStatus & operator<<(daqif::DaqStatus &status, daq::Status const &rhs)
Convert daq::Status -> daqif::DaqStatus by populating from rhs.
Definition: conversion.cpp:18
daq::Trim::Right
@ Right
Definition: log4cplus.hpp:43
daq::LogLevel::value
log4cplus::LogLevel value
Definition: log4cplus.hpp:23
daq::Trim
Trim string from whitespace (' ', ' ')
Definition: log4cplus.hpp:39
daq::LogLevel
ly typed log4cplus::LogLevel (which is an alias to int)
Definition: log4cplus.hpp:22