QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxSerialize_unordered_map.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifdef _QX_ENABLE_BOOST_SERIALIZATION
33#ifndef _QX_SERIALIZATION_BOOST_UNORDERED_MAP_H_
34#define _QX_SERIALIZATION_BOOST_UNORDERED_MAP_H_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
40#include <boost/serialization/serialization.hpp>
41#include <boost/serialization/collections_save_imp.hpp>
42#include <boost/serialization/collections_load_imp.hpp>
43#include <boost/serialization/split_free.hpp>
44#include <boost/serialization/utility.hpp>
45#include <boost/serialization/nvp.hpp>
46
47namespace boost {
48namespace serialization {
49
50#if (BOOST_VERSION > 105700)
51
52template <class Archive, class Key, class Value>
53inline void save(Archive & ar, const boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
54{
55 long lSize = static_cast<long>(t.size());
56 ar << boost::serialization::make_nvp("size", lSize);
57
58 typedef typename boost::unordered_map<Key, Value>::const_iterator type_itr;
59 for (type_itr itr = t.begin(); itr != t.end(); ++itr)
60 {
61 std::pair<Key, Value> pair_key_value = std::make_pair(itr->first, itr->second);
62 ar << boost::serialization::make_nvp("item", pair_key_value);
63 }
64}
65
66template <class Archive, class Key, class Value>
67inline void load(Archive & ar, boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
68{
69 long lSize = 0;
70 ar >> boost::serialization::make_nvp("size", lSize);
71
72 t.clear();
73 t.reserve(lSize);
74 std::pair<Key, Value> pair_key_value;
75
76 for (long l = 0; l < lSize; l++)
77 {
78 ar >> boost::serialization::make_nvp("item", pair_key_value);
79 t.insert(pair_key_value);
80 }
81}
82
83#else // (BOOST_VERSION > 105700)
84
85template <class Archive, class Key, class Value>
86inline void save(Archive & ar, const boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
87{
88 boost::serialization::stl::save_collection< Archive, boost::unordered_map<Key, Value> >(ar, t);
89}
90
91template <class Archive, class Key, class Value>
92inline void load(Archive & ar, boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
93{
94 boost::serialization::stl::load_collection< Archive, boost::unordered_map<Key, Value>,
95 boost::serialization::stl::archive_input_map< Archive, boost::unordered_map<Key, Value> >,
96 boost::serialization::stl::no_reserve_imp< boost::unordered_map<Key, Value> > >(ar, t);
97}
98
99#endif // (BOOST_VERSION > 105700)
100
101template <class Archive, class Key, class Value>
102inline void serialize(Archive & ar, boost::unordered_map<Key, Value> & t, const unsigned int file_version)
103{
104 boost::serialization::split_free(ar, t, file_version);
105}
106
107#if (BOOST_VERSION > 105700)
108
109template <class Archive, class Key, class Value>
110inline void save(Archive & ar, const boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
111{
112 long lSize = static_cast<long>(t.size());
113 ar << boost::serialization::make_nvp("size", lSize);
114
115 typedef typename boost::unordered_multimap<Key, Value>::const_iterator type_itr;
116 for (type_itr itr = t.begin(); itr != t.end(); ++itr)
117 {
118 std::pair<Key, Value> pair_key_value = std::make_pair(itr->first, itr->second);
119 ar << boost::serialization::make_nvp("item", pair_key_value);
120 }
121}
122
123template <class Archive, class Key, class Value>
124inline void load(Archive & ar, boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
125{
126 long lSize = 0;
127 ar >> boost::serialization::make_nvp("size", lSize);
128
129 t.clear();
130 t.reserve(lSize);
131 std::pair<Key, Value> pair_key_value;
132
133 for (long l = 0; l < lSize; l++)
134 {
135 ar >> boost::serialization::make_nvp("item", pair_key_value);
136 t.insert(pair_key_value);
137 }
138}
139
140#else // (BOOST_VERSION > 105700)
141
142template <class Archive, class Key, class Value>
143inline void save(Archive & ar, const boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
144{
145 boost::serialization::stl::save_collection< Archive, boost::unordered_multimap<Key, Value> >(ar, t);
146}
147
148template <class Archive, class Key, class Value>
149inline void load(Archive & ar, boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
150{
151#if (BOOST_VERSION >= 104200)
152 boost::serialization::stl::load_collection< Archive, boost::unordered_multimap<Key, Value>,
153 boost::serialization::stl::archive_input_map< Archive, boost::unordered_multimap<Key, Value> >,
154 boost::serialization::stl::no_reserve_imp< boost::unordered_multimap<Key, Value> > >(ar, t);
155#else // (BOOST_VERSION >= 104200)
156 boost::serialization::stl::load_collection< Archive, boost::unordered_multimap<Key, Value>,
157 boost::serialization::stl::archive_input_multimap< Archive, boost::unordered_multimap<Key, Value> >,
158 boost::serialization::stl::no_reserve_imp< boost::unordered_multimap<Key, Value> > >(ar, t);
159#endif // (BOOST_VERSION >= 104200)
160}
161
162#endif // (BOOST_VERSION > 105700)
163
164template <class Archive, class Key, class Value>
165inline void serialize(Archive & ar, boost::unordered_multimap<Key, Value> & t, const unsigned int file_version)
166{
167 boost::serialization::split_free(ar, t, file_version);
168}
169
170} // namespace serialization
171} // namespace boost
172
173#endif // _QX_SERIALIZATION_BOOST_UNORDERED_MAP_H_
174#endif // _QX_ENABLE_BOOST_SERIALIZATION
void serialize(Archive &ar, boost::tuple< T0, T1 > &t, const unsigned int file_version)
void load(Archive &ar, boost::unordered_map< Key, Value > &t, const unsigned int)
void save(Archive &ar, const boost::unordered_map< Key, Value > &t, const unsigned int)