epoc32/include/stdapis/boost/serialization/base_object.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/serialization/base_object.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,172 @@
     1.4 +#ifndef BOOST_SERIALIZATION_BASE_OBJECT_HPP
     1.5 +#define BOOST_SERIALIZATION_BASE_OBJECT_HPP
     1.6 +
     1.7 +// MS compatible compilers support #pragma once
     1.8 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
     1.9 +# pragma once
    1.10 +#endif
    1.11 +
    1.12 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
    1.13 +// base_object.hpp:
    1.14 +
    1.15 +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
    1.16 +// Use, modification and distribution is subject to the Boost Software
    1.17 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.18 +// http://www.boost.org/LICENSE_1_0.txt)
    1.19 +
    1.20 +//  See http://www.boost.org for updates, documentation, and revision history.
    1.21 +
    1.22 +// if no archive headers have been included this is a no op
    1.23 +// this is to permit BOOST_EXPORT etc to be included in a 
    1.24 +// file declaration header
    1.25 +
    1.26 +#include <boost/config.hpp>
    1.27 +#include <boost/detail/workaround.hpp>
    1.28 +
    1.29 +#include <boost/mpl/eval_if.hpp>
    1.30 +#include <boost/mpl/int.hpp>
    1.31 +#include <boost/type_traits/is_base_and_derived.hpp>
    1.32 +#include <boost/type_traits/is_pointer.hpp>
    1.33 +#include <boost/type_traits/is_const.hpp>
    1.34 +
    1.35 +#include <boost/static_assert.hpp>
    1.36 +#include <boost/serialization/type_info_implementation.hpp>
    1.37 +#include <boost/serialization/force_include.hpp>
    1.38 +#include <boost/serialization/void_cast_fwd.hpp>
    1.39 +
    1.40 +namespace boost {
    1.41 +namespace serialization {
    1.42 +
    1.43 +namespace detail {
    1.44 +    // metrowerks CodeWarrior
    1.45 +    #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) 
    1.46 +        // only register void casts if the types are polymorphic
    1.47 +        template<class Base, class Derived>
    1.48 +        struct base_register{
    1.49 +            struct nothing {
    1.50 +                static const void_cast_detail::void_caster & invoke(){
    1.51 +                    return static_cast<const void_cast_detail::void_caster &>(
    1.52 +                        * static_cast<const void_cast_detail::void_caster *>(NULL)
    1.53 +                    );
    1.54 +                }
    1.55 +            };
    1.56 +
    1.57 +            // hold a reference to the void_cast_register and void_caster in the hope of 
    1.58 +            // ensuring code instantiation for some compilers with over-zealous link time 
    1.59 +            // optimiser. The compiler that demanded this was CW
    1.60 +            struct reg{
    1.61 +                typedef const void_cast_detail::void_caster & (* t_vcr)(
    1.62 +                    const Derived *,
    1.63 +                    const Base *
    1.64 +                );
    1.65 +                t_vcr m_vcr;
    1.66 +                static const void_cast_detail::void_caster & invoke(){
    1.67 +                    return  void_cast_register<const Derived, const Base>(
    1.68 +                        static_cast<const Derived *>(NULL),
    1.69 +                        static_cast<const Base *>(NULL)
    1.70 +                    );
    1.71 +                }
    1.72 +                reg() :
    1.73 +                    m_vcr(static_cast<t_vcr>(void_cast_register))
    1.74 +                {
    1.75 +                }
    1.76 +            } m_reg;
    1.77 +
    1.78 +            static const void_cast_detail::void_caster & invoke(){
    1.79 +                typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<
    1.80 +                    BOOST_DEDUCED_TYPENAME type_info_implementation<Base>::type::is_polymorphic,
    1.81 +                    mpl::identity<reg>,
    1.82 +                    mpl::identity<nothing>
    1.83 +                >::type typex;
    1.84 +                return typex::invoke();
    1.85 +            }
    1.86 +
    1.87 +            const void_cast_detail::void_caster & m_vc;
    1.88 +            Derived & m_d;
    1.89 +
    1.90 +            base_register(Derived & d) :
    1.91 +                m_vc(invoke()),
    1.92 +                m_d(d)
    1.93 +            {}
    1.94 +            Base & get_base() const {
    1.95 +                return m_d;
    1.96 +            }
    1.97 +        };
    1.98 +    #else
    1.99 +        // only register void casts if the types are polymorphic
   1.100 +        template<class Base, class Derived>
   1.101 +        struct base_register{
   1.102 +            struct nothing {
   1.103 +                static void invoke(){}
   1.104 +            };
   1.105 +            struct reg{
   1.106 +                static void invoke(){
   1.107 +                    void_cast_register<const Derived, const Base>(
   1.108 +                        static_cast<const Derived *>(NULL),
   1.109 +                        static_cast<const Base *>(NULL)
   1.110 +                    );
   1.111 +                }
   1.112 +            };
   1.113 +            static void invoke(){
   1.114 +                typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<
   1.115 +                    BOOST_DEDUCED_TYPENAME type_info_implementation<Base>::type::is_polymorphic,
   1.116 +                    mpl::identity<reg>,
   1.117 +                    mpl::identity<nothing>
   1.118 +                >::type typex;
   1.119 +                typex::invoke();
   1.120 +            }
   1.121 +        };
   1.122 +    #endif
   1.123 +    // get the base type for a given derived type
   1.124 +    // preserving the const-ness
   1.125 +    template<class B, class D>
   1.126 +    struct base_cast
   1.127 +    {
   1.128 +        typedef BOOST_DEDUCED_TYPENAME
   1.129 +            mpl::if_<
   1.130 +                is_const<D>,
   1.131 +                const B,
   1.132 +                B
   1.133 +        >::type type;
   1.134 +        BOOST_STATIC_ASSERT(is_const<type>::value == is_const<D>::value);
   1.135 +    };
   1.136 +} // namespace detail
   1.137 +
   1.138 +// metrowerks CodeWarrior
   1.139 +#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) 
   1.140 +template<class Base, class Derived>
   1.141 +BOOST_DEDUCED_TYPENAME detail::base_cast<Base, Derived>::type & 
   1.142 +base_object(Derived &d)
   1.143 +{
   1.144 +    BOOST_STATIC_ASSERT(( is_base_and_derived<Base,Derived>::value));
   1.145 +    BOOST_STATIC_ASSERT(! is_pointer<Derived>::value);
   1.146 +    typedef BOOST_DEDUCED_TYPENAME detail::base_cast<Base, Derived>::type type;
   1.147 +    return detail::base_register<type, Derived>(d).get_base();
   1.148 +}
   1.149 +// BORLAND
   1.150 +#elif BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x560))
   1.151 +template<class Base, class Derived>
   1.152 +const Base & 
   1.153 +base_object(const Derived & d)
   1.154 +{
   1.155 +    BOOST_STATIC_ASSERT(! is_pointer<Derived>::value);
   1.156 +    detail::base_register<Base, Derived>::invoke();
   1.157 +    return static_cast<const Base &>(d);
   1.158 +}
   1.159 +#else
   1.160 +template<class Base, class Derived>
   1.161 +BOOST_DEDUCED_TYPENAME detail::base_cast<Base, Derived>::type & 
   1.162 +base_object(Derived &d)
   1.163 +{
   1.164 +    BOOST_STATIC_ASSERT(( is_base_and_derived<Base,Derived>::value));
   1.165 +    BOOST_STATIC_ASSERT(! is_pointer<Derived>::value);
   1.166 +    typedef BOOST_DEDUCED_TYPENAME detail::base_cast<Base, Derived>::type type;
   1.167 +    detail::base_register<type, Derived>::invoke();
   1.168 +    return static_cast<type &>(d);
   1.169 +}
   1.170 +#endif
   1.171 +
   1.172 +} // namespace serialization
   1.173 +} // namespace boost
   1.174 +
   1.175 +#endif // BOOST_SERIALIZATION_BASE_OBJECT_HPP