Telkin
Loading...
Searching...
No Matches
Print.h
Go to the documentation of this file.
1
#
pragma
once
2
3
#
include
<
cafe
.
h
>
4
5
#
include
<
source_location
>
6
#
include
<
utility
>
7
8
namespace
tk
{
9
10
namespace
internal
{
11
constexpr
const
char
*
basename
(
const
char
* path) {
12
const
char
* last = path;
13
14
for
(
const
char
* p = path; *p; ++p) {
15
if
(*p ==
'/'
|| *p ==
'\\'
) {
16
last = p + 1;
17
}
18
}
19
20
return
last;
21
}
22
23
struct
LogFormat
{
24
const
char
*
fmt
;
25
const
char
*
file
;
26
u32
line
;
27
28
consteval
LogFormat
(
const
char
*
str
,
std
::
source_location
loc
=
std
::
source_location
::
current
())
29
:
fmt
(
str
)
30
,
file
(
basename
(
loc
.
file_name
()))
31
,
line
(
loc
.
line
())
32
{ }
33
};
34
}
35
36
template
<
typename
... Args>
37
void
print
(
internal
::
LogFormat
format, Args&&... args) {
38
const
auto
& fmt = format
.
fmt
;
39
40
OSReport(
"[%s:%d] "
, format
.
file
, format.line);
41
OSReport(fmt, std::forward<Args>(args)...);
42
}
43
44
template
<
typename
... Args>
45
void
println
(
internal
::
LogFormat
format, Args&&... args) {
46
tk
::print(format, std::forward<Args>(args)...);
47
OSReport(
"\n"
);
48
}
49
50
template
<
typename
... Args>
51
void
fatal
(
internal
::
LogFormat
format, Args&&... args) {
52
const
auto
& fmt = format
.
fmt
;
53
54
OSReport(
"[%s:%d] ERROR: "
, format
.
file
, format.line);
55
OSReport(fmt, std::forward<Args>(args)...);
56
OSReport(
"\n"
);
// we don't expect anything else afterwards
57
58
static
char
buf[512];
59
60
__os_snprintf(buf,
sizeof
(buf), fmt, std::forward<Args>(args)...);
61
OSFatal(buf);
62
}
63
}
tk::internal
Definition
Print.h:10
tk::internal::basename
constexpr const char * basename(const char *path)
Definition
Print.h:11
tk::print
void print(internal::LogFormat format, Args &&... args)
Definition
Print.h:37
tk::getTitleID_t
u64(*)() getTitleID_t
Definition
Mod.h:16
tk::fatal
void fatal(internal::LogFormat format, Args &&... args)
Definition
Print.h:51
tk::println
void println(internal::LogFormat format, Args &&... args)
Definition
Print.h:45
tk::internal::LogFormat
Definition
Print.h:23
tk::internal::LogFormat::file
const char * file
Definition
Print.h:25
tk::internal::LogFormat::fmt
const char * fmt
Definition
Print.h:24
tk::internal::LogFormat::line
u32 line
Definition
Print.h:26
core
include
telkin
Print.h
Generated by
1.14.0