|
1 #ifndef BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP |
|
2 #define BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP |
|
3 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|
4 // MS compatible compilers support #pragma once |
|
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
|
6 # pragma once |
|
7 #endif |
|
8 |
|
9 // extended_type_info_no_rtti.hpp: implementation for version that depends |
|
10 // on runtime typing (rtti - typeid) but uses a user specified string |
|
11 // as the portable class identifier. |
|
12 |
|
13 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
|
14 // Use, modification and distribution is subject to the Boost Software |
|
15 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|
16 // http://www.boost.org/LICENSE_1_0.txt) |
|
17 |
|
18 // See http://www.boost.org for updates, documentation, and revision history. |
|
19 #include <cassert> |
|
20 #include <boost/config.hpp> |
|
21 #include <boost/static_assert.hpp> |
|
22 #include <boost/type_traits/is_const.hpp> |
|
23 |
|
24 #include <boost/serialization/extended_type_info.hpp> |
|
25 #include <boost/mpl/bool.hpp> |
|
26 |
|
27 #include <boost/config/abi_prefix.hpp> // must be the last header |
|
28 #ifdef BOOST_MSVC |
|
29 # pragma warning(push) |
|
30 # pragma warning(disable : 4251 4231 4660 4275) |
|
31 #endif |
|
32 |
|
33 namespace boost { |
|
34 namespace serialization { |
|
35 namespace detail { |
|
36 /////////////////////////////////////////////////////////////////////// |
|
37 // define a special type_info that doesn't depend on rtti which is not |
|
38 // available in all situations. |
|
39 |
|
40 // common base class to share type_info_key. This is used to |
|
41 // identify the method used to keep track of the extended type |
|
42 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info_no_rtti_0 : |
|
43 public extended_type_info |
|
44 { |
|
45 virtual bool |
|
46 less_than(const boost::serialization::extended_type_info &rhs) const ; |
|
47 protected: |
|
48 extended_type_info_no_rtti_0(); |
|
49 // account for bogus gcc warning |
|
50 #if defined(__GNUC__) |
|
51 virtual |
|
52 #endif |
|
53 ~extended_type_info_no_rtti_0(); |
|
54 public: |
|
55 struct is_polymorphic |
|
56 { |
|
57 typedef boost::mpl::bool_<true> type; |
|
58 BOOST_STATIC_CONSTANT(bool, value = is_polymorphic::type::value); |
|
59 }; |
|
60 }; |
|
61 |
|
62 template<class T> |
|
63 class extended_type_info_no_rtti_1 : |
|
64 public extended_type_info_no_rtti_0 |
|
65 { |
|
66 protected: |
|
67 extended_type_info_no_rtti_1(){} |
|
68 public: |
|
69 // note borland complains at making this destructor protected |
|
70 ~extended_type_info_no_rtti_1(){}; |
|
71 static const boost::serialization::extended_type_info * |
|
72 get_derived_extended_type_info(const T & t){ |
|
73 // find the type that corresponds to the most derived type. |
|
74 // this implementation doesn't depend on typeid() but assumes |
|
75 // that the specified type has a function of the following signature. |
|
76 // A common implemention of such a function is to define as a virtual |
|
77 // function. |
|
78 const char * derived_key = t.get_key(); |
|
79 assert(NULL != derived_key); |
|
80 return boost::serialization::extended_type_info::find(derived_key); |
|
81 } |
|
82 static boost::serialization::extended_type_info * |
|
83 get_instance(){ |
|
84 static extended_type_info_no_rtti_1<T> instance; |
|
85 return & instance; |
|
86 } |
|
87 static void |
|
88 export_register(const char * key){ |
|
89 boost::serialization::extended_type_info * eti; |
|
90 eti = get_instance(); |
|
91 eti->key_register(key); // initialize key and add to table |
|
92 eti->self_register(); // add type to type table |
|
93 } |
|
94 }; |
|
95 } // namespace detail |
|
96 |
|
97 template<class T> |
|
98 class extended_type_info_no_rtti : |
|
99 public detail::extended_type_info_no_rtti_1<const T> |
|
100 { |
|
101 // private constructor to inhibit any existence other than the |
|
102 // static one |
|
103 extended_type_info_no_rtti(){} |
|
104 ~extended_type_info_no_rtti(){}; |
|
105 }; |
|
106 |
|
107 } // namespace serialization |
|
108 } // namespace boost |
|
109 |
|
110 /////////////////////////////////////////////////////////////////////////////// |
|
111 // If no other implementation has been designated as default, |
|
112 // use this one. To use this implementation as the default, specify it |
|
113 // before any of the other headers. |
|
114 |
|
115 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO |
|
116 #define BOOST_SERIALIZATION_DEFAULT_TYPE_INFO |
|
117 namespace boost { |
|
118 namespace serialization { |
|
119 template<class T> |
|
120 struct extended_type_info_impl { |
|
121 typedef BOOST_DEDUCED_TYPENAME |
|
122 boost::serialization::extended_type_info_no_rtti<const T> type; |
|
123 }; |
|
124 } // namespace serialization |
|
125 } // namespace boost |
|
126 #endif |
|
127 |
|
128 #ifdef BOOST_MSVC |
|
129 #pragma warning(pop) |
|
130 #endif |
|
131 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas |
|
132 |
|
133 #endif // BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP |