set.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef BOOST_SERIALIZATION_SET_HPP
  2. #define BOOST_SERIALIZATION_SET_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // set.hpp: serialization for stl set templates
  9. // (C) Copyright 2002-2014 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <set>
  15. #include <boost/config.hpp>
  16. #include <boost/serialization/access.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/detail/stack_constructor.hpp>
  19. #include <boost/serialization/collection_size_type.hpp>
  20. #include <boost/serialization/item_version_type.hpp>
  21. #include <boost/serialization/library_version_type.hpp>
  22. #include <boost/serialization/collections_save_imp.hpp>
  23. #include <boost/serialization/split_free.hpp>
  24. #include <boost/move/utility_core.hpp>
  25. namespace boost {
  26. namespace serialization {
  27. template<class Archive, class Container>
  28. inline void load_set_collection(Archive & ar, Container &s)
  29. {
  30. s.clear();
  31. const boost::serialization::library_version_type library_version(
  32. ar.get_library_version()
  33. );
  34. // retrieve number of elements
  35. item_version_type item_version(0);
  36. collection_size_type count;
  37. ar >> BOOST_SERIALIZATION_NVP(count);
  38. if(boost::serialization::library_version_type(3) < library_version){
  39. ar >> BOOST_SERIALIZATION_NVP(item_version);
  40. }
  41. typename Container::iterator hint;
  42. hint = s.begin();
  43. while(count-- > 0){
  44. typedef typename Container::value_type type;
  45. detail::stack_construct<Archive, type> t(ar, item_version);
  46. // borland fails silently w/o full namespace
  47. ar >> boost::serialization::make_nvp("item", t.reference());
  48. typename Container::iterator result =
  49. s.insert(hint, boost::move(t.reference()));
  50. const type * new_address = & (* result);
  51. ar.reset_object_address(new_address, & t.reference());
  52. hint = result;
  53. }
  54. }
  55. template<class Archive, class Key, class Compare, class Allocator >
  56. inline void save(
  57. Archive & ar,
  58. const std::set<Key, Compare, Allocator> &t,
  59. const unsigned int /* file_version */
  60. ){
  61. boost::serialization::stl::save_collection<
  62. Archive, std::set<Key, Compare, Allocator>
  63. >(ar, t);
  64. }
  65. template<class Archive, class Key, class Compare, class Allocator >
  66. inline void load(
  67. Archive & ar,
  68. std::set<Key, Compare, Allocator> &t,
  69. const unsigned int /* file_version */
  70. ){
  71. load_set_collection(ar, t);
  72. }
  73. // split non-intrusive serialization function member into separate
  74. // non intrusive save/load member functions
  75. template<class Archive, class Key, class Compare, class Allocator >
  76. inline void serialize(
  77. Archive & ar,
  78. std::set<Key, Compare, Allocator> & t,
  79. const unsigned int file_version
  80. ){
  81. boost::serialization::split_free(ar, t, file_version);
  82. }
  83. // multiset
  84. template<class Archive, class Key, class Compare, class Allocator >
  85. inline void save(
  86. Archive & ar,
  87. const std::multiset<Key, Compare, Allocator> &t,
  88. const unsigned int /* file_version */
  89. ){
  90. boost::serialization::stl::save_collection<
  91. Archive,
  92. std::multiset<Key, Compare, Allocator>
  93. >(ar, t);
  94. }
  95. template<class Archive, class Key, class Compare, class Allocator >
  96. inline void load(
  97. Archive & ar,
  98. std::multiset<Key, Compare, Allocator> &t,
  99. const unsigned int /* file_version */
  100. ){
  101. load_set_collection(ar, t);
  102. }
  103. // split non-intrusive serialization function member into separate
  104. // non intrusive save/load member functions
  105. template<class Archive, class Key, class Compare, class Allocator >
  106. inline void serialize(
  107. Archive & ar,
  108. std::multiset<Key, Compare, Allocator> & t,
  109. const unsigned int file_version
  110. ){
  111. boost::serialization::split_free(ar, t, file_version);
  112. }
  113. } // namespace serialization
  114. } // namespace boost
  115. #include <boost/serialization/collection_traits.hpp>
  116. BOOST_SERIALIZATION_COLLECTION_TRAITS(std::set)
  117. BOOST_SERIALIZATION_COLLECTION_TRAITS(std::multiset)
  118. #endif // BOOST_SERIALIZATION_SET_HPP