#ifndef BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP #define BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // MS compatible compilers support #pragma once #if defined(_MSC_VER) # pragma once #endif // extended_type_info_no_rtti.hpp: implementation for version that depends // on runtime typing (rtti - typeid) but uses a user specified string // as the portable class identifier. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org for updates, documentation, and revision history. #include #include #include #include #include #include #include #include #include #include #include #include #include // hijack serialization access #include #include // must be the last header #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable : 4251 4231 4660 4275 4511 4512) #endif namespace boost { namespace serialization { /////////////////////////////////////////////////////////////////////// // define a special type_info that doesn't depend on rtti which is not // available in all situations. namespace no_rtti_system { // common base class to share type_info_key. This is used to // identify the method used to keep track of the extended type class BOOST_SYMBOL_VISIBLE extended_type_info_no_rtti_0 : public extended_type_info { protected: BOOST_SERIALIZATION_DECL extended_type_info_no_rtti_0(const char * key); BOOST_SERIALIZATION_DECL ~extended_type_info_no_rtti_0() BOOST_OVERRIDE; public: BOOST_SERIALIZATION_DECL bool is_less_than(const boost::serialization::extended_type_info &rhs) const BOOST_OVERRIDE; BOOST_SERIALIZATION_DECL bool is_equal(const boost::serialization::extended_type_info &rhs) const BOOST_OVERRIDE; }; } // no_rtti_system template class extended_type_info_no_rtti : public no_rtti_system::extended_type_info_no_rtti_0, public singleton > { template struct action { struct defined { static const char * invoke(){ return guid< T >(); } }; struct undefined { // if your program traps here - you failed to // export a guid for this type. the no_rtti // system requires export for types serialized // as pointers. BOOST_STATIC_ASSERT(0 == sizeof(T)); static const char * invoke(); }; static const char * invoke(){ typedef typename boost::mpl::if_c< tf, defined, undefined >::type type; return type::invoke(); } }; public: extended_type_info_no_rtti() : no_rtti_system::extended_type_info_no_rtti_0( action::value >::invoke()) { key_register(); } ~extended_type_info_no_rtti() BOOST_OVERRIDE { key_unregister(); } const extended_type_info * get_derived_extended_type_info(const T & t) const { // find the type that corresponds to the most derived type. // this implementation doesn't depend on typeid() but assumes // that the specified type has a function of the following signature. // A common implementation of such a function is to define as a virtual // function. So if the type is not a polymorphic type it's likely an error BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value); const char * derived_key = t.get_key(); BOOST_ASSERT(NULL != derived_key); return boost::serialization::extended_type_info::find(derived_key); } const char * get_key() const{ return action::value >::invoke(); } const char * get_debug_info() const BOOST_OVERRIDE { return action::value >::invoke(); } void * construct(unsigned int count, ...) const BOOST_OVERRIDE { // count up the arguments void * r = NULL; std::va_list ap; va_start(ap, count); switch(count){ case 0: r = factory::type, 0>(ap); break; case 1: r = factory::type, 1>(ap); break; case 2: r = factory::type, 2>(ap); break; case 3: r = factory::type, 3>(ap); break; case 4: r = factory::type, 4>(ap); break; default: BOOST_ASSERT(false); // too many arguments // throw exception here? } va_end(ap); return r; } void destroy(void const * const p) const BOOST_OVERRIDE { boost::serialization::access::destroy( static_cast(p) ); //delete static_cast(p) ; } }; } // namespace serialization } // namespace boost /////////////////////////////////////////////////////////////////////////////// // If no other implementation has been designated as default, // use this one. To use this implementation as the default, specify it // before any of the other headers. #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO #define BOOST_SERIALIZATION_DEFAULT_TYPE_INFO namespace boost { namespace serialization { template struct extended_type_info_impl { typedef typename boost::serialization::extended_type_info_no_rtti< T > type; }; } // namespace serialization } // namespace boost #endif #ifdef BOOST_MSVC # pragma warning(pop) #endif #include // pops abi_suffix.hpp pragmas #endif // BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP