fix doc example typo
[boost.git] / boost / serialization / extended_type_info_typeid.hpp
blob3930cb9ca21b26defd8f694523833d400031e7d8
1 #ifndef BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_TYPEID_HPP
2 #define BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_TYPEID_HPP
4 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
5 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
10 // extended_type_info_typeid.hpp: implementation for version that depends
11 // on runtime typing (rtti - typeid) but uses a user specified string
12 // as the portable class identifier.
14 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
15 // Use, modification and distribution is subject to the Boost Software
16 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 // See http://www.boost.org for updates, documentation, and revision history.
21 #include <typeinfo>
22 #include <cstdarg>
23 #include <cassert>
24 #include <boost/config.hpp>
26 #include <boost/static_assert.hpp>
27 #include <boost/serialization/static_warning.hpp>
28 #include <boost/type_traits/is_polymorphic.hpp>
29 #include <boost/type_traits/remove_const.hpp>
31 #include <boost/serialization/singleton.hpp>
32 #include <boost/serialization/extended_type_info.hpp>
33 #include <boost/serialization/factory.hpp>
35 #include <boost/config/abi_prefix.hpp> // must be the last header
36 #ifdef BOOST_MSVC
37 # pragma warning(push)
38 # pragma warning(disable : 4251 4231 4660 4275)
39 #endif
41 namespace boost {
42 namespace serialization {
43 namespace detail {
45 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info_typeid_0 :
46 public extended_type_info
48 protected:
49 const std::type_info * m_ti;
50 extended_type_info_typeid_0();
51 ~extended_type_info_typeid_0();
52 void type_register(const std::type_info & ti);
53 void type_unregister();
54 const extended_type_info *
55 get_extended_type_info(const std::type_info & ti) const;
56 public:
57 virtual bool
58 is_less_than(const extended_type_info &rhs) const;
59 virtual bool
60 is_equal(const extended_type_info &rhs) const;
61 const std::type_info & get_typeid() const {
62 return *m_ti;
66 } // namespace detail
68 template<class T>
69 class extended_type_info_typeid :
70 public detail::extended_type_info_typeid_0,
71 public singleton<extended_type_info_typeid<T> >
73 public:
74 extended_type_info_typeid() :
75 detail::extended_type_info_typeid_0()
77 type_register(typeid(T));
79 ~extended_type_info_typeid(){
80 type_unregister();
82 // get the eti record for the true type of this record
83 // relying upon standard type info implemenation (rtti)
84 const extended_type_info *
85 get_derived_extended_type_info(const T & t) const {
86 // note: this implementation - based on usage of typeid (rtti)
87 // only does something if the class has at least one virtual function.
88 BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
89 return
90 detail::extended_type_info_typeid_0::get_extended_type_info(
91 typeid(t)
94 void * construct(unsigned int count, ...) const{
95 // count up the arguments
96 std::va_list ap;
97 va_start(ap, count);
98 switch(count){
99 case 0:
100 return factory<boost::remove_const<T>, 0>(ap);
101 case 1:
102 return factory<boost::remove_const<T>, 1>(ap);
103 case 2:
104 return factory<boost::remove_const<T>, 2>(ap);
105 case 3:
106 return factory<boost::remove_const<T>, 3>(ap);
107 case 4:
108 return factory<boost::remove_const<T>, 4>(ap);
109 default:
110 assert(false); // too many arguments
111 // throw exception here?
112 return NULL;
115 void destroy(void const * const /* p */) const {
116 // the only current usage of extended type info is in the
117 // serialization library. The statement below requires
118 // that destructor of type T be public and this creates
119 // a problem for some users. So, for now, comment this
120 // out
121 //delete static_cast<T const *>(p);
122 // and trap any attempt to invoke this function
123 assert(false);
127 } // namespace serialization
128 } // namespace boost
130 ///////////////////////////////////////////////////////////////////////////////
131 // If no other implementation has been designated as default,
132 // use this one. To use this implementation as the default, specify it
133 // before any of the other headers.
134 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
135 #define BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
136 namespace boost {
137 namespace serialization {
138 template<class T>
139 struct extended_type_info_impl {
140 typedef BOOST_DEDUCED_TYPENAME
141 boost::serialization::extended_type_info_typeid<T> type;
143 } // namespace serialization
144 } // namespace boost
145 #endif
147 #ifdef BOOST_MSVC
148 #pragma warning(pop)
149 #endif
150 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
152 #endif // BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_TYPEID_HPP