dl
dl
io
dl_json.h
浏览该文件的文档.
1
12
#pragma once
13
14
#include <json.hpp>
15
16
#include "
io/dl_log.h
"
17
#include "
memory/dl_buffer.h
"
18
19
using
json
= nlohmann::json;
20
21
namespace
dl::Json
22
{
23
24
extern
bool
g_bJsonLog
;
25
26
30
void
SetLog
(
bool
open);
31
32
struct
DisableLog
33
{
34
DisableLog
() {
SetLog
(
false
); }
35
~DisableLog
() {
SetLog
(
true
); }
36
};
37
42
json
Parse
(std::string_view path_name);
43
48
json
Parse
(
BufferView
buf);
49
53
template
<
typename
T>
54
bool
Get
(
const
json
& j,
const
std::string& name,
T
& t)
55
{
56
auto
iter = j.find(name);
57
if
(iter == j.end())
58
{
59
if
(
g_bJsonLog
)
60
log_err
(
"json取值失败:{}"
, name);
61
return
false
;
62
}
63
try
64
{
65
t = *iter;
66
return
true
;
67
}
68
catch
(nlohmann::detail::exception& e)
69
{
70
if
(
g_bJsonLog
)
71
log_err
(
"json取值失败({}): {}"
, name, e.what());
72
}
73
return
false
;
74
}
75
78
inline
std::string
Dump
(
json
& j)
79
{
80
return
j.dump(4);
81
}
82
85
inline
std::string
Dump
(
BufferView
buf)
86
{
87
json
j =
Parse
(buf);
88
if
(j.is_null())
89
return
{};
90
return
Dump
(j);
91
}
92
93
}
94
dl_buffer.h
表示一段内存
json
nlohmann::json json
定义
dl_json.h:19
dl_log.h
日志系统
log_err
#define log_err(...)
定义
dl_log.h:215
dl::Json
定义
dl_json.h:22
dl::Json::SetLog
void SetLog(bool open)
设置是否提示输出日志(请直接使用DisableLog来关闭后,自动恢复)
dl::Json::Parse
json Parse(std::string_view path_name)
从 文件 构建json对象
dl::Json::g_bJsonLog
bool g_bJsonLog
dl::Json::Get
bool Get(const json &j, const std::string &name, T &t)
从json返回值,不存在则返回false,打印日志
定义
dl_json.h:54
dl::Json::Dump
std::string Dump(json &j)
dump
定义
dl_json.h:78
dl::BufferView
std::span< std::byte > BufferView
定义
dl_buffer.h:22
dl::KeyCode::T
@ T
定义
dl_input.h:120
dl::Json::DisableLog::DisableLog
DisableLog()
定义
dl_json.h:34
dl::Json::DisableLog::~DisableLog
~DisableLog()
定义
dl_json.h:35
制作者
1.13.1