basic_serializer_map.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // serializer_map.cpp:
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org for updates, documentation, and revision history.
  8. #if (defined _MSC_VER) && (_MSC_VER == 1200)
  9. # pragma warning (disable : 4786) // too long name, harmless warning
  10. #endif
  11. #include <set>
  12. #include <utility>
  13. #define BOOST_ARCHIVE_SOURCE
  14. // include this to prevent linker errors when the
  15. // same modules are marked export and import.
  16. #define BOOST_SERIALIZATION_SOURCE
  17. #include <boost/serialization/config.hpp>
  18. #include <boost/serialization/throw_exception.hpp>
  19. #include <boost/archive/archive_exception.hpp>
  20. #include <boost/archive/detail/basic_serializer.hpp>
  21. #include <boost/archive/detail/basic_serializer_map.hpp>
  22. namespace boost {
  23. namespace serialization {
  24. class extended_type_info;
  25. }
  26. namespace archive {
  27. namespace detail {
  28. bool
  29. basic_serializer_map::type_info_pointer_compare::operator()(
  30. const basic_serializer * lhs, const basic_serializer * rhs
  31. ) const {
  32. return *lhs < *rhs;
  33. }
  34. BOOST_ARCHIVE_DECL bool
  35. basic_serializer_map::insert(const basic_serializer * bs){
  36. // attempt to insert serializer into it's map
  37. // the following is commented out - rather than being just
  38. // deleted as a reminder not to try this.
  39. // const std::pair<map_type::iterator, bool> result =
  40. m_map.insert(bs);
  41. // At first it seemed like a good idea. It enforced the
  42. // idea that a type be exported from at most one code module
  43. // (DLL or mainline). This would enforce a "one definition rule"
  44. // across code modules. This seems a good idea to me.
  45. // But it seems that it's just too hard for many users to implement.
  46. // Ideally, I would like to make this exception a warning -
  47. // but there isn't anyway to do that.
  48. // if this fails, it's because it's been instantiated
  49. // in multiple modules - DLLS - a recipe for problems.
  50. // So trap this here
  51. // if(!result.second){
  52. // boost::serialization::throw_exception(
  53. // archive_exception(
  54. // archive_exception::multiple_code_instantiation,
  55. // bs->get_debug_info()
  56. // )
  57. // );
  58. // }
  59. return true;
  60. }
  61. BOOST_ARCHIVE_DECL void
  62. basic_serializer_map::erase(const basic_serializer * bs){
  63. map_type::iterator it = m_map.begin();
  64. map_type::iterator it_end = m_map.end();
  65. while(it != it_end){
  66. // note item 9 from Effective STL !!! it++
  67. if(*it == bs)
  68. m_map.erase(it++);
  69. else
  70. it++;
  71. }
  72. // note: we can't do this since some of the eti records
  73. // we're pointing to might be expired and the comparison
  74. // won't work. Leave this as a reminder not to "optimize" this.
  75. //it = m_map.find(bs);
  76. //assert(it != m_map.end());
  77. //if(*it == bs)
  78. // m_map.erase(it);
  79. }
  80. BOOST_ARCHIVE_DECL const basic_serializer *
  81. basic_serializer_map::find(
  82. const boost::serialization::extended_type_info & eti
  83. ) const {
  84. const basic_serializer_arg bs(eti);
  85. map_type::const_iterator it;
  86. it = m_map.find(& bs);
  87. if(it == m_map.end()){
  88. BOOST_ASSERT(false);
  89. return 0;
  90. }
  91. return *it;
  92. }
  93. } // namespace detail
  94. } // namespace archive
  95. } // namespace boost