QxOrm  1.4.3
C++ Object Relational Mapping library
QxSerialize_unordered_map.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** http://www.qxorm.com/
00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
00005 **
00006 ** This file is part of the QxOrm library
00007 **
00008 ** This software is provided 'as-is', without any express or implied
00009 ** warranty. In no event will the authors be held liable for any
00010 ** damages arising from the use of this software
00011 **
00012 ** Commercial Usage
00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
00014 ** accordance with the commercial license agreement provided with the
00015 ** Software or, alternatively, in accordance with the terms contained in
00016 ** a written agreement between you and Lionel Marty
00017 **
00018 ** GNU General Public License Usage
00019 ** Alternatively, this file may be used under the terms of the GNU
00020 ** General Public License version 3.0 as published by the Free Software
00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
00022 ** packaging of this file. Please review the following information to
00023 ** ensure the GNU General Public License version 3.0 requirements will be
00024 ** met : http://www.gnu.org/copyleft/gpl.html
00025 **
00026 ** If you are unsure which license is appropriate for your use, or
00027 ** if you have questions regarding the use of this file, please contact :
00028 ** contact@qxorm.com
00029 **
00030 ****************************************************************************/
00031 
00032 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00033 #ifndef _QX_SERIALIZATION_BOOST_UNORDERED_MAP_H_
00034 #define _QX_SERIALIZATION_BOOST_UNORDERED_MAP_H_
00035 
00036 #ifdef _MSC_VER
00037 #pragma once
00038 #endif
00039 
00040 #include <boost/version.hpp>
00041 #include <boost/unordered_map.hpp>
00042 
00043 #include <boost/serialization/serialization.hpp>
00044 #include <boost/serialization/collections_save_imp.hpp>
00045 #include <boost/serialization/collections_load_imp.hpp>
00046 #include <boost/serialization/split_free.hpp>
00047 #include <boost/serialization/utility.hpp>
00048 #include <boost/serialization/nvp.hpp>
00049 
00050 namespace boost {
00051 namespace serialization {
00052 
00053 #if (BOOST_VERSION > 105700)
00054 
00055 template <class Archive, class Key, class Value>
00056 inline void save(Archive & ar, const boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
00057 {
00058    long lSize = static_cast<long>(t.size());
00059    ar << boost::serialization::make_nvp("size", lSize);
00060 
00061    typedef typename boost::unordered_map<Key, Value>::const_iterator type_itr;
00062    for (type_itr itr = t.begin(); itr != t.end(); ++itr)
00063    {
00064       std::pair<Key, Value> pair_key_value = std::make_pair(itr->first, itr->second);
00065       ar << boost::serialization::make_nvp("item", pair_key_value);
00066    }
00067 }
00068 
00069 template <class Archive, class Key, class Value>
00070 inline void load(Archive & ar, boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
00071 {
00072    long lSize = 0;
00073    ar >> boost::serialization::make_nvp("size", lSize);
00074 
00075    t.clear();
00076    t.reserve(lSize);
00077    std::pair<Key, Value> pair_key_value;
00078 
00079    for (long l = 0; l < lSize; l++)
00080    {
00081       ar >> boost::serialization::make_nvp("item", pair_key_value);
00082       t.insert(pair_key_value);
00083    }
00084 }
00085 
00086 #else // (BOOST_VERSION > 105700)
00087 
00088 template <class Archive, class Key, class Value>
00089 inline void save(Archive & ar, const boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
00090 {
00091    boost::serialization::stl::save_collection< Archive, boost::unordered_map<Key, Value> >(ar, t);
00092 }
00093 
00094 template <class Archive, class Key, class Value>
00095 inline void load(Archive & ar, boost::unordered_map<Key, Value> & t, const unsigned int /* file_version */)
00096 {
00097    boost::serialization::stl::load_collection< Archive, boost::unordered_map<Key, Value>,
00098       boost::serialization::stl::archive_input_map< Archive, boost::unordered_map<Key, Value> >,
00099       boost::serialization::stl::no_reserve_imp< boost::unordered_map<Key, Value> > >(ar, t);
00100 }
00101 
00102 #endif // (BOOST_VERSION > 105700)
00103 
00104 template <class Archive, class Key, class Value>
00105 inline void serialize(Archive & ar, boost::unordered_map<Key, Value> & t, const unsigned int file_version)
00106 {
00107    boost::serialization::split_free(ar, t, file_version);
00108 }
00109 
00110 #if (BOOST_VERSION > 105700)
00111 
00112 template <class Archive, class Key, class Value>
00113 inline void save(Archive & ar, const boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
00114 {
00115    long lSize = static_cast<long>(t.size());
00116    ar << boost::serialization::make_nvp("size", lSize);
00117 
00118    typedef typename boost::unordered_multimap<Key, Value>::const_iterator type_itr;
00119    for (type_itr itr = t.begin(); itr != t.end(); ++itr)
00120    {
00121       std::pair<Key, Value> pair_key_value = std::make_pair(itr->first, itr->second);
00122       ar << boost::serialization::make_nvp("item", pair_key_value);
00123    }
00124 }
00125 
00126 template <class Archive, class Key, class Value>
00127 inline void load(Archive & ar, boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
00128 {
00129    long lSize = 0;
00130    ar >> boost::serialization::make_nvp("size", lSize);
00131 
00132    t.clear();
00133    t.reserve(lSize);
00134    std::pair<Key, Value> pair_key_value;
00135 
00136    for (long l = 0; l < lSize; l++)
00137    {
00138       ar >> boost::serialization::make_nvp("item", pair_key_value);
00139       t.insert(pair_key_value);
00140    }
00141 }
00142 
00143 #else // (BOOST_VERSION > 105700)
00144 
00145 template <class Archive, class Key, class Value>
00146 inline void save(Archive & ar, const boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
00147 {
00148    boost::serialization::stl::save_collection< Archive, boost::unordered_multimap<Key, Value> >(ar, t);
00149 }
00150 
00151 template <class Archive, class Key, class Value>
00152 inline void load(Archive & ar, boost::unordered_multimap<Key, Value> & t, const unsigned int /* file_version */)
00153 {
00154 #if (BOOST_VERSION >= 104200)
00155    boost::serialization::stl::load_collection< Archive, boost::unordered_multimap<Key, Value>,
00156       boost::serialization::stl::archive_input_map< Archive, boost::unordered_multimap<Key, Value> >,
00157       boost::serialization::stl::no_reserve_imp< boost::unordered_multimap<Key, Value> > >(ar, t);
00158 #else // (BOOST_VERSION >= 104200)
00159    boost::serialization::stl::load_collection< Archive, boost::unordered_multimap<Key, Value>,
00160       boost::serialization::stl::archive_input_multimap< Archive, boost::unordered_multimap<Key, Value> >,
00161       boost::serialization::stl::no_reserve_imp< boost::unordered_multimap<Key, Value> > >(ar, t);
00162 #endif // (BOOST_VERSION >= 104200)
00163 }
00164 
00165 #endif // (BOOST_VERSION > 105700)
00166 
00167 template <class Archive, class Key, class Value>
00168 inline void serialize(Archive & ar, boost::unordered_multimap<Key, Value> & t, const unsigned int file_version)
00169 {
00170    boost::serialization::split_free(ar, t, file_version);
00171 }
00172 
00173 } // namespace serialization
00174 } // namespace boost
00175 
00176 #endif // _QX_SERIALIZATION_BOOST_UNORDERED_MAP_H_
00177 #endif // _QX_ENABLE_BOOST_SERIALIZATION