1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // extended_type_info_typeid.cpp: specific implementation of type info
3 // that is based on typeid
5 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
6 // Use, modification and distribution is subject to the Boost Software
7 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org for updates, documentation, and revision history.
13 #include <cstddef> // NULL
17 #include <boost/assert.hpp>
18 #include <boost/core/no_exceptions_support.hpp>
20 // it marks our code with proper attributes as being exported when
21 // we're compiling it while marking it import when just the headers
23 #define BOOST_SERIALIZATION_SOURCE
24 #include <boost/serialization/config.hpp>
25 #include <boost/serialization/singleton.hpp>
26 #include <boost/serialization/extended_type_info_typeid.hpp>
29 namespace serialization
{
30 namespace typeid_system
{
32 #define EXTENDED_TYPE_INFO_TYPE_KEY 1
38 const extended_type_info_typeid_0
* lhs
,
39 const extended_type_info_typeid_0
* rhs
41 return lhs
->is_less_than(*rhs
);
45 typedef std::multiset
<
46 const extended_type_info_typeid_0
*,
50 BOOST_SERIALIZATION_DECL
bool
51 extended_type_info_typeid_0::is_less_than(
52 const boost::serialization::extended_type_info
& rhs
54 // shortcut for common case
57 return 0 != m_ti
->before(
58 *(static_cast<const extended_type_info_typeid_0
&>(rhs
).m_ti
)
62 BOOST_SERIALIZATION_DECL
bool
63 extended_type_info_typeid_0::is_equal(
64 const boost::serialization::extended_type_info
& rhs
67 // note: std::type_info == operator returns an int !!!
68 // the following permits conversion to bool without a warning.
71 != *(static_cast<const extended_type_info_typeid_0
&>(rhs
).m_ti
)
76 BOOST_SERIALIZATION_DECL
77 extended_type_info_typeid_0::extended_type_info_typeid_0(
80 extended_type_info(EXTENDED_TYPE_INFO_TYPE_KEY
, key
),
84 BOOST_SERIALIZATION_DECL
85 extended_type_info_typeid_0::~extended_type_info_typeid_0()
88 BOOST_SERIALIZATION_DECL
void
89 extended_type_info_typeid_0::type_register(const std::type_info
& ti
){
91 singleton
<tkmap
>::get_mutable_instance().insert(this);
94 BOOST_SERIALIZATION_DECL
void
95 extended_type_info_typeid_0::type_unregister()
98 // note: previously this conditional was a runtime assertion with
99 // BOOST_ASSERT. We've changed it because we've discovered that at
100 // least one platform is not guaranteed to destroy singletons in
101 // reverse order of distruction.
102 // BOOST_ASSERT(! singleton<tkmap>::is_destroyed());
103 if(! singleton
<tkmap
>::is_destroyed()){
104 tkmap
& x
= singleton
<tkmap
>::get_mutable_instance();
106 // remove all entries in map which corresponds to this type
107 // make sure that we don't use any invalidated iterators
109 const tkmap::iterator
& it
= x
.find(this);
120 # pragma warning(push)
121 # pragma warning(disable : 4511 4512)
124 // this derivation is used for creating search arguments
125 class extended_type_info_typeid_arg
:
126 public extended_type_info_typeid_0
128 void * construct(unsigned int /*count*/, ...) const BOOST_OVERRIDE
{
132 void destroy(void const * const /*p*/) const BOOST_OVERRIDE
{
136 extended_type_info_typeid_arg(const std::type_info
& ti
) :
137 extended_type_info_typeid_0(NULL
)
139 // note absence of self register and key as this is used only as
140 // search argument given a type_info reference and is not to
141 // be added to the map.
144 ~extended_type_info_typeid_arg() BOOST_OVERRIDE
{
150 # pragma warning(pop)
153 BOOST_SERIALIZATION_DECL
const extended_type_info
*
154 extended_type_info_typeid_0::get_extended_type_info(
155 const std::type_info
& ti
157 typeid_system::extended_type_info_typeid_arg
etia(ti
);
158 const tkmap
& t
= singleton
<tkmap
>::get_const_instance();
159 const tkmap::const_iterator it
= t
.find(& etia
);
165 } // namespace detail
166 } // namespace serialization