knowL: Knowledge Libraries
Loading...
Searching...
No Matches
Formatter.h
1#pragma once
2
3#include <clog_qt>
4
5#include "Global.h"
6
7#define KNOWCORE_CORE_DECLARE_FORMATTER(_TYPE_) \
8 clog_fmt_declare_formatter(_TYPE_)
9
10#define KNOWCORE_CORE_DECLARE_FORMATTER_INHERIT(_TYPE_, _OTHER_T_) \
11 clog_fmt_declare_formatter_inherit(_TYPE_, _OTHER_T_)
12
13#define KNOWCORE_CORE_DECLARE_CAST_FORMATTER(_TYPE_, _TO_TYPE_) \
14template<> \
15struct fmt::formatter<_TYPE_> : public clog_fmt::cast_formatter<_TYPE_, _TO_TYPE_> {};
16
17namespace knowCore
18{
19 template<typename _TYPE_>
20 struct printable_formatter : public fmt::formatter<QString> {
21 template <typename FormatContext>
22 auto format(_TYPE_ const& p, FormatContext& ctx)
23 {
24 auto const [success, value, message] = p.printable();
25 if(success)
26 {
27 return fmt::formatter<QString>::format(value, ctx);
28 } else {
29 return fmt::format_to(ctx.out(), "error: '{}'", message);
30 }
31 }
32 };
33}
34
35#define KNOWCORE_CORE_DECLARE_FORMATTER_PRINTABLE(_TYPE_) \
36template<> \
37struct fmt::formatter<_TYPE_> : public knowCore::printable_formatter<_TYPE_> {};
38
39#define KNOWCORE_CORE_DECLARE_FORMATTER_ENUM(_TYPE_, ...) \
40 clog_fmt_declare_formatter_enum(_TYPE_, __VA_ARGS__)
Definition Formatter.h:20