]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/serialization/src/extended_type_info.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / serialization / src / extended_type_info.cpp
CommitLineData
7c673cae
FG
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// extended_type_info.cpp: implementation for portable version of type_info
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 <algorithm>
16#include <set>
17#include <utility>
18#include <boost/assert.hpp>
19#include <cstddef> // NULL
20
21#include <cstring>
22#if defined(BOOST_NO_STDC_NAMESPACE)
23namespace std{ using ::strcmp; }
24#endif
25
26#include <boost/config.hpp> // msvc needs this to suppress warning
27
28#include <boost/core/no_exceptions_support.hpp>
29
30// it marks our code with proper attributes as being exported when
31// we're compiling it while marking it import when just the headers
32// is being included.
33#define BOOST_SERIALIZATION_SOURCE
34#include <boost/serialization/config.hpp>
35#include <boost/serialization/singleton.hpp>
36#include <boost/serialization/force_include.hpp>
37#include <boost/serialization/extended_type_info.hpp>
38
39#ifdef BOOST_MSVC
40# pragma warning(push)
41# pragma warning(disable : 4511 4512)
42#endif
43
44namespace boost {
45namespace serialization {
46namespace detail {
47
48struct key_compare
49{
50 bool
51 operator()(
52 const extended_type_info * lhs,
53 const extended_type_info * rhs
54 ) const {
55 // performance shortcut
56 if(lhs == rhs)
57 return false;
58 const char * l = lhs->get_key();
59 BOOST_ASSERT(NULL != l);
60 const char * r = rhs->get_key();
61 BOOST_ASSERT(NULL != r);
62 // performance shortcut
63 // shortcut to exploit string pooling
64 if(l == r)
65 return false;
66 // for exported types, use the string key so that
67 // multiple instances in different translation units
68 // can be matched up
69 return std::strcmp(l, r) < 0;
70 }
71};
72
73typedef std::multiset<const extended_type_info *, key_compare> ktmap;
74
75#ifdef BOOST_MSVC
76# pragma warning(push)
77# pragma warning(disable : 4511 4512)
78#endif
79
80class extended_type_info_arg : public extended_type_info
81{
82 virtual bool
83 is_less_than(const extended_type_info & /*rhs*/) const {
84 BOOST_ASSERT(false);
85 return false;
86 };
87 virtual bool
88 is_equal(const extended_type_info & /*rhs*/) const {
89 BOOST_ASSERT(false);
90 return false;
91 };
92 virtual const char * get_debug_info() const {
93 return get_key();
94 }
95 virtual void * construct(unsigned int /*count*/, ...) const{
96 BOOST_ASSERT(false);
97 return NULL;
98 }
99 virtual void destroy(void const * const /*p*/) const {
100 BOOST_ASSERT(false);
101 }
102public:
103 extended_type_info_arg(const char * key) :
104 extended_type_info(0, key)
105 {}
106
107 ~extended_type_info_arg(){
108 }
109};
110
111#ifdef BOOST_MSVC
112# pragma warning(pop)
113#endif
114
115} // namespace detail
116
117BOOST_SERIALIZATION_DECL void
118extended_type_info::key_register() const{
119 if(NULL == get_key())
120 return;
121 singleton<detail::ktmap>::get_mutable_instance().insert(this);
122}
123
124BOOST_SERIALIZATION_DECL void
125extended_type_info::key_unregister() const{
126 if(NULL == get_key())
127 return;
b32b8144 128 BOOST_ASSERT(! singleton<detail::ktmap>::is_destroyed());
7c673cae
FG
129 if(! singleton<detail::ktmap>::is_destroyed()){
130 detail::ktmap & x = singleton<detail::ktmap>::get_mutable_instance();
131 detail::ktmap::iterator start = x.lower_bound(this);
132 detail::ktmap::iterator end = x.upper_bound(this);
133 // remove entry in map which corresponds to this type
134 for(;start != end; ++start){
135 if(this == *start){
136 x.erase(start);
137 break;
138 }
139 }
140 }
141}
142
143BOOST_SERIALIZATION_DECL const extended_type_info *
144extended_type_info::find(const char *key) {
145 BOOST_ASSERT(NULL != key);
146 const detail::ktmap & k = singleton<detail::ktmap>::get_const_instance();
147 const detail::extended_type_info_arg eti_key(key);
148 const detail::ktmap::const_iterator it = k.find(& eti_key);
149 if(k.end() == it)
150 return NULL;
151 return *(it);
152}
153
154BOOST_SERIALIZATION_DECL
155extended_type_info::extended_type_info(
156 const unsigned int type_info_key,
157 const char * key
158) :
159 m_type_info_key(type_info_key),
160 m_key(key)
161{
162}
163
164BOOST_SERIALIZATION_DECL
165extended_type_info::~extended_type_info(){
166}
167
168BOOST_SERIALIZATION_DECL bool
169extended_type_info::operator<(const extended_type_info &rhs) const {
170 // short cut for a common cases
171 if(this == & rhs)
172 return false;
173 if(m_type_info_key == rhs.m_type_info_key){
174 return is_less_than(rhs);
175 }
176 if(m_type_info_key < rhs.m_type_info_key)
177 return true;
178 return false;
179}
180
181BOOST_SERIALIZATION_DECL bool
182extended_type_info::operator==(const extended_type_info &rhs) const {
183 // short cut for a common cases
184 if(this == & rhs)
185 return true;
186 if(m_type_info_key != rhs.m_type_info_key){
187 return false;
188 }
189 return is_equal(rhs);
190}
191
192} // namespace serialization
193} // namespace boost