Boost logo

Boost :

From: René Bürgel (r.buergel_at_[hidden])
Date: 2007-12-05 10:07:54


As this is pretty straightforward, would you mind adding the
serialization code for this two classes to your library?
I just adapted it from map/multimap and it works without any problems on
gcc-4.2 for Linux on x86 and PowerPC

#include <tr1/unordered_map>

#include <boost/config.hpp>

#include <boost/serialization/utility.hpp>
#include <boost/serialization/collections_save_imp.hpp>
#include <boost/serialization/collections_load_imp.hpp>
#include <boost/serialization/split_free.hpp>

namespace boost {
namespace serialization {

template<class Archive, class Type, class Key, class Hash, class
Compare, class Allocator >
inline void save(
   Archive & ar,
   const std::tr1::unordered_map<Key, Type, Hash, Compare, Allocator> &t,
   const unsigned int /* file_version */
){
   boost::serialization::stl::save_collection<
       Archive,
       std::tr1::unordered_map<Key, Type, Hash, Compare, Allocator>
>(ar, t);
}

template<class Archive, class Type, class Key, class Hash, class
Compare, class Allocator >
inline void load(
   Archive & ar,
   std::tr1::unordered_map<Key, Type, Hash, Compare, Allocator> &t,
   const unsigned int /* file_version */
){
   boost::serialization::stl::load_collection<
       Archive,
       std::tr1::unordered_map<Key, Type, Hash, Compare, Allocator>,
       boost::serialization::stl::archive_input_unique<
           Archive, std::tr1::unordered_map<Key, Type, Hash, Compare,
Allocator> >,
           
boost::serialization::stl::no_reserve_imp<std::tr1::unordered_map<
               Key, Type, Hash, Compare, Allocator
>
>
>(ar, t);
}

// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<class Archive, class Type, class Key, class Hash, class
Compare, class Allocator >
inline void serialize(
   Archive & ar,
   std::tr1::unordered_map<Key, Type, Hash, Compare, Allocator> &t,
   const unsigned int file_version
){
   boost::serialization::split_free(ar, t, file_version);
}

// unordered_multimap
template<class Archive, class Type, class Key, class Hash, class
Compare, class Allocator >
inline void save(
   Archive & ar,
   const std::tr1::unordered_multimap<Key, Type, Hash, Compare,
Allocator> &t,
   const unsigned int /* file_version */
){
   boost::serialization::stl::save_collection<
       Archive,
       std::tr1::unordered_multimap<Key, Type, Hash, Compare, Allocator>
>(ar, t);
}

template<class Archive, class Type, class Key, class Hash, class
Compare, class Allocator >
inline void load(
   Archive & ar,
   std::tr1::unordered_multimap<Key, Type, Hash, Compare, Allocator> &t,
   const unsigned int /* file_version */
){
   boost::serialization::stl::load_collection<
       Archive,
       std::tr1::unordered_multimap<Key, Type, Hash, Compare, Allocator>,
       boost::serialization::stl::archive_input_multi<
           Archive, std::tr1::unordered_multimap<Key, Type, Hash,
Compare, Allocator>
>,
       boost::serialization::stl::no_reserve_imp<
           std::tr1::unordered_multimap<Key, Type, Hash, Compare,
Allocator>
>
>(ar, t);
}

// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<class Archive, class Type, class Key, class Hash, class
Compare, class Allocator >
inline void serialize(
   Archive & ar,
   std::tr1::unordered_multimap<Key, Type, Hash, Compare, Allocator> &t,
   const unsigned int file_version
){
   boost::serialization::split_free(ar, t, file_version);
}

} // serialization
} // namespace boost

Thanks in advance,

René Bürgel

-- 
Unicontrol Systemtechnik GmbH
OT Dittersbach
Sachsenburger Weg 34
09669 Frankenberg
 
Tel.: 03 72 06/ 88 73 - 12
Fax: 03 72 06/ 88 73 - 60
E-Mail: r.buergel_at_[hidden]
Internet: www.unicontrol.de
 
Unicontrol Systemtechnik GmbH
Geschäftsführer: Dipl.-Ing. Siegfried Heinze
Sitz der Gesellschaft: Frankenberg
Registergericht: Amtsgericht Chemnitz, HRB 15 475

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk