fix doc example typo
[boost.git] / boost / serialization / extended_type_info_no_rtti.hpp
blob6ee2c9b28dab41fc5a77b6b2877964687cd4622e
1 #ifndef BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP
2 #define BOOST_EXTENDED_TYPE_INFO_NO_RTTI_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_no_rtti.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.
20 #include <cassert>
22 #include <boost/config.hpp>
23 #include <boost/static_assert.hpp>
25 #include <boost/serialization/singleton.hpp>
26 #include <boost/serialization/extended_type_info.hpp>
27 #include <boost/serialization/factory.hpp>
29 #include <boost/config/abi_prefix.hpp> // must be the last header
30 #ifdef BOOST_MSVC
31 # pragma warning(push)
32 # pragma warning(disable : 4251 4231 4660 4275)
33 #endif
35 namespace boost {
36 namespace serialization {
37 ///////////////////////////////////////////////////////////////////////
38 // define a special type_info that doesn't depend on rtti which is not
39 // available in all situations.
41 namespace detail {
43 // common base class to share type_info_key. This is used to
44 // identify the method used to keep track of the extended type
45 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info_no_rtti_0 :
46 public extended_type_info
48 protected:
49 extended_type_info_no_rtti_0();
50 ~extended_type_info_no_rtti_0();
51 public:
52 virtual bool
53 is_less_than(const boost::serialization::extended_type_info &rhs) const ;
54 virtual bool
55 is_equal(const boost::serialization::extended_type_info &rhs) const ;
58 } // detail
60 template<class T>
61 class extended_type_info_no_rtti :
62 public detail::extended_type_info_no_rtti_0,
63 public singleton<extended_type_info_no_rtti<T> >
65 public:
66 const extended_type_info *
67 get_derived_extended_type_info(const T & t) const {
68 // find the type that corresponds to the most derived type.
69 // this implementation doesn't depend on typeid() but assumes
70 // that the specified type has a function of the following signature.
71 // A common implemention of such a function is to define as a virtual
72 // function.
73 const char * derived_key = t.get_key();
74 assert(NULL != derived_key);
75 return boost::serialization::extended_type_info::find(derived_key);
77 void * construct(unsigned int count, ...) const{
78 // count up the arguments
79 std::va_list ap;
80 va_start(ap, count);
81 switch(count){
82 case 0:
83 return factory<T, 0>(ap);
84 case 1:
85 return factory<T, 1>(ap);
86 case 2:
87 return factory<T, 2>(ap);
88 case 3:
89 return factory<T, 3>(ap);
90 case 4:
91 return factory<T, 4>(ap);
92 default:
93 assert(false); // too many arguments
94 // throw exception here?
95 return NULL;
98 void destroy(void const * const p) const{
99 delete static_cast<T const *>(p) ;
103 } // namespace serialization
104 } // namespace boost
106 ///////////////////////////////////////////////////////////////////////////////
107 // If no other implementation has been designated as default,
108 // use this one. To use this implementation as the default, specify it
109 // before any of the other headers.
111 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
112 #define BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
113 namespace boost {
114 namespace serialization {
115 template<class T>
116 struct extended_type_info_impl {
117 typedef BOOST_DEDUCED_TYPENAME
118 boost::serialization::extended_type_info_no_rtti<T> type;
120 } // namespace serialization
121 } // namespace boost
122 #endif
124 #ifdef BOOST_MSVC
125 # pragma warning(pop)
126 #endif
127 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
129 #endif // BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP