libkazv
immer-flex-vector.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of libkazv.
3  * SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
4  * SPDX-License-Identifier: AGPL-3.0-or-later
5  */
6 
7 #pragma once
8 
9 #include <libkazv-config.hpp>
10 
11 #include <boost/serialization/nvp.hpp>
12 #include <boost/serialization/split_free.hpp>
13 
14 #include <immer/flex_vector.hpp>
15 #include <immer/flex_vector_transient.hpp>
16 
17 namespace boost::serialization
18 {
19  template<class Archive,
20  class T,
21  class MP,
22  std::uint32_t B,
23  std::uint32_t BL>
24  void save(Archive &ar, const immer::flex_vector<T, MP, B, BL> &v, const unsigned int /* version */)
25  {
26  auto size = v.size();
27  ar << BOOST_SERIALIZATION_NVP(size);
28 
29  for (const auto &i : v) {
30  ar << i;
31  }
32  }
33 
34  template<class Archive,
35  class T,
36  class MP,
37  std::uint32_t B,
38  std::uint32_t BL>
39  void load(Archive &ar, immer::flex_vector<T, MP, B, BL> &v, const unsigned int /* version */)
40  {
41  using VecT = immer::flex_vector<T, MP, B, BL>;
42  using TransientT = decltype(v.transient());
43  using SizeT = decltype(v.size());
44  using ValueT = typename VecT::value_type;
45 
46  SizeT size{};
47  ar >> BOOST_SERIALIZATION_NVP(size);
48  TransientT transient = VecT(size).transient();
49 
50  for (auto i = SizeT{}; i != size; ++i) {
51  ValueT val;
52  ar >> val;
53  transient.set(i, std::move(val));
54  }
55 
56  v = transient.persistent();
57  }
58 
59  template<class Archive,
60  class T,
61  class MP,
62  std::uint32_t B,
63  std::uint32_t BL>
64  inline void serialize(Archive &ar, immer::flex_vector<T, MP, B, BL> &v, const unsigned int version)
65  {
66  boost::serialization::split_free(ar, v, version);
67  }
68 }
Definition: immer-array.hpp:18
void load(Archive &ar, immer::array< T, MP > &v, const unsigned int)
Definition: immer-array.hpp:35
void serialize(Archive &ar, immer::array< T, MP > &v, const unsigned int version)
Definition: immer-array.hpp:58
void save(Archive &ar, const immer::array< T, MP > &v, const unsigned int)
Definition: immer-array.hpp:22