Unravel Engine C++ Reference
Loading...
Searching...
No Matches
serialization.cpp
Go to the documentation of this file.
1
#include "
serialization.h
"
2
#include <sstream>
3
4
namespace
serialization
5
{
6
namespace
7
{
8
auto
get_warning_logger() ->
log_callback_t
&
9
{
10
static
log_callback_t
logger;
11
return
logger;
12
}
13
14
// Path tracking implementation
15
thread_local
path_context
* current_path_context =
nullptr
;
16
17
}
// namespace
18
19
void
log_warning
(
const
std::string& log_msg,
const
hpp::source_location& loc)
20
{
21
auto
& logger = get_warning_logger();
22
if
(logger)
23
logger(log_msg, loc);
24
}
25
26
auto
get_path_context
() ->
path_context
*
27
{
28
return
current_path_context;
29
}
30
31
void
set_path_context
(
path_context
* ctx)
32
{
33
current_path_context = ctx;
34
}
35
36
auto
path_context::push_segment
(
const
std::string& segment) ->
bool
37
{
38
39
if
(ignore_next_push)
40
{
41
ignore_next_push =
false
;
42
return
false
;
43
}
44
45
if
(recording_enabled)
46
{
47
path_segments.push_back(segment);
48
return
true
;
49
}
50
return
false
;
51
}
52
53
void
path_context::pop_segment
()
54
{
55
if
(
recording_enabled
&& !
path_segments
.empty())
56
{
57
if
(
path_segments
.back().ends_with(
"]"
))
58
{
59
int
a
= 0;
60
a
++;
61
}
62
path_segments
.pop_back();
63
}
64
}
65
66
auto
path_context::get_current_path
() const ->
std
::
string
67
{
68
if
(
path_segments
.empty())
69
return
""
;
70
71
std::stringstream ss;
72
for
(
size_t
i = 0; i <
path_segments
.size(); ++i)
73
{
74
// For array indices, don't add a separator
75
if
(i > 0 &&
path_segments
[i][0] !=
'['
)
76
ss <<
"/"
;
77
ss <<
path_segments
[i];
78
}
79
return
ss.str();
80
}
81
82
void
path_context::enable_recording
()
83
{
84
recording_enabled
=
true
;
85
}
86
87
void
path_context::disable_recording
()
88
{
89
recording_enabled
=
false
;
90
}
91
92
auto
path_context::is_recording
() const ->
bool
93
{
94
return
recording_enabled
;
95
}
96
97
void
path_context::clear
()
98
{
99
path_segments
.clear();
100
recording_enabled
=
false
;
101
}
102
103
path_segment_guard::path_segment_guard
(
const
std::string& segment)
104
{
105
push_segment
(segment);
106
}
107
108
path_segment_guard::~path_segment_guard
()
109
{
110
pop_segment
();
111
}
112
113
114
void
path_segment_guard::push_segment
(
const
std::string& segment)
115
{
116
auto
* ctx =
get_path_context
();
117
if
(ctx && ctx->is_recording())
118
{
119
was_pushed_ = ctx->push_segment(segment);
120
}
121
}
122
void
path_segment_guard::pop_segment
()
123
{
124
if
(was_pushed_)
125
{
126
auto
* ctx =
get_path_context
();
127
if
(ctx && ctx->is_recording())
128
{
129
ctx->pop_segment();
130
}
131
}
132
was_pushed_ =
false
;
133
}
134
135
136
path_skip_segment_guard::path_skip_segment_guard
(
bool
ignore_next_push)
137
{
138
auto
* ctx =
get_path_context
();
139
if
(ctx && ctx->is_recording())
140
{
141
ctx->ignore_next_push = ignore_next_push;
142
}
143
}
144
145
path_skip_segment_guard::~path_skip_segment_guard
()
146
{
147
148
}
149
auto
get_current_deserialization_path
() -> std::string
150
{
151
auto
* ctx =
get_path_context
();
152
if
(ctx && ctx->is_recording())
153
{
154
return
ctx->get_current_path();
155
}
156
return
""
;
157
}
158
159
160
161
void
init
(
const
init_data
& data)
162
{
163
if
(data.
warning_logger
)
164
{
165
get_warning_logger() = data.
warning_logger
;
166
}
167
168
auto
& context = ser20::get_vector_serialization_context();
169
context.on_element_serialization_begin = [](
size_t
index
)
170
{
171
std::string index_segment =
"["
+ std::to_string(
index
) +
"]"
;
172
// guard->push_segment(index_segment);
173
auto
* ctx =
serialization::get_path_context
();
174
if
(ctx && ctx->is_recording())
175
{
176
ctx->push_segment(index_segment);
177
}
178
};
179
context.on_element_serialization_end = [](
size_t
index
)
180
{
181
auto
* ctx =
serialization::get_path_context
();
182
if
(ctx && ctx->is_recording())
183
{
184
ctx->pop_segment();
185
}
186
};
187
context.should_serialize_element = [](
size_t
index
)
188
{
189
auto
* ctx =
serialization::get_path_context
();
190
if
(ctx && ctx->is_recording())
191
{
192
return
ctx->should_serialize_property(ctx->get_current_path());
193
}
194
return
true
;
195
};
196
}
197
}
// namespace serialization
a
entt::handle a
Definition
bullet_backend.cpp:98
index
uint16_t index
Definition
gpu_frame_stats_widgets.cpp:31
serialization
Definition
serialization.cpp:5
serialization::log_warning
void log_warning(const std::string &log_msg, const hpp::source_location &loc)
Definition
serialization.cpp:19
serialization::get_current_deserialization_path
auto get_current_deserialization_path() -> std::string
Definition
serialization.cpp:149
serialization::log_callback_t
std::function< void(const std::string &, const hpp::source_location &loc)> log_callback_t
Definition
serialization.h:24
serialization::set_path_context
void set_path_context(path_context *ctx)
Definition
serialization.cpp:31
serialization::init
void init(const init_data &data)
Definition
serialization.cpp:161
serialization::get_path_context
auto get_path_context() -> path_context *
Definition
serialization.cpp:26
std
Hash specialization for batch_key to enable use in std::unordered_map.
Definition
render_view_keys.h:37
serialization.h
serialization::init_data
Definition
serialization.h:27
serialization::init_data::warning_logger
log_callback_t warning_logger
Definition
serialization.h:28
serialization::path_context
Definition
serialization.h:35
serialization::path_context::recording_enabled
bool recording_enabled
Definition
serialization.h:38
serialization::path_context::clear
void clear()
Definition
serialization.cpp:97
serialization::path_context::disable_recording
void disable_recording()
Definition
serialization.cpp:87
serialization::path_context::get_current_path
auto get_current_path() const -> std::string
Definition
serialization.cpp:66
serialization::path_context::push_segment
auto push_segment(const std::string &segment) -> bool
Definition
serialization.cpp:36
serialization::path_context::pop_segment
void pop_segment()
Definition
serialization.cpp:53
serialization::path_context::enable_recording
void enable_recording()
Definition
serialization.cpp:82
serialization::path_context::is_recording
auto is_recording() const -> bool
Definition
serialization.cpp:92
serialization::path_context::path_segments
std::vector< std::string > path_segments
Definition
serialization.h:37
serialization::path_segment_guard::~path_segment_guard
~path_segment_guard()
Definition
serialization.cpp:108
serialization::path_segment_guard::pop_segment
void pop_segment()
Definition
serialization.cpp:122
serialization::path_segment_guard::path_segment_guard
path_segment_guard()=default
serialization::path_segment_guard::push_segment
void push_segment(const std::string &segment)
Definition
serialization.cpp:114
serialization::path_skip_segment_guard::~path_skip_segment_guard
~path_skip_segment_guard()
Definition
serialization.cpp:145
serialization::path_skip_segment_guard::path_skip_segment_guard
path_skip_segment_guard(bool ignore_next_push=false)
Definition
serialization.cpp:136
engine
core
serialization
serialization.cpp
Generated by
1.12.0