1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#pragma once
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/Move.h>
#include <Corrade/Containers/StringView.h>
#include <concepts>
namespace floormat {
template<typename T>
concept DebugPrintable = requires(Debug& dbg, const T& value) {
{ dbg << value } -> std::convertible_to<Debug&>;
};
} // namespace floormat
namespace floormat::detail::corrade_debug {
// ***** colon *****
struct Colon { char c; };
Debug& operator<<(Debug& dbg, Colon box);
// ***** error string *****
struct ErrorString { int value; };
Debug& operator<<(Debug& dbg, ErrorString box);
// ***** quoted *****
template<typename T> struct Quoted
{
using type = T;
T value; char c;
};
Debug::Flags quoted_begin(Debug& dbg, char c);
Debug& quoted_end(Debug& dbg, Debug::Flags flags, char c);
template<typename T> Debug& operator<<(Debug& dbg, Quoted<T> box)
{
Debug::Flags flags = quoted_begin(dbg, box.c);
dbg << box.value;
return quoted_end(dbg, flags, box.c);
}
} // namespace floormat::detail::corrade_debug
// ***** api *****
// ***** functions *****
namespace floormat {
floormat::detail::corrade_debug::Colon colon(char c = ':');
floormat::detail::corrade_debug::ErrorString error_string(int error);
floormat::detail::corrade_debug::ErrorString error_string();
template<DebugPrintable T>
auto quoted(T&& value, char c = '\'')
{
using U = std::remove_cvref_t<T>;
using floormat::detail::corrade_debug::Quoted;
if constexpr(std::is_rvalue_reference_v<decltype(value)>)
return Quoted<U>{ .value = Utility::move(value), .c = c };
else
return Quoted<const U&>{ .value = value, .c = c };
}
template<DebugPrintable T> auto quoted2(T&& value) { return quoted(Utility::forward<T>(value), '"'); }
} // namespace floormat
|