quill
FilesystemPath.h
1 
7 #pragma once
8 
9 #include "quill/core/Attributes.h"
10 #include "quill/core/Codec.h"
11 #include "quill/core/DynamicFormatArgStore.h"
12 #include "quill/core/Filesystem.h"
13 #include "quill/core/InlinedVector.h"
14 
15 #include "quill/bundled/fmt/format.h"
16 #include "quill/bundled/fmt/std.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <string>
21 #include <type_traits>
22 
23 #if defined(_WIN32)
24  #include "quill/std/WideString.h"
25 #endif
26 
27 QUILL_BEGIN_NAMESPACE
28 
29 template <>
30 struct Codec<fs::path>
31 {
32  static size_t compute_encoded_size(detail::SizeCacheVector& conditional_arg_size_cache, fs::path const& arg) noexcept
33  {
34  if constexpr (std::is_same_v<fs::path::string_type, std::string>)
35  {
36  return Codec<std::string>::compute_encoded_size(conditional_arg_size_cache, arg.string());
37  }
38 #if defined(_WIN32)
39  else if constexpr (std::is_same_v<fs::path::string_type, std::wstring>)
40  {
41  return Codec<std::wstring>::compute_encoded_size(conditional_arg_size_cache, arg.wstring());
42  }
43 #endif
44  }
45 
46  static void encode(std::byte*& buffer, detail::SizeCacheVector const& conditional_arg_size_cache,
47  uint32_t& conditional_arg_size_cache_index, fs::path const& arg) noexcept
48  {
49  if constexpr (std::is_same_v<fs::path::string_type, std::string>)
50  {
51  Codec<std::string>::encode(buffer, conditional_arg_size_cache,
52  conditional_arg_size_cache_index, arg.string());
53  }
54 #if defined(_WIN32)
55  else if constexpr (std::is_same_v<fs::path::string_type, std::wstring>)
56  {
57  Codec<std::wstring>::encode(buffer, conditional_arg_size_cache,
58  conditional_arg_size_cache_index, arg.wstring());
59  }
60 #endif
61  }
62 
63  static fs::path decode_arg(std::byte*& buffer)
64  {
65  if constexpr (std::is_same_v<fs::path::string_type, std::string>)
66  {
67  return fs::path{Codec<std::string_view>::decode_arg(buffer)};
68  }
69 #if defined(_WIN32)
70  else if constexpr (std::is_same_v<fs::path::string_type, std::wstring>)
71  {
72  return fs::path{Codec<std::wstring_view>::decode_arg(buffer)};
73  }
74 #endif
75  }
76 
77  static void decode_and_store_arg(std::byte*& buffer, DynamicFormatArgStore* args_store)
78  {
79  args_store->push_back(decode_arg(buffer));
80  }
81 };
82 
83 QUILL_END_NAMESPACE
Similar to fmt::dynamic_arg_store but better suited to our needs e.g does not include <functional> an...
Definition: DynamicFormatArgStore.h:77
typename = void for specializations with enable_if
Definition: Codec.h:144
void push_back(T &&arg)
Adds an argument for later passing to a formatting function.
Definition: DynamicFormatArgStore.h:116