Xped
Loading...
Searching...
No Matches
YasHelpers.hpp
Go to the documentation of this file.
1#ifndef XPED_YAS_HELPERS_HPP
2#define XPED_YAS_HELPERS_HPP
3
4#include <filesystem>
5
6#include "yas/serialize.hpp"
7#include "yas/std_types.hpp"
8
9namespace yas {
10namespace detail {
11
12/***************************************************************************/
13
14template <std::size_t F>
15struct serializer<type_prop::not_a_fundamental, ser_case::use_internal_serializer, F, std::filesystem::path>
16{
17 template <typename Archive>
18 static Archive& save(Archive& ar, const std::filesystem::path& p)
19 {
20 __YAS_CONSTEXPR_IF(F & yas::json)
21 {
22 if(p.string().empty()) {
23 ar.write("null", 4);
24 } else {
25 ar.write("\"", 1);
26 save_string(ar, p.string().data(), p.string().size());
27 ar.write("\"", 1);
28 }
29 }
30 else
31 {
32 ar.write_seq_size(p.string().length());
33 ar.write(p.string().data(), p.string().length());
34 }
35 return ar;
36 }
37
38 template <typename Archive>
39 static Archive& load(Archive& ar, std::filesystem::path& p)
40 {
41 std::string tmp;
42
43 __YAS_CONSTEXPR_IF(F & yas::json)
44 {
45 char ch = ar.getch();
46 if(ch == '\"') {
47 load_string(tmp, ar);
48 __YAS_THROW_IF_WRONG_JSON_CHARS(ar, "\"");
49 } else if(ch == 'n') {
50 ar.ungetch(ch);
51 __YAS_THROW_IF_WRONG_JSON_CHARS(ar, "null");
52 tmp.clear();
53 } else if(is_valid_for_int_and_double(ar, ch)) {
54 tmp += ch;
55 for(ch = ar.peekch(); is_valid_for_int_and_double(ar, ch); ch = ar.peekch()) { tmp += ar.getch(); }
56 } else {
57 __YAS_THROW_IF_WRONG_JSON_CHARS(ar, "unreachable");
58 }
59 }
60 else
61 {
62 const auto size = ar.read_seq_size();
63 tmp.resize(size);
64 ar.read(__YAS_CCAST(char*, tmp.data()), size);
65 }
66 p = tmp;
67 return ar;
68 }
69};
70
71/***************************************************************************/
72
73} // namespace detail
74} // namespace yas
75
76#endif