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.
14 #include <boost/assert.hpp>
16 #include <cstddef> // NULL
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 BOOST_ASSERT(! singleton
<tkmap
>::is_destroyed());
99 if(! singleton
<tkmap
>::is_destroyed()){
100 tkmap
& x
= singleton
<tkmap
>::get_mutable_instance();
102 // remove all entries in map which corresponds to this type
103 // make sure that we don't use any invalidated iterators
105 const tkmap::iterator
& it
= x
.find(this);
116 # pragma warning(push)
117 # pragma warning(disable : 4511 4512)
120 // this derivation is used for creating search arguments
121 class extended_type_info_typeid_arg
:
122 public extended_type_info_typeid_0
124 virtual void * construct(unsigned int /*count*/, ...) const{
128 virtual void destroy(void const * const /*p*/) const {
132 extended_type_info_typeid_arg(const std::type_info
& ti
) :
133 extended_type_info_typeid_0(NULL
)
135 // note absense of self register and key as this is used only as
136 // search argument given a type_info reference and is not to
137 // be added to the map.
140 ~extended_type_info_typeid_arg(){
146 # pragma warning(pop)
149 BOOST_SERIALIZATION_DECL
const extended_type_info
*
150 extended_type_info_typeid_0::get_extended_type_info(
151 const std::type_info
& ti
153 typeid_system::extended_type_info_typeid_arg
etia(ti
);
154 const tkmap
& t
= singleton
<tkmap
>::get_const_instance();
155 const tkmap::const_iterator it
= t
.find(& etia
);
161 } // namespace detail
162 } // namespace serialization