os/ossrv/ossrv_pub/boost_apis/boost/archive/detail/iserializer.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#ifndef BOOST_ARCHIVE_DETAIL_ISERIALIZER_HPP
sl@0
     2
#define BOOST_ARCHIVE_DETAIL_ISERIALIZER_HPP
sl@0
     3
sl@0
     4
// MS compatible compilers support #pragma once
sl@0
     5
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
sl@0
     6
# pragma once
sl@0
     7
#pragma inline_depth(511)
sl@0
     8
#pragma inline_recursion(on)
sl@0
     9
#endif
sl@0
    10
sl@0
    11
#if defined(__MWERKS__)
sl@0
    12
#pragma inline_depth(511)
sl@0
    13
#endif
sl@0
    14
sl@0
    15
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
    16
// iserializer.hpp: interface for serialization system.
sl@0
    17
sl@0
    18
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
sl@0
    19
// Use, modification and distribution is subject to the Boost Software
sl@0
    20
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
    21
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    22
sl@0
    23
//  See http://www.boost.org for updates, documentation, and revision history.
sl@0
    24
sl@0
    25
#include <new>     // for placement new
sl@0
    26
#include <memory>  // for auto_ptr
sl@0
    27
#include <cstddef> // size_t
sl@0
    28
sl@0
    29
#include <boost/config.hpp>
sl@0
    30
#include <boost/detail/workaround.hpp>
sl@0
    31
#if defined(BOOST_NO_STDC_NAMESPACE)
sl@0
    32
namespace std{ 
sl@0
    33
    using ::size_t; 
sl@0
    34
} // namespace std
sl@0
    35
#endif
sl@0
    36
#include <boost/throw_exception.hpp>
sl@0
    37
#include <boost/smart_cast.hpp>
sl@0
    38
#include <boost/static_assert.hpp>
sl@0
    39
#include <boost/static_warning.hpp>
sl@0
    40
#include <boost/detail/no_exceptions_support.hpp>
sl@0
    41
sl@0
    42
#include <boost/type_traits/is_pointer.hpp>
sl@0
    43
#include <boost/type_traits/is_fundamental.hpp>
sl@0
    44
#include <boost/type_traits/is_enum.hpp>
sl@0
    45
#include <boost/type_traits/is_const.hpp>
sl@0
    46
#include <boost/type_traits/remove_const.hpp>
sl@0
    47
#include <boost/serialization/is_abstract.hpp>
sl@0
    48
sl@0
    49
#include <boost/mpl/eval_if.hpp>
sl@0
    50
#include <boost/mpl/if.hpp>
sl@0
    51
#include <boost/mpl/identity.hpp>
sl@0
    52
#include <boost/mpl/or.hpp>
sl@0
    53
#include <boost/mpl/and.hpp>
sl@0
    54
#include <boost/mpl/less.hpp>
sl@0
    55
#include <boost/mpl/greater_equal.hpp>
sl@0
    56
#include <boost/mpl/int.hpp>
sl@0
    57
#include <boost/mpl/list.hpp>
sl@0
    58
#include <boost/mpl/empty.hpp>
sl@0
    59
#include <boost/mpl/not.hpp>
sl@0
    60
sl@0
    61
 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO   
sl@0
    62
     #include <boost/serialization/extended_type_info_typeid.hpp>   
sl@0
    63
 #endif 
sl@0
    64
// the following is need only for dynamic cast of polymorphic pointers
sl@0
    65
#include <boost/archive/detail/basic_iarchive.hpp>
sl@0
    66
#include <boost/archive/detail/basic_iserializer.hpp>
sl@0
    67
#include <boost/archive/detail/archive_pointer_iserializer.hpp>
sl@0
    68
#include <boost/archive/archive_exception.hpp>
sl@0
    69
sl@0
    70
#include <boost/serialization/force_include.hpp>
sl@0
    71
#include <boost/serialization/serialization.hpp>
sl@0
    72
#include <boost/serialization/version.hpp>
sl@0
    73
#include <boost/serialization/level.hpp>
sl@0
    74
#include <boost/serialization/tracking.hpp>
sl@0
    75
#include <boost/serialization/type_info_implementation.hpp>
sl@0
    76
#include <boost/serialization/nvp.hpp>
sl@0
    77
#include <boost/serialization/binary_object.hpp>
sl@0
    78
#include <boost/serialization/void_cast.hpp>
sl@0
    79
sl@0
    80
namespace boost {
sl@0
    81
sl@0
    82
namespace serialization {
sl@0
    83
    class extended_type_info;
sl@0
    84
} // namespace serialization
sl@0
    85
sl@0
    86
namespace archive {
sl@0
    87
sl@0
    88
// an accessor to permit friend access to archives.  Needed because
sl@0
    89
// some compilers don't handle friend templates completely
sl@0
    90
class load_access {
sl@0
    91
public:
sl@0
    92
    template<class Archive, class T>
sl@0
    93
    static void load_primitive(Archive &ar, T &t){
sl@0
    94
        ar.load(t);
sl@0
    95
    }
sl@0
    96
};
sl@0
    97
sl@0
    98
namespace detail {
sl@0
    99
sl@0
   100
template<class Archive, class T>
sl@0
   101
class iserializer : public basic_iserializer
sl@0
   102
{
sl@0
   103
private:
sl@0
   104
    virtual void destroy(/*const*/ void *address) const {
sl@0
   105
        boost::serialization::access::destroy(static_cast<T *>(address));
sl@0
   106
    }
sl@0
   107
    // private constructor to inhibit any existence other than the 
sl@0
   108
    // static one
sl@0
   109
    explicit iserializer() :
sl@0
   110
        basic_iserializer(
sl@0
   111
            * boost::serialization::type_info_implementation<T>::type::get_instance()
sl@0
   112
        )
sl@0
   113
    {}
sl@0
   114
public:
sl@0
   115
    virtual BOOST_DLLEXPORT void load_object_data(
sl@0
   116
        basic_iarchive & ar,
sl@0
   117
        void *x, 
sl@0
   118
        const unsigned int file_version
sl@0
   119
    ) const BOOST_USED ;
sl@0
   120
    virtual bool class_info() const {
sl@0
   121
        return boost::serialization::implementation_level<T>::value 
sl@0
   122
            >= boost::serialization::object_class_info;
sl@0
   123
    }
sl@0
   124
    virtual bool tracking(const unsigned int flags) const {
sl@0
   125
//        if(0 != (flags & no_tracking))
sl@0
   126
//            return false;
sl@0
   127
        return boost::serialization::tracking_level<T>::value 
sl@0
   128
                == boost::serialization::track_always
sl@0
   129
            || boost::serialization::tracking_level<T>::value 
sl@0
   130
                == boost::serialization::track_selectivly
sl@0
   131
            && serialized_as_pointer();
sl@0
   132
    }
sl@0
   133
    virtual unsigned int version() const {
sl@0
   134
        return ::boost::serialization::version<T>::value;
sl@0
   135
    }
sl@0
   136
    virtual bool is_polymorphic() const {
sl@0
   137
        typedef BOOST_DEDUCED_TYPENAME 
sl@0
   138
            boost::serialization::type_info_implementation<
sl@0
   139
                T
sl@0
   140
            >::type::is_polymorphic::type typex;
sl@0
   141
        return typex::value;
sl@0
   142
    }
sl@0
   143
    static iserializer & instantiate(){
sl@0
   144
        static iserializer instance;
sl@0
   145
        return instance;
sl@0
   146
    }
sl@0
   147
    virtual ~iserializer(){};
sl@0
   148
};
sl@0
   149
sl@0
   150
template<class Archive, class T>
sl@0
   151
BOOST_DLLEXPORT void iserializer<Archive, T>::load_object_data(
sl@0
   152
    basic_iarchive & ar,
sl@0
   153
    void *x, 
sl@0
   154
    const unsigned int file_version
sl@0
   155
) const {
sl@0
   156
    // make sure call is routed through the higest interface that might
sl@0
   157
    // be specialized by the user.
sl@0
   158
    boost::serialization::serialize_adl(
sl@0
   159
        boost::smart_cast_reference<Archive &>(ar),
sl@0
   160
        * static_cast<T *>(x), 
sl@0
   161
        file_version
sl@0
   162
    );
sl@0
   163
}
sl@0
   164
sl@0
   165
// instantiation of this template creates a static object.  Note inversion of
sl@0
   166
// normal argument order to workaround bizarre error in MSVC 6.0 which only
sl@0
   167
// manifests iftself during compiler time.
sl@0
   168
template<class T, class Archive>
sl@0
   169
class pointer_iserializer : public archive_pointer_iserializer<Archive> 
sl@0
   170
{
sl@0
   171
private:
sl@0
   172
    virtual const basic_iserializer & get_basic_serializer() const {
sl@0
   173
        return iserializer<Archive, T>::instantiate();
sl@0
   174
    }
sl@0
   175
    virtual BOOST_DLLEXPORT void load_object_ptr(
sl@0
   176
        basic_iarchive & ar, 
sl@0
   177
        void * & x,
sl@0
   178
        const unsigned int file_version
sl@0
   179
    ) const BOOST_USED;
sl@0
   180
#if defined(__GNUC__) || ( defined(BOOST_MSVC) && (_MSC_VER <= 1300) )
sl@0
   181
public:
sl@0
   182
#endif
sl@0
   183
    // private constructor to inhibit any existence other than the 
sl@0
   184
    // static one.  Note GCC doesn't permit constructor to be private
sl@0
   185
    explicit BOOST_DLLEXPORT pointer_iserializer() BOOST_USED;
sl@0
   186
    static const pointer_iserializer instance;
sl@0
   187
public:
sl@0
   188
    // at least one compiler (CW) seems to require that serialize_adl
sl@0
   189
    // be explicitly instantiated. Still under investigation. 
sl@0
   190
    #if ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
sl@0
   191
    void (* const m)(Archive &, T &, const unsigned);
sl@0
   192
    boost::serialization::extended_type_info * (* e)();
sl@0
   193
    #endif
sl@0
   194
    static BOOST_DLLEXPORT const pointer_iserializer & instantiate() BOOST_USED;
sl@0
   195
    virtual ~pointer_iserializer(){};
sl@0
   196
};
sl@0
   197
sl@0
   198
template<class T, class Archive>
sl@0
   199
BOOST_DLLEXPORT const pointer_iserializer<T, Archive> & 
sl@0
   200
pointer_iserializer<T, Archive>::instantiate() {
sl@0
   201
    return instance;
sl@0
   202
}
sl@0
   203
sl@0
   204
// note: instances of this template to be constructed before the main
sl@0
   205
// is called in order for things to be initialized properly.  For this
sl@0
   206
// reason, hiding the instance in a static function as was done above
sl@0
   207
// won't work here so we created a free instance here.
sl@0
   208
template<class T, class Archive>
sl@0
   209
const pointer_iserializer<T, Archive> pointer_iserializer<T, Archive>::instance;
sl@0
   210
sl@0
   211
// note trick to be sure that operator new is using class specific
sl@0
   212
// version if such exists. Due to Peter Dimov.
sl@0
   213
// note: the following fails if T has no default constructor.
sl@0
   214
// otherwise it would have been ideal
sl@0
   215
//struct heap_allocator : public T 
sl@0
   216
//{
sl@0
   217
//    T * invoke(){
sl@0
   218
//        return ::new(sizeof(T));
sl@0
   219
//    }
sl@0
   220
//}
sl@0
   221
sl@0
   222
// note: this should really be a member of the load_ptr function
sl@0
   223
// below but some compilers still complain about this.
sl@0
   224
template<class T>
sl@0
   225
struct heap_allocator
sl@0
   226
{
sl@0
   227
    #if 0
sl@0
   228
        // note: this fails on msvc 7.0 and gcc 3.2
sl@0
   229
        template <class U, U x> struct test;
sl@0
   230
        typedef char* yes;
sl@0
   231
        typedef int* no;
sl@0
   232
        template <class U>
sl@0
   233
        yes has_op_new(U*, test<void* (*)(std::size_t), &U::operator new>* = 0);
sl@0
   234
        no has_op_new(...);
sl@0
   235
sl@0
   236
        template<class U>
sl@0
   237
        T * new_operator(U);
sl@0
   238
sl@0
   239
        T * new_operator(yes){
sl@0
   240
            return (T::operator new)(sizeof(T));
sl@0
   241
        }
sl@0
   242
        T * new_operator(no){
sl@0
   243
            return static_cast<T *>(operator new(sizeof(T)));
sl@0
   244
        }
sl@0
   245
        static T * invoke(){
sl@0
   246
            return new_operator(has_op_new(static_cast<T *>(NULL)));
sl@0
   247
        }
sl@0
   248
    #else
sl@0
   249
        // while this doesn't handle operator new overload for class T
sl@0
   250
        static T * invoke(){
sl@0
   251
            return static_cast<T *>(operator new(sizeof(T)));
sl@0
   252
        }
sl@0
   253
    #endif
sl@0
   254
};
sl@0
   255
sl@0
   256
// due to Martin Ecker
sl@0
   257
template <typename T>
sl@0
   258
class auto_ptr_with_deleter
sl@0
   259
{
sl@0
   260
public:
sl@0
   261
    explicit auto_ptr_with_deleter(T* p) :
sl@0
   262
        m_p(p)
sl@0
   263
    {}
sl@0
   264
    ~auto_ptr_with_deleter(){
sl@0
   265
        if (m_p)
sl@0
   266
            boost::serialization::access::destroy(m_p);
sl@0
   267
    }
sl@0
   268
    T* get() const {
sl@0
   269
        return m_p;
sl@0
   270
    }
sl@0
   271
sl@0
   272
    T* release() {
sl@0
   273
        T* p = m_p;
sl@0
   274
        m_p = NULL;
sl@0
   275
        return p;
sl@0
   276
    }
sl@0
   277
private:
sl@0
   278
    T* m_p;
sl@0
   279
};
sl@0
   280
sl@0
   281
template<class T, class Archive>
sl@0
   282
BOOST_DLLEXPORT void pointer_iserializer<T, Archive>::load_object_ptr(
sl@0
   283
    basic_iarchive & ar, 
sl@0
   284
    void * & x,
sl@0
   285
    const unsigned int file_version
sl@0
   286
) const {
sl@0
   287
    Archive & ar_impl = boost::smart_cast_reference<Archive &>(ar);
sl@0
   288
sl@0
   289
//    if(0 != (ar.get_flags() & no_object_creation)){
sl@0
   290
//        ar_impl >> boost::serialization::make_nvp(NULL, * static_cast<T *>(x));
sl@0
   291
//        return;
sl@0
   292
//    }
sl@0
   293
sl@0
   294
    auto_ptr_with_deleter<T> ap(heap_allocator<T>::invoke());
sl@0
   295
    if(NULL == ap.get())
sl@0
   296
        boost::throw_exception(std::bad_alloc()) ;
sl@0
   297
sl@0
   298
    T * t = ap.get();
sl@0
   299
    x = t;
sl@0
   300
sl@0
   301
    // catch exception during load_construct_data so that we don't
sl@0
   302
    // automatically delete the t which is most likely not fully
sl@0
   303
    // constructed
sl@0
   304
    BOOST_TRY {
sl@0
   305
        // this addresses an obscure situtation that occurs when 
sl@0
   306
        // load_constructor de-serializes something through a pointer.
sl@0
   307
        ar.next_object_pointer(t);
sl@0
   308
        boost::serialization::load_construct_data_adl<Archive, T>(
sl@0
   309
            ar_impl,
sl@0
   310
            t, 
sl@0
   311
            file_version
sl@0
   312
        );
sl@0
   313
    }
sl@0
   314
    BOOST_CATCH(...){
sl@0
   315
        BOOST_RETHROW;
sl@0
   316
    }
sl@0
   317
    BOOST_CATCH_END
sl@0
   318
sl@0
   319
    ar_impl >> boost::serialization::make_nvp(NULL, * t);
sl@0
   320
    ap.release();
sl@0
   321
}
sl@0
   322
sl@0
   323
template<class T, class Archive>
sl@0
   324
#if ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
sl@0
   325
BOOST_DLLEXPORT pointer_iserializer<T, Archive>::pointer_iserializer() :
sl@0
   326
    archive_pointer_iserializer<Archive>(
sl@0
   327
        * boost::serialization::type_info_implementation<T>::type::get_instance()
sl@0
   328
    ),
sl@0
   329
    m(boost::serialization::serialize_adl<Archive, T>),
sl@0
   330
    e(boost::serialization::type_info_implementation<T>::type::get_instance)
sl@0
   331
#else
sl@0
   332
BOOST_DLLEXPORT pointer_iserializer<T, Archive>::pointer_iserializer() :
sl@0
   333
    archive_pointer_iserializer<Archive>(
sl@0
   334
        * boost::serialization::type_info_implementation<T>::type::get_instance()
sl@0
   335
    )
sl@0
   336
#endif
sl@0
   337
{
sl@0
   338
    iserializer<Archive, T> & bis = iserializer<Archive, T>::instantiate();
sl@0
   339
    bis.set_bpis(this);
sl@0
   340
}
sl@0
   341
sl@0
   342
template<class Archive, class T>
sl@0
   343
struct load_non_pointer_type {
sl@0
   344
    // note this bounces the call right back to the archive
sl@0
   345
    // with no runtime overhead
sl@0
   346
    struct load_primitive {
sl@0
   347
        static void invoke(Archive & ar, T & t){
sl@0
   348
            load_access::load_primitive(ar, t);
sl@0
   349
        }
sl@0
   350
    };
sl@0
   351
    // note this bounces the call right back to the archive
sl@0
   352
    // with no runtime overhead
sl@0
   353
    struct load_only {
sl@0
   354
        static void invoke(Archive & ar, T & t){
sl@0
   355
            // short cut to user's serializer
sl@0
   356
            // make sure call is routed through the higest interface that might
sl@0
   357
            // be specialized by the user.
sl@0
   358
            boost::serialization::serialize_adl(
sl@0
   359
                ar, t, boost::serialization::version<T>::value
sl@0
   360
            );
sl@0
   361
        }
sl@0
   362
    };
sl@0
   363
sl@0
   364
    // note this save class information including version
sl@0
   365
    // and serialization level to the archive
sl@0
   366
    struct load_standard {
sl@0
   367
        static void invoke(Archive &ar, T &t){
sl@0
   368
            //BOOST_STATIC_ASSERT(! boost::is_const<T>::value);
sl@0
   369
            // borland - for some reason T is const here - even though
sl@0
   370
            // its not called that way - so fix it her
sl@0
   371
            typedef BOOST_DEDUCED_TYPENAME boost::remove_const<T>::type typex;
sl@0
   372
            void * x = & const_cast<typex &>(t);
sl@0
   373
            ar.load_object(x, iserializer<Archive, T>::instantiate());
sl@0
   374
        }
sl@0
   375
    };
sl@0
   376
sl@0
   377
    struct load_conditional {
sl@0
   378
        static void invoke(Archive &ar, T &t){
sl@0
   379
            //if(0 == (ar.get_flags() & no_tracking))
sl@0
   380
                load_standard::invoke(ar, t);
sl@0
   381
            //else
sl@0
   382
            //    load_only::invoke(ar, t);
sl@0
   383
        }
sl@0
   384
    };
sl@0
   385
sl@0
   386
    typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   387
            // if its primitive
sl@0
   388
            mpl::equal_to<
sl@0
   389
                boost::serialization::implementation_level<T>,
sl@0
   390
                mpl::int_<boost::serialization::primitive_type>
sl@0
   391
            >,
sl@0
   392
            mpl::identity<load_primitive>,
sl@0
   393
        // else
sl@0
   394
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   395
        // class info / version
sl@0
   396
        mpl::greater_equal<
sl@0
   397
                    boost::serialization::implementation_level<T>,
sl@0
   398
                    mpl::int_<boost::serialization::object_class_info>
sl@0
   399
                >,
sl@0
   400
        // do standard load
sl@0
   401
        mpl::identity<load_standard>,
sl@0
   402
    // else
sl@0
   403
    BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   404
        // no tracking
sl@0
   405
                mpl::equal_to<
sl@0
   406
                    boost::serialization::tracking_level<T>,
sl@0
   407
                    mpl::int_<boost::serialization::track_never>
sl@0
   408
            >,
sl@0
   409
            // do a fast load
sl@0
   410
            mpl::identity<load_only>,
sl@0
   411
        // else
sl@0
   412
        // do a fast load only tracking is turned off
sl@0
   413
        mpl::identity<load_conditional>
sl@0
   414
    > > >::type typex;
sl@0
   415
sl@0
   416
    static void invoke(Archive & ar, T &t){
sl@0
   417
        BOOST_STATIC_ASSERT((
sl@0
   418
            mpl::greater_equal<
sl@0
   419
                boost::serialization::implementation_level<T>, 
sl@0
   420
                mpl::int_<boost::serialization::primitive_type>
sl@0
   421
            >::value
sl@0
   422
        ));
sl@0
   423
        typex::invoke(ar, t);
sl@0
   424
    }
sl@0
   425
};
sl@0
   426
sl@0
   427
template<class Archive, class Tptr>
sl@0
   428
struct load_pointer_type {
sl@0
   429
    template<class T>
sl@0
   430
    struct abstract
sl@0
   431
    {
sl@0
   432
        static const basic_pointer_iserializer * register_type(Archive & /* ar */){
sl@0
   433
            #if ! defined(__BORLANDC__)
sl@0
   434
            typedef BOOST_DEDUCED_TYPENAME 
sl@0
   435
                boost::serialization::type_info_implementation<T>::type::is_polymorphic typex;
sl@0
   436
            // it has? to be polymorphic
sl@0
   437
            BOOST_STATIC_ASSERT(typex::value);
sl@0
   438
            #endif
sl@0
   439
            return static_cast<basic_pointer_iserializer *>(NULL);
sl@0
   440
         }
sl@0
   441
    };
sl@0
   442
sl@0
   443
    template<class T>
sl@0
   444
    struct non_abstract
sl@0
   445
    {
sl@0
   446
        static const basic_pointer_iserializer * register_type(Archive & ar){
sl@0
   447
            return ar.register_type(static_cast<T *>(NULL));
sl@0
   448
        }
sl@0
   449
    };
sl@0
   450
sl@0
   451
    template<class T>
sl@0
   452
    static const basic_pointer_iserializer * register_type(Archive &ar, T & /*t*/){
sl@0
   453
        // there should never be any need to load an abstract polymorphic 
sl@0
   454
        // class pointer.  Inhibiting code generation for this
sl@0
   455
        // permits abstract base classes to be used - note: exception
sl@0
   456
        // virtual serialize functions used for plug-ins
sl@0
   457
        typedef BOOST_DEDUCED_TYPENAME
sl@0
   458
            mpl::eval_if<
sl@0
   459
                serialization::is_abstract<T>,
sl@0
   460
                mpl::identity<abstract<T> >,
sl@0
   461
                mpl::identity<non_abstract<T> >    
sl@0
   462
            >::type typex;
sl@0
   463
        return typex::register_type(ar);
sl@0
   464
    }
sl@0
   465
sl@0
   466
    template<class T>
sl@0
   467
    static T * pointer_tweak(
sl@0
   468
        const boost::serialization::extended_type_info & eti,
sl@0
   469
        void * t,
sl@0
   470
        T &
sl@0
   471
    ) {
sl@0
   472
        // tweak the pointer back to the base class
sl@0
   473
        return static_cast<T *>(
sl@0
   474
            boost::serialization::void_upcast(
sl@0
   475
                eti,
sl@0
   476
                * boost::serialization::type_info_implementation<T>::type::get_instance(),
sl@0
   477
                t
sl@0
   478
            )
sl@0
   479
        );
sl@0
   480
    }
sl@0
   481
sl@0
   482
    static void invoke(Archive & ar, Tptr & t){
sl@0
   483
        const basic_pointer_iserializer * bpis_ptr = register_type(ar, *t);
sl@0
   484
        const basic_pointer_iserializer * newbpis_ptr = ar.load_pointer(
sl@0
   485
            * reinterpret_cast<void **>(&t),
sl@0
   486
            bpis_ptr,
sl@0
   487
            archive_pointer_iserializer<Archive>::find
sl@0
   488
        );
sl@0
   489
        // if the pointer isn't that of the base class
sl@0
   490
        if(newbpis_ptr != bpis_ptr){
sl@0
   491
            t = pointer_tweak(newbpis_ptr->get_eti(), t, *t);
sl@0
   492
        }
sl@0
   493
    }
sl@0
   494
};
sl@0
   495
sl@0
   496
template<class Archive, class T>
sl@0
   497
struct load_enum_type {
sl@0
   498
    static void invoke(Archive &ar, T &t){
sl@0
   499
        // convert integers to correct enum to load
sl@0
   500
        int i;
sl@0
   501
        ar >> boost::serialization::make_nvp(NULL, i);
sl@0
   502
        t = static_cast<T>(i);
sl@0
   503
    }
sl@0
   504
};
sl@0
   505
sl@0
   506
template<class Archive, class T>
sl@0
   507
struct load_array_type {
sl@0
   508
    static void invoke(Archive &ar, T &t){
sl@0
   509
        // convert integers to correct enum to load
sl@0
   510
        int current_count = sizeof(t) / (
sl@0
   511
            static_cast<char *>(static_cast<void *>(&t[1])) 
sl@0
   512
            - static_cast<char *>(static_cast<void *>(&t[0]))
sl@0
   513
        );
sl@0
   514
        int count;
sl@0
   515
        ar >> BOOST_SERIALIZATION_NVP(count);
sl@0
   516
        if(count > current_count)
sl@0
   517
            boost::throw_exception(archive::archive_exception(
sl@0
   518
                boost::archive::archive_exception::array_size_too_short
sl@0
   519
            ));
sl@0
   520
        int i;
sl@0
   521
        for(i = 0; i < count; ++i)
sl@0
   522
            ar >> boost::serialization::make_nvp("item", t[i]);
sl@0
   523
    }
sl@0
   524
};
sl@0
   525
sl@0
   526
// note bogus arguments to workaround msvc 6 silent runtime failure
sl@0
   527
template<class Archive, class T>
sl@0
   528
BOOST_DLLEXPORT 
sl@0
   529
inline const basic_pointer_iserializer &
sl@0
   530
instantiate_pointer_iserializer(
sl@0
   531
    Archive * /* ar = NULL */,
sl@0
   532
    T * /* t = NULL */
sl@0
   533
) BOOST_USED;
sl@0
   534
sl@0
   535
template<class Archive, class T>
sl@0
   536
BOOST_DLLEXPORT 
sl@0
   537
inline const basic_pointer_iserializer &
sl@0
   538
instantiate_pointer_iserializer(
sl@0
   539
    Archive * /* ar = NULL */,
sl@0
   540
    T * /* t = NULL */
sl@0
   541
){
sl@0
   542
    // note: reversal of order of arguments to work around msvc 6.0 bug
sl@0
   543
    // that manifests itself while trying to link.
sl@0
   544
    return pointer_iserializer<T, Archive>::instantiate();
sl@0
   545
}
sl@0
   546
sl@0
   547
} // detail
sl@0
   548
sl@0
   549
template<class Archive, class T>
sl@0
   550
inline void load(Archive &ar, T &t){
sl@0
   551
    // if this assertion trips. It means we're trying to load a
sl@0
   552
    // const object with a compiler that doesn't have correct
sl@0
   553
    // funtion template ordering.  On other compilers, this is
sl@0
   554
    // handled below.
sl@0
   555
    BOOST_STATIC_ASSERT(! boost::is_const<T>::value);
sl@0
   556
    typedef
sl@0
   557
        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer<T>,
sl@0
   558
            mpl::identity<detail::load_pointer_type<Archive, T> >
sl@0
   559
        ,//else
sl@0
   560
        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array<T>,
sl@0
   561
            mpl::identity<detail::load_array_type<Archive, T> >
sl@0
   562
        ,//else
sl@0
   563
        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum<T>,
sl@0
   564
            mpl::identity<detail::load_enum_type<Archive, T> >
sl@0
   565
        ,//else
sl@0
   566
            mpl::identity<detail::load_non_pointer_type<Archive, T> >
sl@0
   567
        >
sl@0
   568
        >
sl@0
   569
        >::type typex;
sl@0
   570
    typex::invoke(ar, t);
sl@0
   571
}
sl@0
   572
sl@0
   573
// BORLAND
sl@0
   574
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x560))
sl@0
   575
// borland has a couple fo problems
sl@0
   576
// a) if function is partiall specialized - see below
sl@0
   577
// const paramters are transformed to non-const ones
sl@0
   578
// b) implementation of base_object can't be made to work
sl@0
   579
// correctly which results in all base_object s being const.
sl@0
   580
// So, strip off the const for borland.  This breaks the trap
sl@0
   581
// for loading const objects - but I see no alternative
sl@0
   582
template<class Archive, class T>
sl@0
   583
inline void load(Archive &ar, const T & t){
sl@0
   584
        load(ar, const_cast<T &>(t));
sl@0
   585
}
sl@0
   586
#endif
sl@0
   587
sl@0
   588
// let wrappers through.  (Someday implement is_wrapper)
sl@0
   589
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
sl@0
   590
template<class Archive, class T>
sl@0
   591
inline void load(Archive &ar, const serialization::nvp<T> &t){
sl@0
   592
        boost::archive::load(ar, const_cast<serialization::nvp<T> &>(t));
sl@0
   593
}
sl@0
   594
template<class Archive>
sl@0
   595
inline void load(Archive &ar, const serialization::binary_object &t){
sl@0
   596
        boost::archive::load(ar, const_cast<serialization::binary_object &>(t));
sl@0
   597
}
sl@0
   598
sl@0
   599
//template<class Archive, class T>
sl@0
   600
//inline void load(Archive &ar, const serialization::binary_object &t){
sl@0
   601
//      load(ar, const_cast<binary_object &>(t));
sl@0
   602
//}
sl@0
   603
#endif
sl@0
   604
sl@0
   605
} // namespace archive
sl@0
   606
} // namespace boost
sl@0
   607
sl@0
   608
#endif // BOOST_ARCHIVE_DETAIL_ISERIALIZER_HPP