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