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