Taskolib  1.3.3
format.h
Go to the documentation of this file.
1 
23 // SPDX-License-Identifier: LGPL-2.1-or-later
24 
25 #ifndef TASKOLIB_FORMAT_H_
26 #define TASKOLIB_FORMAT_H_
27 
28 #include <fmt/format.h>
29 #include <sstream>
30 
31 #include "taskolib/Message.h"
32 #include "taskolib/time_types.h"
33 #include "taskolib/Timeout.h"
34 
35 using namespace std::literals;
36 
37 template<> struct fmt::formatter<task::Message> {
38  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
39  return ctx.begin();
40  }
41  template <typename FormatContext>
42  auto format(task::Message const& val, FormatContext& ctx) -> decltype(ctx.out()) {
43  std::stringstream ss{ };
44  ss << val;
45  return format_to(ctx.out(), "{}", ss.str());
46  }
47 };
48 
49 template<> struct fmt::formatter<task::Timeout> {
50  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
51  return ctx.begin();
52  }
53  template <typename FormatContext>
54  auto format(task::Timeout const& val, FormatContext& ctx) -> decltype(ctx.out()) {
55  std::stringstream ss{ };
56  ss << val;
57  return format_to(ctx.out(), "{}", ss.str());
58  }
59 };
60 
61 template<> struct fmt::formatter<task::TimePoint> {
62  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
63  return ctx.begin();
64  }
65  template <typename FormatContext>
66  auto format(task::TimePoint const& val, FormatContext& ctx) -> decltype(ctx.out()) {
67  return format_to(ctx.out(), "{}", task::to_string(val));
68  }
69 };
70 
71 #endif
Declaration of the Message class.
Declaration of the Timeout class.
A message carrying some text, a timestamp, and a type, to be transported with a message queue between...
Definition: Message.h:45
A type for storing a timeout duration.
Definition: Timeout.h:72
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33
std::string to_string(Step::Type type)
Return a lower-case name for a step type ("action", "if", "end").
Definition: Step.cc:287
std::chrono::time_point< Clock > TimePoint
Definition: time_types.h:34
auto format(task::Message const &val, FormatContext &ctx) -> decltype(ctx.out())
Definition: format.h:42
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin())
Definition: format.h:38
auto format(task::TimePoint const &val, FormatContext &ctx) -> decltype(ctx.out())
Definition: format.h:66
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin())
Definition: format.h:62
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin())
Definition: format.h:50
auto format(task::Timeout const &val, FormatContext &ctx) -> decltype(ctx.out())
Definition: format.h:54
Declaration of time-related types.