LkEngine
0.1.2
Loading...
Searching...
No Matches
LogFormatters.h
Go to the documentation of this file.
1
5
#pragma once
6
7
#include <stdint.h>
8
#include <codecvt>
9
#if defined(LK_PLATFORM_WINDOWS)
10
# include <format>
11
#elif defined(LK_PLATFORM_LINUX)
12
# include <spdlog/fmt/fmt.h>
13
#endif
14
#include <filesystem>
15
#include <locale>
16
#include <string>
17
18
#include <glm/glm.hpp>
19
20
#include "LkEngine/Core/Hash/UUID.h"
21
35
template
<>
36
struct
LK_FMT_LIB::formatter<
std
::wstring>
37
{
38
template
<
typename
ParseContext>
39
constexpr
auto
parse(ParseContext& Context)
40
{
41
return
Context.begin();
42
}
43
44
template
<
typename
FormatContext>
45
auto
format(
const
std::wstring& WideString, FormatContext& Context)
const
46
{
47
const
std::string NarrowString = std::wstring_convert<std::codecvt_utf8<wchar_t>>{}.to_bytes(WideString);
48
return
LK_FMT_LIB::format_to(Context.out(),
"{}"
, NarrowString);
49
}
50
};
51
55
template
<>
56
struct
LK_FMT_LIB::formatter<const wchar_t*>
57
{
58
template
<
typename
ParseContext>
59
constexpr
auto
parse(ParseContext& Context)
60
{
61
return
Context.begin();
62
}
63
64
template
<
typename
FormatContext>
65
auto
format(
const
wchar_t
* WideString, FormatContext& Context)
const
66
{
67
if
(!WideString)
68
{
69
return
LK_FMT_LIB::format_to(Context.out(),
"(NULL)"
);
70
}
71
72
const
std::string NarrowString = std::wstring_convert<std::codecvt_utf8<wchar_t>>{}.to_bytes(WideString);
73
return
LK_FMT_LIB::format_to(Context.out(),
"{}"
, NarrowString);
74
}
75
};
76
80
template
<>
81
struct
LK_FMT_LIB::formatter<
std
::filesystem::path>
82
{
83
template
<
typename
ParseContext>
84
constexpr
auto
parse(ParseContext& Context)
85
{
86
return
Context.begin();
87
}
88
89
template
<
typename
FormatContext>
90
auto
format(
const
std::filesystem::path& Input, FormatContext& Context)
const
91
{
92
return
LK_FMT_LIB::format_to(Context.out(),
"{}"
, Input.generic_string());
93
}
94
};
95
99
template
<std::
size_t
N>
100
struct
LK_FMT_LIB::formatter<
std
::array<char, N>>
101
{
102
template
<
typename
ParseContext>
103
constexpr
auto
parse(ParseContext& Context)
104
{
105
return
Context.begin();
106
}
107
108
template
<
typename
FormatContext>
109
auto
format(
const
std::array<char, N>& Input, FormatContext& Context)
const
110
{
111
return
LK_FMT_LIB::format_to(Context.out(),
"{}"
, Input.data());
112
}
113
};
114
118
template
<>
119
struct
LK_FMT_LIB::formatter<glm::vec2>
120
{
121
template
<
typename
ParseContext>
122
constexpr
auto
parse(ParseContext& Context)
123
{
124
return
Context.begin();
125
}
126
127
template
<
typename
FormatContext>
128
auto
format(
const
glm::vec2& Input, FormatContext& Context)
const
129
{
130
return
LK_FMT_LIB::format_to(Context.out(),
"({:.2f}, {:.2f})"
, Input.x, Input.y);
131
}
132
};
133
137
template
<>
138
struct
LK_FMT_LIB::formatter<glm::vec3>
139
{
140
template
<
typename
ParseContext>
141
constexpr
auto
parse(ParseContext& Context)
142
{
143
return
Context.begin();
144
}
145
146
template
<
typename
FormatContext>
147
auto
format(
const
glm::vec3& Input, FormatContext& Context)
const
148
{
149
return
LK_FMT_LIB::format_to(Context.out(),
"({:.2f}, {:.2f}, {:.2f})"
, Input.x, Input.y, Input.z);
150
}
151
};
152
156
template
<>
157
struct
LK_FMT_LIB::formatter<glm::vec4>
158
{
159
template
<
typename
ParseContext>
160
constexpr
auto
parse(ParseContext& Context)
161
{
162
return
Context.begin();
163
}
164
165
template
<
typename
FormatContext>
166
auto
format(
const
glm::vec4& Input, FormatContext& Context)
const
167
{
168
return
LK_FMT_LIB::format_to(Context.out(),
"({:.2f}, {:.2f}, {:.2f}, {:.2f})"
, Input.x, Input.y, Input.z, Input.z);
169
}
170
};
171
175
template
<>
176
struct
LK_FMT_LIB::formatter<
LkEngine
::LUUID> : LK_FMT_LIB::formatter<std::string>
177
{
178
template
<
typename
ParseContext>
179
constexpr
auto
parse(ParseContext& Context)
180
{
181
return
Context.begin();
182
}
183
184
template
<
typename
FormatContext>
185
auto
format(
const
LkEngine::LUUID
& Uuid, FormatContext& Context)
const
186
{
187
return
LK_FMT_LIB::format_to(Context.out(),
"{}"
,
static_cast<
::LkEngine::LUUID::SizeType
>
(Uuid));
188
}
189
};
LkEngine
Definition
Asset.h:11
std
Definition
UUID.h:33
LkEngine::LUUID
Definition
UUID.h:13
LkEngine
Source
LkEngine
Core
Log
LogFormatters.h
Generated by
1.12.0