]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/src/extended_type_info.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / src / extended_type_info.cpp
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)
23 namespace 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
44 namespace boost {
45 namespace serialization {
46 namespace detail {
47
48 struct 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
73 typedef 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
80 class 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 }
102 public:
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
117 BOOST_SERIALIZATION_DECL void
118 extended_type_info::key_register() const{
119 if(NULL == get_key())
120 return;
121 singleton<detail::ktmap>::get_mutable_instance().insert(this);
122 }
123
124 BOOST_SERIALIZATION_DECL void
125 extended_type_info::key_unregister() const{
126 if(NULL == get_key())
127 return;
128 if(! singleton<detail::ktmap>::is_destroyed()){
129 detail::ktmap & x = singleton<detail::ktmap>::get_mutable_instance();
130 detail::ktmap::iterator start = x.lower_bound(this);
131 detail::ktmap::iterator end = x.upper_bound(this);
132 // remove entry in map which corresponds to this type
133 for(;start != end; ++start){
134 if(this == *start){
135 x.erase(start);
136 break;
137 }
138 }
139 }
140 }
141
142 BOOST_SERIALIZATION_DECL const extended_type_info *
143 extended_type_info::find(const char *key) {
144 BOOST_ASSERT(NULL != key);
145 const detail::ktmap & k = singleton<detail::ktmap>::get_const_instance();
146 const detail::extended_type_info_arg eti_key(key);
147 const detail::ktmap::const_iterator it = k.find(& eti_key);
148 if(k.end() == it)
149 return NULL;
150 return *(it);
151 }
152
153 BOOST_SERIALIZATION_DECL
154 extended_type_info::extended_type_info(
155 const unsigned int type_info_key,
156 const char * key
157 ) :
158 m_type_info_key(type_info_key),
159 m_key(key)
160 {
161 }
162
163 BOOST_SERIALIZATION_DECL
164 extended_type_info::~extended_type_info(){
165 }
166
167 BOOST_SERIALIZATION_DECL bool
168 extended_type_info::operator<(const extended_type_info &rhs) const {
169 // short cut for a common cases
170 if(this == & rhs)
171 return false;
172 if(m_type_info_key == rhs.m_type_info_key){
173 return is_less_than(rhs);
174 }
175 if(m_type_info_key < rhs.m_type_info_key)
176 return true;
177 return false;
178 }
179
180 BOOST_SERIALIZATION_DECL bool
181 extended_type_info::operator==(const extended_type_info &rhs) const {
182 // short cut for a common cases
183 if(this == & rhs)
184 return true;
185 if(m_type_info_key != rhs.m_type_info_key){
186 return false;
187 }
188 return is_equal(rhs);
189 }
190
191 } // namespace serialization
192 } // namespace boost