epoc32/include/stdapis/boost/serialization/void_cast.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/void_cast.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,200 @@
     1.4 +#ifndef  BOOST_SERIALIZATION_VOID_CAST_HPP
     1.5 +#define BOOST_SERIALIZATION_VOID_CAST_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 +// void_cast.hpp:   interface for run-time casting of void pointers.
    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 +// gennadiy.rozental@tfn.com
    1.20 +
    1.21 +//  See http://www.boost.org for updates, documentation, and revision history.
    1.22 +
    1.23 +#include <boost/smart_cast.hpp>
    1.24 +#include <boost/mpl/eval_if.hpp>
    1.25 +#include <boost/mpl/identity.hpp>
    1.26 +
    1.27 +#include <boost/serialization/config.hpp>
    1.28 +#include <boost/serialization/force_include.hpp>
    1.29 +#include <boost/serialization/type_info_implementation.hpp>
    1.30 +
    1.31 +#include <boost/config/abi_prefix.hpp> // must be the last header
    1.32 +
    1.33 +#ifdef BOOST_MSVC
    1.34 +#  pragma warning(push)
    1.35 +#  pragma warning(disable : 4251 4231 4660 4275)
    1.36 +#endif
    1.37 +
    1.38 +namespace boost { 
    1.39 +namespace serialization { 
    1.40 +
    1.41 +class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) extended_type_info;
    1.42 +
    1.43 +// Given a void *, assume that it really points to an instance of one type
    1.44 +// and alter it so that it would point to an instance of a related type.
    1.45 +// Return the altered pointer. If there exists no sequence of casts that
    1.46 +// can transform from_type to to_type, return a NULL.  
    1.47 +
    1.48 +BOOST_SERIALIZATION_DECL(void const *)
    1.49 +void_upcast(
    1.50 +    extended_type_info const & derived_type,  
    1.51 +    extended_type_info const & base_type, 
    1.52 +    void const * const t,
    1.53 +    bool top = true
    1.54 +);
    1.55 +
    1.56 +inline void *
    1.57 +void_upcast(
    1.58 +    extended_type_info const & derived_type_,
    1.59 +    extended_type_info const & base_type_,
    1.60 +    void * const t 
    1.61 +){
    1.62 +    return const_cast<void*>(void_upcast(
    1.63 +        derived_type_, 
    1.64 +        base_type_, 
    1.65 +        const_cast<void const *>(t)
    1.66 +    ));
    1.67 +}
    1.68 +
    1.69 +BOOST_SERIALIZATION_DECL(void const *)
    1.70 +void_downcast(
    1.71 +    extended_type_info const & derived_type,  
    1.72 +    extended_type_info const & base_type, 
    1.73 +    void const * const t,
    1.74 +    bool top = true
    1.75 +);
    1.76 +
    1.77 +inline void *
    1.78 +void_downcast(
    1.79 +    extended_type_info const & derived_type_,
    1.80 +    extended_type_info const & base_type_,
    1.81 +    void * const t 
    1.82 +){
    1.83 +    return const_cast<void*>(void_downcast(
    1.84 +        derived_type_, 
    1.85 +        base_type_, 
    1.86 +        const_cast<void const *>(t)
    1.87 +    ));
    1.88 +}
    1.89 +
    1.90 +namespace void_cast_detail {
    1.91 +
    1.92 +// note: can't be abstract because an instance is used as a search argument
    1.93 +class BOOST_SERIALIZATION_DECL(BOOST_PP_EMPTY()) void_caster
    1.94 +{
    1.95 +    friend struct void_caster_compare ;
    1.96 +    friend 
    1.97 +    BOOST_SERIALIZATION_DECL(void const *)  
    1.98 +    boost::serialization::void_upcast(
    1.99 +        const extended_type_info & derived_type,
   1.100 +        const extended_type_info & base_type,
   1.101 +        const void * t,
   1.102 +        bool top
   1.103 +    );
   1.104 +    friend 
   1.105 +    BOOST_SERIALIZATION_DECL(void const *)  
   1.106 +    boost::serialization::void_downcast(
   1.107 +        const extended_type_info & derived_type,
   1.108 +        const extended_type_info & base_type,
   1.109 +        const void * t,
   1.110 +        bool top
   1.111 +    );
   1.112 +    // each derived class must re-implement these;
   1.113 +    virtual void const * upcast(void const * t) const = 0;
   1.114 +    virtual void const * downcast(void const * t) const = 0;
   1.115 +    // Data members
   1.116 +    extended_type_info const & m_derived_type;
   1.117 +    extended_type_info const & m_base_type;
   1.118 +protected:
   1.119 +    static void static_register(const void_caster *);
   1.120 +public:
   1.121 +    // Constructor
   1.122 +    void_caster(
   1.123 +        extended_type_info const & derived_type_,
   1.124 +        extended_type_info const & base_type_ 
   1.125 +    );
   1.126 +    // predicate used to determine if this void caster includes
   1.127 +    // a particular eti *
   1.128 +    bool includes(const extended_type_info * eti) const;
   1.129 +    virtual ~void_caster();
   1.130 +private:
   1.131 +    // cw 8.3 requires this!!
   1.132 +    void_caster& operator=(void_caster const&);
   1.133 +};
   1.134 +
   1.135 +template <class Derived, class Base>
   1.136 +class void_caster_primitive : 
   1.137 +    public void_caster
   1.138 +{
   1.139 +    virtual void const* downcast( void const * t ) const {
   1.140 +        Derived * d = boost::smart_cast<const Derived *, const Base *>(
   1.141 +            static_cast<const Base *>(t)
   1.142 +        );
   1.143 +        return d;
   1.144 +    }
   1.145 +    virtual void const* upcast(void const * t) const {
   1.146 +        Base * b = boost::smart_cast<const Base *, const Derived *>(
   1.147 +            static_cast<const Derived *>(t)
   1.148 +        );
   1.149 +        return b;
   1.150 +    }
   1.151 +
   1.152 +public:
   1.153 +    static const void_caster_primitive instance;
   1.154 +    void_caster_primitive() BOOST_USED;
   1.155 +};
   1.156 +
   1.157 +template <class Derived, class Base>
   1.158 +void_caster_primitive<Derived, Base>::void_caster_primitive() :
   1.159 +    void_caster( 
   1.160 +        * type_info_implementation<Derived>::type::get_instance(), 
   1.161 +        * type_info_implementation<Base>::type::get_instance() 
   1.162 +    )
   1.163 +{
   1.164 +    this->static_register(& instance);
   1.165 +}
   1.166 +
   1.167 +// the purpose of this class is to create to->from and from->to instances
   1.168 +// of void_caster_primitive for each related pair of types.  This has to be
   1.169 +// done a pre-execution time - hence the usage of static variable.
   1.170 +template<class Derived, class Base>
   1.171 +const void_caster_primitive<Derived, Base>
   1.172 +    void_caster_primitive<Derived, Base>::instance;
   1.173 +
   1.174 +} // void_cast_detail 
   1.175 +
   1.176 +// Register a base/derived pair.  This indicates that it is possible
   1.177 +// to upcast a void pointer from Derived to Base and downcast a
   1.178 +// void pointer from Base to Derived.  Note bogus arguments to workaround
   1.179 +// bug in msvc 6.0
   1.180 +template<class Derived, class Base>
   1.181 +BOOST_DLLEXPORT 
   1.182 +inline const void_cast_detail::void_caster & void_cast_register(
   1.183 +    const Derived * dnull, 
   1.184 +    const Base * bnull
   1.185 +) BOOST_USED;
   1.186 +template<class Derived, class Base>
   1.187 +BOOST_DLLEXPORT 
   1.188 +inline const void_cast_detail::void_caster & void_cast_register(
   1.189 +    const Derived * /* dnull = NULL */, 
   1.190 +    const Base * /* bnull = NULL */
   1.191 +){
   1.192 +    return void_cast_detail::void_caster_primitive<
   1.193 +        const Derived, 
   1.194 +        const Base
   1.195 +    >::instance;
   1.196 +}
   1.197 +
   1.198 +} // namespace serialization
   1.199 +} // namespace boost
   1.200 +
   1.201 +#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
   1.202 +
   1.203 +#endif // BOOST_SERIALIZATION_VOID_CAST_HPP