2#include "ser20/access.hpp"
3#include "ser20/ser20.hpp"
4#include "ser20/types/polymorphic.hpp"
5#include "ser20/types/vector.hpp"
6#include <hpp/source_location.hpp>
7#include <hpp/concepts.hpp>
13#include <unordered_map>
15#define SERIALIZE_FUNCTION_NAME SER20_SERIALIZE_FUNCTION_NAME
16#define SAVE_FUNCTION_NAME SER20_SAVE_FUNCTION_NAME
17#define LOAD_FUNCTION_NAME SER20_LOAD_FUNCTION_NAME
18#define SAVE_MINIMAL_FUNCTION_NAME SER20_SAVE_MINIMAL_FUNCTION_NAME
19#define LOAD_MINIMAL_FUNCTION_NAME SER20_LOAD_MINIMAL_FUNCTION_NAME
20#define SERIALIZE_REGISTER_TYPE_WITH_NAME(T, Name) SER20_REGISTER_TYPE_WITH_NAME(T, Name)
24using log_callback_t = std::function<void(
const std::string&,
const hpp::source_location& loc)>;
30void log_warning(
const std::string& log_msg,
const hpp::source_location& loc = hpp::source_location::current());
81 bool was_pushed_ =
false;
101#define SERIALIZABLE(T) \
104 friend class serialization::access; \
105 template<typename Archive> \
106 friend void SAVE_FUNCTION_NAME(Archive& ar, T const&); \
107 template<typename Archive> \
108 friend void LOAD_FUNCTION_NAME(Archive& ar, T&);
110#define SERIALIZE_INLINE(cls) \
111 template<typename Archive> \
112 inline void SERIALIZE_FUNCTION_NAME(Archive& ar, cls& obj)
114#define SAVE_INLINE(cls) \
115 template<typename Archive> \
116 inline void SAVE_FUNCTION_NAME(Archive& ar, cls const& obj)
118#define LOAD_INLINE(cls) \
119 template<typename Archive> \
120 inline void LOAD_FUNCTION_NAME(Archive& ar, cls& obj)
122#define SERIALIZE_EXTERN(cls) \
123 template<typename Archive> \
124 extern void SERIALIZE_FUNCTION_NAME(Archive& ar, cls& obj)
126#define SAVE_EXTERN(cls) \
127 template<typename Archive> \
128 extern void SAVE_FUNCTION_NAME(Archive& ar, cls const& obj)
130#define LOAD_EXTERN(cls) \
131 template<typename Archive> \
132 extern void LOAD_FUNCTION_NAME(Archive& ar, cls& obj)
134#define SERIALIZE(cls) \
135 template<typename Archive> \
136 void SERIALIZE_FUNCTION_NAME(Archive& ar, cls& obj)
139 template<typename Archive> \
140 void SAVE_FUNCTION_NAME(Archive& ar, cls const& obj)
143 template<typename Archive> \
144 void LOAD_FUNCTION_NAME(Archive& ar, cls& obj)
146#define SERIALIZE_INSTANTIATE(cls, Archive) template void SERIALIZE_FUNCTION_NAME(Archive& archive, cls& obj)
148#define SAVE_INSTANTIATE(cls, Archive) template void SAVE_FUNCTION_NAME(Archive& archive, cls const& obj)
150#define LOAD_INSTANTIATE(cls, Archive) template void LOAD_FUNCTION_NAME(Archive& archive, cls& obj)
152template<
typename Archive>
159template<
typename Archive>
162 return Archive::is_loading::value;
166template<
typename Archive,
typename T>
168 ser20::NameValuePair<T>&& t,
169 const hpp::source_location& loc = hpp::source_location::current()) -> bool;
171template<
typename Archive,
typename T>
173 ser20::NameValuePair<T>&& t,
174 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
178 ar(std::forward<ser20::NameValuePair<T>>(t));
180 catch(
const std::exception& e)
249 auto path = path_ctx->get_current_path();
250 if(!path_ctx->should_serialize_property(path))
254 return serialize_callback();
256 return serialize_callback();
260template<
typename Archive,
typename T>
262 ser20::NameValuePair<T>&& t,
263 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
267 return try_serialize_direct(ar, std::forward<ser20::NameValuePair<T>>(t), loc);
274template<
typename Archive,
typename T>
276 ser20::NameValuePair<T>&& t,
277 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
279 return try_serialize(ar, std::forward<ser20::NameValuePair<T>>(t), loc);
282template<
typename Archive,
typename T>
284 ser20::NameValuePair<T>&& t,
285 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
287 return try_serialize(ar, std::forward<ser20::NameValuePair<T>>(t), loc);
291template<
typename Archive,
typename F>
294 F&& serialize_callback,
295 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
299 ar.setNextName(
name);
301 return serialize_callback();
304template<
typename Archive,
typename F>
308 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
313template<
typename Archive,
typename F>
317 const hpp::source_location& loc = hpp::source_location::current()) ->
bool
void log_warning(const std::string &log_msg, const hpp::source_location &loc)
auto get_current_deserialization_path() -> std::string
std::function< void(const std::string &, const hpp::source_location &loc)> log_callback_t
void set_path_context(path_context *ctx)
void init(const init_data &data)
auto get_path_context() -> path_context *
Hash specialization for batch_key to enable use in std::unordered_map.
auto try_serialize(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
auto try_serialize_sequence_container(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
auto try_serialize_direct(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
auto serialize_check(const std::string &name, F &&serialize_callback) -> bool
constexpr auto is_binary_archive() -> bool
constexpr auto is_loading_archive() -> bool
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
log_callback_t warning_logger
auto get_current_path() const -> std::string
auto push_segment(const std::string &segment) -> bool
auto should_serialize_property(const std::string &property_path) const -> bool
std::function< bool(const std::string &)> should_serialize_property_callback
auto is_recording() const -> bool
std::vector< std::string > path_segments
path_segment_guard & operator=(const path_segment_guard &)=delete
path_segment_guard(const path_segment_guard &)=delete
path_segment_guard(path_segment_guard &&)=delete
path_segment_guard & operator=(path_segment_guard &&)=delete
path_segment_guard()=default
void push_segment(const std::string &segment)
path_skip_segment_guard(const path_skip_segment_guard &)=delete
~path_skip_segment_guard()
path_skip_segment_guard & operator=(path_skip_segment_guard &&)=delete
path_skip_segment_guard & operator=(const path_skip_segment_guard &)=delete
path_skip_segment_guard(bool ignore_next_push=false)
path_skip_segment_guard(path_skip_segment_guard &&)=delete