70#define JUCE_COMPARISON_OPS X(==) X(!=) X(<) X(<=) X(>) X(>=)
89 #define X(op) auto operator op (const Named& other) const { return value op other.value; }
119 #define X(op) auto operator op (const SerialisationSize& other) const { return size op other.size; }
132#undef JUCE_COMPARISON_OPS
141template <
typename...
Ts>
142struct SerialisationTraits<
std::vector<Ts...>>
144 static constexpr auto marshallingVersion = std::nullopt;
146 template <
typename Archive,
typename T>
149 auto size = t.size();
153 for (
auto& element : t)
157 template <
typename Archive,
typename T>
162 for (
auto& element : t)
167template <
typename Element,
typename Mutex,
int minSize>
168struct SerialisationTraits<Array<Element, Mutex, minSize>>
170 static constexpr auto marshallingVersion = std::nullopt;
172 template <
typename Archive,
typename T>
175 auto size = t.size();
179 for (
auto& element : t)
183 template <
typename Archive,
typename T>
188 for (
auto& element : t)
194struct SerialisationTraits<StringArray>
196 static constexpr auto marshallingVersion = std::nullopt;
198 template <
typename Archive,
typename T>
205template <
typename...
Ts>
206struct SerialisationTraits<
std::pair<Ts...>>
208 static constexpr auto marshallingVersion = std::nullopt;
210 template <
typename Archive,
typename T>
218struct SerialisationTraits<
std::optional<T>>
220 static constexpr auto marshallingVersion = std::nullopt;
222 template <
typename Archive>
236 template <
typename Archive>
247struct SerialisationTraits<
std::string>
249 static constexpr auto marshallingVersion = std::nullopt;
251 template <
typename Archive>
259 template <
typename Archive>
266template <
typename...
Ts>
267struct SerialisationTraits<
std::map<Ts...>>
269 static constexpr auto marshallingVersion = std::nullopt;
271 template <
typename Archive,
typename T>
274 auto size = t.size();
277 for (
auto i = (
decltype (size)) 0; i <
size; ++i)
285 template <
typename Archive,
typename T>
288 auto size = t.size();
291 for (
const auto& element : t)
296template <
typename...
Ts>
297struct SerialisationTraits<
std::set<Ts...>>
299 static constexpr auto marshallingVersion = std::nullopt;
301 template <
typename Archive,
typename T>
304 auto size = t.size();
307 for (
auto i = (
decltype (size)) 0; i <
size; ++i)
309 typename T::value_type element;
315 template <
typename Archive,
typename T>
318 auto size = t.size();
321 for (
const auto& element : t)
327struct SerialisationTraits<
char[
N]>
329 static constexpr auto marshallingVersion = std::nullopt;
331 template <
typename Archive,
typename T>
335template <
typename Element,
size_t N>
336struct SerialisationTraits<Element[
N]>
338 static constexpr auto marshallingVersion = std::nullopt;
340 template <
typename Archive,
typename T>
346 for (
auto& element : t)
350 template <
typename Archive,
typename T>
356 for (
auto& element : t)
361template <
typename Element,
size_t N>
362struct SerialisationTraits<
std::array<Element, N>>
364 static constexpr auto marshallingVersion = std::nullopt;
366 template <
typename Archive,
typename T>
372 for (
auto& element : t)
376 template <
typename Archive,
typename T>
382 for (
auto& element : t)
397 template <
typename... Ts>
398 bool operator() (Ts&&...);
403 template <
typename T,
typename =
void>
406 template <
typename T>
409 template <
typename Traits,
typename T,
typename =
void>
412 template <
typename Traits,
typename T>
415 template <
typename Traits,
typename T,
typename =
void>
418 template <
typename Traits,
typename T>
421 template <
typename Traits,
typename T,
typename =
void>
424 template <
typename Traits,
typename T>
427 template <
typename T>
430 template <
typename T>
433 template <
typename T>
436 template <
typename T>
458 template <
typename T>
461 if constexpr (std::is_arithmetic_v<T> || std::is_enum_v<T> || std::is_same_v<T, String> || std::is_same_v<T, var>)
462 return SerialisationKind::primitive;
464 return SerialisationKind::internal;
466 return SerialisationKind::external;
468 return SerialisationKind::none;
472 template <
typename T, SerialisationKind kind = serialisationKind<T>>
475 static constexpr auto marshallingVersion = std::nullopt;
477 template <
typename Archive,
typename Primitive>
478 static auto load (Archive& archive, Primitive& t)
480 if constexpr (std::is_enum_v<Primitive>)
486 template <
typename Archive,
typename Primitive>
487 static auto save (Archive& archive,
const Primitive& t)
489 if constexpr (std::is_enum_v<Primitive>)
500 template <
typename T>
505 template <
typename Archive,
typename Item>
506 static auto serialise (Archive& archive, Item& t) ->
decltype (Item::serialise (archive, t)) {
return Item::serialise (archive, t); }
508 template <
typename Archive,
typename Item>
509 static auto load (Archive& archive, Item& t) ->
decltype (Item::load (archive, t)) {
return Item::load (archive, t); }
511 template <
typename Archive,
typename Item>
512 static auto save (Archive& archive,
const Item& t) ->
decltype (Item::save (archive, t)) {
return Item::save (archive, t); }
519 template <
typename T>
522 template <
typename T,
typename =
void>
525 template <
typename T>
526 constexpr auto hasSerialise<T,
std::void_t<
decltype (ForwardingSerialisationTraits<T>::serialise (std::declval<DummyArchive&>(), std::declval<T&>()))>> =
true;
528 template <
typename T,
typename =
void>
529 constexpr auto hasLoad =
false;
531 template <
typename T>
532 constexpr auto hasLoad<T,
std::void_t<
decltype (ForwardingSerialisationTraits<T>::load (std::declval<DummyArchive&>(), std::declval<T&>()))>> =
true;
534 template <
typename T,
typename =
void>
535 constexpr auto hasSave =
false;
537 template <
typename T>
538 constexpr auto hasSave<T,
std::void_t<
decltype (ForwardingSerialisationTraits<T>::save (std::declval<DummyArchive&>(), std::declval<const T&>()))>> =
true;
540 template <
typename T>
545 template <
typename Archive,
typename T>
549 static_assert (
delayStaticAssert<T>,
"No serialisation function found or marshallingVersion unset");
551 return ForwardingSerialisationTraits<T>::serialise (
archive, t);
553 return ForwardingSerialisationTraits<T>::save (
archive, t);
560 template <
typename Archive,
typename T>
564 static_assert (
delayStaticAssert<T>,
"No serialisation function found or marshallingVersion unset");
566 return ForwardingSerialisationTraits<T>::serialise (
archive, t);
568 return ForwardingSerialisationTraits<T>::load (
archive, t);
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
constexpr auto named(std::string_view c, T &t)
Produces a Named instance that holds a mutable reference.
constexpr auto serialisationSize(T &t) -> std::enable_if_t< std::is_integral_v< T >, SerialisationSize< T > >
Produces a SerialisationSize instance that holds a mutable reference to a size value.
Allows serialisation functions to be attached to a specific type without having to modify the declara...
Combines an object with a name.
T & value
A reference to a value to wrap.
std::string_view name
A name that corresponds to the value.
Holds a reference to some kind of size value, used to indicate that an object being marshalled is of ...