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
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.
23 #include <boost/assert.hpp>
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/config.hpp>
32 #include <boost/serialization/singleton.hpp>
33 #include <boost/serialization/extended_type_info.hpp>
34 #include <boost/serialization/factory.hpp>
36 // hijack serialization access
37 #include <boost/serialization/access.hpp>
39 #include <boost/mpl/if.hpp>
41 #include <boost/config/abi_prefix.hpp> // must be the last header
44 # pragma warning(push)
45 # pragma warning(disable : 4251 4231 4660 4275 4511 4512)
49 namespace serialization {
50 namespace typeid_system {
52 class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info_typeid_0 :
53 public extended_type_info
55 virtual const char * get_debug_info() const {
56 if(static_cast<const std::type_info *>(0) == m_ti)
57 return static_cast<const char *>(0);
61 const std::type_info * m_ti;
62 extended_type_info_typeid_0(const char * key);
63 ~extended_type_info_typeid_0();
64 void type_register(const std::type_info & ti);
65 void type_unregister();
66 const extended_type_info *
67 get_extended_type_info(const std::type_info & ti) const;
70 is_less_than(const extended_type_info &rhs) const;
72 is_equal(const extended_type_info &rhs) const;
73 const std::type_info & get_typeid() const {
81 class extended_type_info_typeid :
82 public typeid_system::extended_type_info_typeid_0,
83 public singleton<extended_type_info_typeid< T > >
86 extended_type_info_typeid() :
87 typeid_system::extended_type_info_typeid_0(get_key())
89 type_register(typeid(T));
92 ~extended_type_info_typeid(){
96 // get the eti record for the true type of this record
97 // relying upon standard type info implemenation (rtti)
98 const extended_type_info *
99 get_derived_extended_type_info(const T & t) const {
100 // note: this implementation - based on usage of typeid (rtti)
101 // only does something if the class has at least one virtual function.
102 BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
104 typeid_system::extended_type_info_typeid_0::get_extended_type_info(
108 const char * get_key() const {
109 return boost::serialization::guid< T >();
111 virtual void * construct(unsigned int count, ...) const{
112 // count up the arguments
117 return factory<typename boost::remove_const< T >::type, 0>(ap);
119 return factory<typename boost::remove_const< T >::type, 1>(ap);
121 return factory<typename boost::remove_const< T >::type, 2>(ap);
123 return factory<typename boost::remove_const< T >::type, 3>(ap);
125 return factory<typename boost::remove_const< T >::type, 4>(ap);
127 BOOST_ASSERT(false); // too many arguments
128 // throw exception here?
132 virtual void destroy(void const * const p) const {
133 boost::serialization::access::destroy(
134 static_cast<T const *>(p)
136 //delete static_cast<T const * const>(p);
140 } // namespace serialization
143 ///////////////////////////////////////////////////////////////////////////////
144 // If no other implementation has been designated as default,
145 // use this one. To use this implementation as the default, specify it
146 // before any of the other headers.
147 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
148 #define BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
150 namespace serialization {
152 struct extended_type_info_impl {
154 boost::serialization::extended_type_info_typeid< T > type;
156 } // namespace serialization
163 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
165 #endif // BOOST_SERIALIZATION_EXTENDED_TYPE_INFO_TYPEID_HPP