OGLplus  (0.59.0) a C++ wrapper for rendering APIs

backend.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_LOGGING_BACKEND_HPP
10 #define EAGINE_LOGGING_BACKEND_HPP
11 
12 #include "../interface.hpp"
13 #include "../memory/block.hpp"
14 #include "../memory/shared_alloc.hpp"
15 #include "../message_id.hpp"
16 #include "../string_span.hpp"
17 #include "severity.hpp"
18 #include <chrono>
19 #include <cstdint>
20 
21 namespace eagine {
22 class application_config;
23 //------------------------------------------------------------------------------
26 template <typename T>
28 private:
29  template <
30  typename X,
31  typename = decltype(
32  adapt_log_entry_arg(std::declval<identifier>(), std::declval<X>()))>
33  static auto _test(X*) -> std::true_type;
34  static auto _test(...) -> std::false_type;
35 
36 public:
37  // NOLINTNEXTLINE(hicpp-vararg)
38  using type = decltype(_test(static_cast<T*>(nullptr)));
39 };
40 
44 template <typename T>
45 using has_log_entry_adapter_t = typename does_have_log_entry_adapter<T>::type;
46 
50 template <typename T>
51 constexpr const bool has_log_entry_adapter_v =
53 //------------------------------------------------------------------------------
56 using logger_instance_id = std::uintptr_t;
57 
60 struct logger_backend : interface<logger_backend> {
61  virtual auto configure(application_config&) -> bool {
62  return false;
63  }
64 
66  virtual auto allocator() noexcept -> memory::shared_byte_allocator = 0;
67 
69  virtual auto type_id() noexcept -> identifier = 0;
70 
74  virtual auto
75  entry_backend(identifier source, log_event_severity severity) noexcept
76  -> logger_backend* = 0;
77 
79  virtual void enter_scope(identifier scope) noexcept = 0;
80 
82  virtual void leave_scope(identifier scope) noexcept = 0;
83 
85  virtual void set_description(
86  identifier source,
87  logger_instance_id instance,
88  string_view display_name,
89  string_view description) noexcept = 0;
90 
97  virtual auto begin_message(
98  identifier source,
99  identifier tag,
100  logger_instance_id instance,
101  log_event_severity severity,
102  string_view format) noexcept -> bool = 0;
103 
108  virtual void add_nothing(identifier arg, identifier tag) noexcept = 0;
109 
114  virtual void add_identifier(
115  identifier arg,
116  identifier tag,
117  identifier value) noexcept = 0;
118 
119  virtual void
120  add_message_id(identifier arg, identifier tag, message_id) noexcept = 0;
121 
126  virtual void
127  add_bool(identifier arg, identifier tag, bool value) noexcept = 0;
128 
133  virtual void add_integer(
134  identifier arg,
135  identifier tag,
136  std::intmax_t value) noexcept = 0;
137 
142  virtual void add_unsigned(
143  identifier arg,
144  identifier tag,
145  std::uintmax_t value) noexcept = 0;
146 
151  virtual void
152  add_float(identifier arg, identifier tag, float value) noexcept = 0;
153 
160  virtual void add_float(
161  identifier arg,
162  identifier tag,
163  float min,
164  float value,
165  float max) noexcept = 0;
166 
171  virtual void add_duration(
172  identifier arg,
173  identifier tag,
174  std::chrono::duration<float> value) noexcept = 0;
175 
180  virtual void
181  add_string(identifier arg, identifier tag, string_view value) noexcept = 0;
182 
187  virtual void add_blob(
188  identifier arg,
189  identifier tag,
190  memory::const_block value) noexcept = 0;
191 
197  template <typename T>
198  auto add_adapted(identifier arg, const T& value)
199  -> std::enable_if_t<has_log_entry_adapter_v<T>> {
200  adapt_log_entry_arg(arg, value)(*this);
201  }
202 
204  virtual void finish_message() noexcept = 0;
205 
207  virtual void finish_log() noexcept = 0;
208 
214  virtual void log_chart_sample(
215  identifier source,
216  logger_instance_id instance,
217  identifier series,
218  float value) noexcept = 0;
219 };
220 //------------------------------------------------------------------------------
221 } // namespace eagine
222 
223 #endif // EAGINE_LOGGING_BACKEND_HPP
auto add_adapted(identifier arg, const T &value) -> std::enable_if_t< has_log_entry_adapter_v< T >>
Add argument with value having type adaptable to log entry.
Definition: backend.hpp:198
virtual void add_string(identifier arg, identifier tag, string_view value) noexcept=0
Add argument with string value.
Helper class used in implementation of has_log_entry_adapter_t.
Definition: backend.hpp:27
Common code is placed in this namespace.
Definition: eagine.hpp:21
virtual void finish_message() noexcept=0
Finishes the current logging message.
std::uintptr_t logger_instance_id
Logger object instance id type.
Definition: backend.hpp:56
Class for reading application configuration.
Definition: application_config.hpp:29
typename does_have_log_entry_adapter< T >::type has_log_entry_adapter_t
Trait indicating if there is a log entry adapter for type T.
Definition: backend.hpp:45
virtual void add_bool(identifier arg, identifier tag, bool value) noexcept=0
Add argument with boolean value.
virtual void leave_scope(identifier scope) noexcept=0
Leaves logging scope.
virtual void add_duration(identifier arg, identifier tag, std::chrono::duration< float > value) noexcept=0
Add argument with time duration value.
virtual void set_description(identifier source, logger_instance_id instance, string_view display_name, string_view description) noexcept=0
Sets the user-readable description for the logger object.
Base template for abstract interfaces, implements common functionality.
Definition: interface.hpp:18
virtual void finish_log() noexcept=0
Finishes the current log.
static auto format(std::string &&fmt_str) noexcept -> format_string_and_list< 0 >
Function taking a format string, returning an object for variable specification.
Definition: str_format.hpp:118
virtual auto allocator() noexcept -> memory::shared_byte_allocator=0
The memory allocator used by the logger backend.
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
virtual void add_identifier(identifier arg, identifier tag, identifier value) noexcept=0
Add argument with identifier value.
log_event_severity
Log event severity enumeration.
Definition: severity.hpp:18
virtual void add_blob(identifier arg, identifier tag, memory::const_block value) noexcept=0
Add argument with BLOB value.
Interface for logging backend implementations.
Definition: backend.hpp:60
virtual void add_unsigned(identifier arg, identifier tag, std::uintmax_t value) noexcept=0
Add argument with unsigned integer value.
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
virtual void log_chart_sample(identifier source, logger_instance_id instance, identifier series, float value) noexcept=0
Adds a chart/graph sample to the log.
virtual void add_float(identifier arg, identifier tag, float value) noexcept=0
Add argument with floating-point value.
virtual void enter_scope(identifier scope) noexcept=0
Enters logging scope.
virtual void add_integer(identifier arg, identifier tag, std::intmax_t value) noexcept=0
Add argument with signed integer value.
virtual auto begin_message(identifier source, identifier tag, logger_instance_id instance, log_event_severity severity, string_view format) noexcept -> bool=0
Begins a new logging message.
virtual void add_nothing(identifier arg, identifier tag) noexcept=0
Add valueless (name-only) argument.
constexpr const bool has_log_entry_adapter_v
Trait indicating if there is a log entry adapter for type T.
Definition: backend.hpp:51
virtual auto entry_backend(identifier source, log_event_severity severity) noexcept -> logger_backend *=0
Returns a pointer to the actual backend to be used by an log_entry.
virtual auto type_id() noexcept -> identifier=0
The backend type identifier.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).