source: NonGTP/Boost/boost/serialization/extended_type_info_no_rtti.hpp @ 857

Revision 857, 4.3 KB checked in by igarcia, 18 years ago (diff)
Line 
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
33namespace boost {
34namespace serialization {
35namespace 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
42class 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 ;
47protected:
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();
54public:
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
62template<class T>
63class extended_type_info_no_rtti_1 :
64    public extended_type_info_no_rtti_0
65{
66protected:
67    extended_type_info_no_rtti_1(){}
68public:
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
97template<class T>
98class 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(T) \
117    extended_type_info_no_rtti<const T>
118/**/
119#endif
120
121#ifdef BOOST_MSVC
122#pragma warning(pop)
123#endif
124#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
125
126#endif // BOOST_EXTENDED_TYPE_INFO_NO_RTTI_HPP
Note: See TracBrowser for help on using the repository browser.