23#ifndef VCL_IO_SERIALIZATION_SERIALIZE_H
24#define VCL_IO_SERIALIZATION_SERIALIZE_H
28#include <vclib/concepts/serialization.h>
29#include <vclib/concepts/types.h>
49void serialize(std::ostream& os,
const T& data, std::endian endian)
51 if (endian != std::endian::native) {
52 T swapped = detail::swapEndian(data);
53 os.write(
reinterpret_cast<const char*
>(&swapped),
sizeof(T));
56 os.write(
reinterpret_cast<const char*
>(&data),
sizeof(T));
79 std::endian endian = std::endian::little)
81 for (std::size_t i = 0; i < size; ++i) {
82 serialize(os, data[i], endian);
86template<
typename T,
typename... Others>
87void serialize(std::ostream& os,
const T& data,
const Others&... others)
89 if constexpr (Serializable<T>) {
93 serialize(os, data, std::endian::little);
95 if constexpr (
sizeof...(Others) > 0) {
96 serialize(os, others...);
106template<
typename T, std::
size_t N>
107void serialize(std::ostream& os,
const std::array<T, N>& a)
109 if constexpr (Serializable<T>) {
110 for (
const T& v : a) {
115 for (
const T& e : a) {
125inline void serialize(std::ostream& os,
const std::string& s)
127 std::size_t size = s.size();
129 serializeN(os, s.data(), size);
137void serialize(std::ostream& os,
const std::vector<T>& v)
139 std::size_t size = v.size();
141 if constexpr (Serializable<T>) {
142 for (
const T& e : v) {
147 for (
const T& e : v) {