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
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 <boost/assert.hpp>
22 #include <boost/config.hpp>
23 #include <boost/static_assert.hpp>
25 #include <boost/mpl/if.hpp>
26 #include <boost/type_traits/is_polymorphic.hpp>
27 #include <boost/type_traits/remove_const.hpp>
29 #include <boost/serialization/static_warning.hpp>
30 #include <boost/serialization/singleton.hpp>
31 #include <boost/serialization/extended_type_info.hpp>
32 #include <boost/serialization/factory.hpp>
33 #include <boost/serialization/throw_exception.hpp>
35 #include <boost/serialization/config.hpp>
36 // hijack serialization access
37 #include <boost/serialization/access.hpp>
39 #include <boost/config/abi_prefix.hpp> // must be the last header
41 # pragma warning(push)
42 # pragma warning(disable : 4251 4231 4660 4275 4511 4512)
46 namespace serialization {
47 ///////////////////////////////////////////////////////////////////////
48 // define a special type_info that doesn't depend on rtti which is not
49 // available in all situations.
51 namespace no_rtti_system {
53 // common base class to share type_info_key. This is used to
54 // identify the method used to keep track of the extended type
55 class BOOST_SYMBOL_VISIBLE extended_type_info_no_rtti_0 :
56 public extended_type_info
59 BOOST_SERIALIZATION_DECL extended_type_info_no_rtti_0(const char * key);
60 BOOST_SERIALIZATION_DECL ~extended_type_info_no_rtti_0() BOOST_OVERRIDE;
62 BOOST_SERIALIZATION_DECL bool
63 is_less_than(const boost::serialization::extended_type_info &rhs) const BOOST_OVERRIDE;
64 BOOST_SERIALIZATION_DECL bool
65 is_equal(const boost::serialization::extended_type_info &rhs) const BOOST_OVERRIDE;
71 class extended_type_info_no_rtti :
72 public no_rtti_system::extended_type_info_no_rtti_0,
73 public singleton<extended_type_info_no_rtti< T > >
78 static const char * invoke(){
83 // if your program traps here - you failed to
84 // export a guid for this type. the no_rtti
85 // system requires export for types serialized
87 BOOST_STATIC_ASSERT(0 == sizeof(T));
88 static const char * invoke();
90 static const char * invoke(){
92 typename boost::mpl::if_c<
97 return type::invoke();
101 extended_type_info_no_rtti() :
102 no_rtti_system::extended_type_info_no_rtti_0(get_key())
106 ~extended_type_info_no_rtti() BOOST_OVERRIDE {
109 const extended_type_info *
110 get_derived_extended_type_info(const T & t) const {
111 // find the type that corresponds to the most derived type.
112 // this implementation doesn't depend on typeid() but assumes
113 // that the specified type has a function of the following signature.
114 // A common implemention of such a function is to define as a virtual
115 // function. So if the is not a polymorphic type it's likely an error
116 BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
117 const char * derived_key = t.get_key();
118 BOOST_ASSERT(NULL != derived_key);
119 return boost::serialization::extended_type_info::find(derived_key);
121 const char * get_key() const{
122 return action<guid_defined< T >::value >::invoke();
124 const char * get_debug_info() const BOOST_OVERRIDE {
125 return action<guid_defined< T >::value >::invoke();
127 void * construct(unsigned int count, ...) const BOOST_OVERRIDE {
128 // count up the arguments
133 return factory<typename boost::remove_const< T >::type, 0>(ap);
135 return factory<typename boost::remove_const< T >::type, 1>(ap);
137 return factory<typename boost::remove_const< T >::type, 2>(ap);
139 return factory<typename boost::remove_const< T >::type, 3>(ap);
141 return factory<typename boost::remove_const< T >::type, 4>(ap);
143 BOOST_ASSERT(false); // too many arguments
144 // throw exception here?
148 void destroy(void const * const p) const BOOST_OVERRIDE {
149 boost::serialization::access::destroy(
150 static_cast<T const *>(p)
152 //delete static_cast<T const * const>(p) ;
156 } // namespace serialization
159 ///////////////////////////////////////////////////////////////////////////////
160 // If no other implementation has been designated as default,
161 // use this one. To use this implementation as the default, specify it
162 // before any of the other headers.
164 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
165 #define BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
167 namespace serialization {
169 struct extended_type_info_impl {
171 boost::serialization::extended_type_info_no_rtti< T > type;
173 } // namespace serialization
178 # pragma warning(pop)
180 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
182 #endif // BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP