Electroneum
unordered_containers_boost_serialization.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2021, The Electroneum Project
2 // Copyrights(c) 2014-2019, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 
34 #include <boost/serialization/split_free.hpp>
35 #include <unordered_map>
36 #include <unordered_set>
37 
38 namespace boost
39 {
40  namespace serialization
41  {
42  template <class Archive, class h_key, class hval>
43  inline void save(Archive &a, const std::unordered_map<h_key, hval> &x, const boost::serialization::version_type ver)
44  {
45  size_t s = x.size();
46  a << s;
47  for(auto& v: x)
48  {
49  a << v.first;
50  a << v.second;
51  }
52  }
53 
54  template <class Archive, class h_key, class hval>
55  inline void load(Archive &a, std::unordered_map<h_key, hval> &x, const boost::serialization::version_type ver)
56  {
57  x.clear();
58  size_t s = 0;
59  a >> s;
60  for(size_t i = 0; i != s; i++)
61  {
62  h_key k;
63  hval v;
64  a >> k;
65  a >> v;
66  x.insert(std::pair<h_key, hval>(k, v));
67  }
68  }
69 
70 
71  template <class Archive, class h_key, class hval>
72  inline void save(Archive &a, const std::unordered_multimap<h_key, hval> &x, const boost::serialization::version_type ver)
73  {
74  size_t s = x.size();
75  a << s;
76  for(auto& v: x)
77  {
78  a << v.first;
79  a << v.second;
80  }
81  }
82 
83  template <class Archive, class h_key, class hval>
84  inline void load(Archive &a, std::unordered_multimap<h_key, hval> &x, const boost::serialization::version_type ver)
85  {
86  x.clear();
87  size_t s = 0;
88  a >> s;
89  for(size_t i = 0; i != s; i++)
90  {
91  h_key k;
92  hval v;
93  a >> k;
94  a >> v;
95  x.emplace(k, v);
96  }
97  }
98 
99 
100  template <class Archive, class hval>
101  inline void save(Archive &a, const std::unordered_set<hval> &x, const boost::serialization::version_type ver)
102  {
103  size_t s = x.size();
104  a << s;
105  for(auto& v: x)
106  {
107  a << v;
108  }
109  }
110 
111  template <class Archive, class hval>
112  inline void load(Archive &a, std::unordered_set<hval> &x, const boost::serialization::version_type ver)
113  {
114  x.clear();
115  size_t s = 0;
116  a >> s;
117  for(size_t i = 0; i != s; i++)
118  {
119  hval v;
120  a >> v;
121  x.insert(v);
122  }
123  }
124 
125 
126  template <class Archive, class h_key, class hval>
127  inline void serialize(Archive &a, std::unordered_map<h_key, hval> &x, const boost::serialization::version_type ver)
128  {
129  split_free(a, x, ver);
130  }
131 
132  template <class Archive, class h_key, class hval>
133  inline void serialize(Archive &a, std::unordered_multimap<h_key, hval> &x, const boost::serialization::version_type ver)
134  {
135  split_free(a, x, ver);
136  }
137 
138  template <class Archive, class hval>
139  inline void serialize(Archive &a, std::unordered_set<hval> &x, const boost::serialization::version_type ver)
140  {
141  split_free(a, x, ver);
142  }
143  }
144 }
void save(Archive &a, const std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
void serialize(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
void load(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124