os/ossrv/ossrv_pub/boost_apis/boost/archive/detail/oserializer.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef BOOST_ARCHIVE_OSERIALIZER_HPP
sl@0
     2
#define BOOST_ARCHIVE_OSERIALIZER_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
// oserializer.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 <cassert>
sl@0
    26
sl@0
    27
#include <boost/config.hpp>
sl@0
    28
#include <boost/detail/workaround.hpp>
sl@0
    29
#include <boost/throw_exception.hpp>
sl@0
    30
#include <boost/smart_cast.hpp>
sl@0
    31
#include <boost/static_assert.hpp>
sl@0
    32
#include <boost/static_warning.hpp>
sl@0
    33
sl@0
    34
#include <boost/type_traits/is_pointer.hpp>
sl@0
    35
#include <boost/type_traits/is_fundamental.hpp>
sl@0
    36
#include <boost/type_traits/is_enum.hpp>
sl@0
    37
#include <boost/type_traits/is_volatile.hpp>
sl@0
    38
#include <boost/type_traits/is_const.hpp>
sl@0
    39
#include <boost/type_traits/is_same.hpp>
sl@0
    40
#include <boost/serialization/is_abstract.hpp>
sl@0
    41
sl@0
    42
#include <boost/mpl/eval_if.hpp>
sl@0
    43
#include <boost/mpl/and.hpp>
sl@0
    44
#include <boost/mpl/less.hpp>
sl@0
    45
#include <boost/mpl/greater_equal.hpp>
sl@0
    46
#include <boost/mpl/equal_to.hpp>
sl@0
    47
#include <boost/mpl/int.hpp>
sl@0
    48
#include <boost/mpl/identity.hpp>
sl@0
    49
#include <boost/mpl/list.hpp>
sl@0
    50
#include <boost/mpl/empty.hpp>
sl@0
    51
#include <boost/mpl/not.hpp>
sl@0
    52
sl@0
    53
 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO   
sl@0
    54
     #include <boost/serialization/extended_type_info_typeid.hpp>   
sl@0
    55
 #endif 
sl@0
    56
// the following is need only for dynamic cast of polymorphic pointers
sl@0
    57
#include <boost/archive/detail/basic_oarchive.hpp>
sl@0
    58
#include <boost/archive/detail/basic_oserializer.hpp>
sl@0
    59
#include <boost/archive/detail/archive_pointer_oserializer.hpp>
sl@0
    60
sl@0
    61
#include <boost/serialization/force_include.hpp>
sl@0
    62
#include <boost/serialization/serialization.hpp>
sl@0
    63
#include <boost/serialization/version.hpp>
sl@0
    64
#include <boost/serialization/level.hpp>
sl@0
    65
#include <boost/serialization/tracking.hpp>
sl@0
    66
#include <boost/serialization/type_info_implementation.hpp>
sl@0
    67
#include <boost/serialization/nvp.hpp>
sl@0
    68
#include <boost/serialization/void_cast.hpp>
sl@0
    69
sl@0
    70
#include <boost/archive/archive_exception.hpp>
sl@0
    71
sl@0
    72
namespace boost {
sl@0
    73
sl@0
    74
namespace serialization {
sl@0
    75
    class extended_type_info;
sl@0
    76
} // namespace serialization
sl@0
    77
sl@0
    78
namespace archive {
sl@0
    79
sl@0
    80
// an accessor to permit friend access to archives.  Needed because
sl@0
    81
// some compilers don't handle friend templates completely
sl@0
    82
class save_access {
sl@0
    83
public:
sl@0
    84
    template<class Archive>
sl@0
    85
    static void end_preamble(Archive & ar){
sl@0
    86
        ar.end_preamble();
sl@0
    87
    }
sl@0
    88
    template<class Archive, class T>
sl@0
    89
    static void save_primitive(Archive & ar, const  T & t){
sl@0
    90
        ar.end_preamble();
sl@0
    91
        ar.save(t);
sl@0
    92
    }
sl@0
    93
};
sl@0
    94
sl@0
    95
namespace detail {
sl@0
    96
sl@0
    97
template<class Archive, class T>
sl@0
    98
class oserializer : public basic_oserializer
sl@0
    99
{
sl@0
   100
private:
sl@0
   101
    // private constructor to inhibit any existence other than the 
sl@0
   102
    // static one
sl@0
   103
    explicit oserializer() :
sl@0
   104
        basic_oserializer(
sl@0
   105
            * boost::serialization::type_info_implementation<T>::type::get_instance()
sl@0
   106
        )
sl@0
   107
    {}
sl@0
   108
public:
sl@0
   109
    virtual BOOST_DLLEXPORT void save_object_data(
sl@0
   110
        basic_oarchive & ar,    
sl@0
   111
        const void *x
sl@0
   112
    ) const BOOST_USED ;
sl@0
   113
    virtual bool class_info() const {
sl@0
   114
        return boost::serialization::implementation_level<T>::value 
sl@0
   115
            >= boost::serialization::object_class_info;
sl@0
   116
    }
sl@0
   117
    virtual bool tracking(const unsigned int flags) const {
sl@0
   118
//        if(0 != (flags &  no_tracking))
sl@0
   119
//            return false;
sl@0
   120
        return boost::serialization::tracking_level<T>::value == boost::serialization::track_always
sl@0
   121
            || boost::serialization::tracking_level<T>::value == boost::serialization::track_selectivly
sl@0
   122
            && serialized_as_pointer();
sl@0
   123
    }
sl@0
   124
    virtual unsigned int version() const {
sl@0
   125
        return ::boost::serialization::version<T>::value;
sl@0
   126
    }
sl@0
   127
    virtual bool is_polymorphic() const {
sl@0
   128
        typedef BOOST_DEDUCED_TYPENAME boost::serialization::type_info_implementation<
sl@0
   129
            T
sl@0
   130
        >::type::is_polymorphic::type typex;
sl@0
   131
        return typex::value;
sl@0
   132
    }
sl@0
   133
    static oserializer & instantiate(){
sl@0
   134
        static oserializer instance;
sl@0
   135
        return instance;
sl@0
   136
    }
sl@0
   137
    virtual ~oserializer(){}
sl@0
   138
};
sl@0
   139
sl@0
   140
template<class Archive, class T>
sl@0
   141
BOOST_DLLEXPORT void oserializer<Archive, T>::save_object_data(
sl@0
   142
    basic_oarchive & ar,    
sl@0
   143
    const void *x
sl@0
   144
) const {
sl@0
   145
    // make sure call is routed through the highest interface that might
sl@0
   146
    // be specialized by the user.
sl@0
   147
    boost::serialization::serialize_adl(
sl@0
   148
        boost::smart_cast_reference<Archive &>(ar),
sl@0
   149
        * static_cast<T *>(const_cast<void *>(x)),
sl@0
   150
        version()
sl@0
   151
    );
sl@0
   152
}
sl@0
   153
sl@0
   154
// instantiation of this template creates a static object.  Note inversion of
sl@0
   155
// normal argument order to workaround bizarre error in MSVC 6.0 which only
sl@0
   156
// manifests iftself during compiler time.
sl@0
   157
template<class T, class Archive>
sl@0
   158
class pointer_oserializer : public archive_pointer_oserializer<Archive> 
sl@0
   159
{
sl@0
   160
private:
sl@0
   161
    virtual const basic_oserializer & get_basic_serializer() const {
sl@0
   162
        return oserializer<Archive, T>::instantiate();
sl@0
   163
    }
sl@0
   164
    virtual BOOST_DLLEXPORT void save_object_ptr(
sl@0
   165
        basic_oarchive & ar,
sl@0
   166
        const void * x
sl@0
   167
    ) const BOOST_USED ;
sl@0
   168
#if defined(__GNUC__) || ( defined(BOOST_MSVC) && (_MSC_VER <= 1300) )
sl@0
   169
public:
sl@0
   170
#endif
sl@0
   171
    // private constructor to inhibit any existence other than the 
sl@0
   172
    // static one.  Note GCC doesn't permit constructor to be private
sl@0
   173
    explicit BOOST_DLLEXPORT pointer_oserializer() BOOST_USED;
sl@0
   174
    static const pointer_oserializer instance;
sl@0
   175
public:
sl@0
   176
    #if ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
sl@0
   177
    // at least one compiler (CW) seems to require that serialize_adl
sl@0
   178
    // be explicitly instantiated. Still under investigation. 
sl@0
   179
    void (* const m)(Archive &, T &, const unsigned);
sl@0
   180
    boost::serialization::extended_type_info * (* e)();
sl@0
   181
    #endif
sl@0
   182
    static BOOST_DLLEXPORT const pointer_oserializer & instantiate() BOOST_USED;
sl@0
   183
    virtual ~pointer_oserializer(){}
sl@0
   184
};
sl@0
   185
sl@0
   186
template<class T, class Archive>
sl@0
   187
BOOST_DLLEXPORT const pointer_oserializer<T, Archive> & 
sl@0
   188
pointer_oserializer<T, Archive>::instantiate(){
sl@0
   189
    return instance;
sl@0
   190
}
sl@0
   191
sl@0
   192
// note: instances of this template to be constructed before the main
sl@0
   193
// is called in order for things to be initialized properly.  For this
sl@0
   194
// reason, hiding the instance in a static function as was done above
sl@0
   195
// won't work here so we created a free instance here.
sl@0
   196
template<class T, class Archive>
sl@0
   197
const pointer_oserializer<T, Archive> pointer_oserializer<T, Archive>::instance;
sl@0
   198
sl@0
   199
template<class T, class Archive>
sl@0
   200
BOOST_DLLEXPORT void pointer_oserializer<T, Archive>::save_object_ptr(
sl@0
   201
    basic_oarchive & ar,
sl@0
   202
    const void * x
sl@0
   203
) const {
sl@0
   204
    assert(NULL != x);
sl@0
   205
    // make sure call is routed through the highest interface that might
sl@0
   206
    // be specialized by the user.
sl@0
   207
    T * t = static_cast<T *>(const_cast<void *>(x));
sl@0
   208
    const unsigned int file_version = boost::serialization::version<T>::value;
sl@0
   209
    Archive & ar_impl = boost::smart_cast_reference<Archive &>(ar);
sl@0
   210
    boost::serialization::save_construct_data_adl<Archive, T>(
sl@0
   211
        ar_impl, 
sl@0
   212
        t, 
sl@0
   213
        file_version
sl@0
   214
    );
sl@0
   215
    ar_impl << boost::serialization::make_nvp(NULL, * t);
sl@0
   216
}
sl@0
   217
sl@0
   218
template<class T, class Archive>
sl@0
   219
#if ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
sl@0
   220
BOOST_DLLEXPORT pointer_oserializer<T, Archive>::pointer_oserializer() :
sl@0
   221
    archive_pointer_oserializer<Archive>(
sl@0
   222
        * boost::serialization::type_info_implementation<T>::type::get_instance()
sl@0
   223
    ),
sl@0
   224
    m(boost::serialization::serialize_adl<Archive, T>),
sl@0
   225
    e(boost::serialization::type_info_implementation<T>::type::get_instance)
sl@0
   226
#else
sl@0
   227
BOOST_DLLEXPORT pointer_oserializer<T, Archive>::pointer_oserializer() :
sl@0
   228
    archive_pointer_oserializer<Archive>(
sl@0
   229
        * boost::serialization::type_info_implementation<T>::type::get_instance()
sl@0
   230
    )
sl@0
   231
#endif
sl@0
   232
{
sl@0
   233
    // make sure appropriate member function is instantiated
sl@0
   234
    oserializer<Archive, T> & bos = oserializer<Archive, T>::instantiate();
sl@0
   235
    bos.set_bpos(this);
sl@0
   236
}
sl@0
   237
sl@0
   238
template<class Archive, class T>
sl@0
   239
struct save_non_pointer_type {
sl@0
   240
    // note this bounces the call right back to the archive
sl@0
   241
    // with no runtime overhead
sl@0
   242
    struct save_primitive {
sl@0
   243
        static void invoke(Archive & ar, const T & t){
sl@0
   244
            save_access::save_primitive(ar, t);
sl@0
   245
        }
sl@0
   246
    };
sl@0
   247
    // same as above but passes through serialization
sl@0
   248
    struct save_only {
sl@0
   249
        static void invoke(Archive & ar, const T & t){
sl@0
   250
            // make sure call is routed through the highest interface that might
sl@0
   251
            // be specialized by the user.
sl@0
   252
            boost::serialization::serialize_adl(
sl@0
   253
                ar, 
sl@0
   254
                const_cast<T &>(t), 
sl@0
   255
                ::boost::serialization::version<T>::value
sl@0
   256
            );
sl@0
   257
        }
sl@0
   258
    };
sl@0
   259
    // adds class information to the archive. This includes
sl@0
   260
    // serialization level and class version
sl@0
   261
    struct save_standard {
sl@0
   262
        static void invoke(Archive &ar, const T & t){
sl@0
   263
            ar.save_object(& t, oserializer<Archive, T>::instantiate());
sl@0
   264
        }
sl@0
   265
    };
sl@0
   266
sl@0
   267
    // adds class information to the archive. This includes
sl@0
   268
    // serialization level and class version
sl@0
   269
    struct save_conditional {
sl@0
   270
        static void invoke(Archive &ar, const T &t){
sl@0
   271
            //if(0 == (ar.get_flags() & no_tracking))
sl@0
   272
                save_standard::invoke(ar, t);
sl@0
   273
            //else
sl@0
   274
            //   save_only::invoke(ar, t);
sl@0
   275
        }
sl@0
   276
    };
sl@0
   277
sl@0
   278
    typedef 
sl@0
   279
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   280
        // if its primitive
sl@0
   281
            mpl::equal_to<
sl@0
   282
                boost::serialization::implementation_level<T>,
sl@0
   283
                mpl::int_<boost::serialization::primitive_type>
sl@0
   284
            >,
sl@0
   285
            mpl::identity<save_primitive>,
sl@0
   286
        // else
sl@0
   287
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   288
            // class info / version
sl@0
   289
            mpl::greater_equal<
sl@0
   290
                boost::serialization::implementation_level<T>,
sl@0
   291
                mpl::int_<boost::serialization::object_class_info>
sl@0
   292
            >,
sl@0
   293
            // do standard save
sl@0
   294
            mpl::identity<save_standard>,
sl@0
   295
        // else
sl@0
   296
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   297
                // no tracking
sl@0
   298
            mpl::equal_to<
sl@0
   299
                boost::serialization::tracking_level<T>,
sl@0
   300
                mpl::int_<boost::serialization::track_never>
sl@0
   301
            >,
sl@0
   302
            // do a fast save
sl@0
   303
            mpl::identity<save_only>,
sl@0
   304
        // else
sl@0
   305
            // do a fast save only tracking is turned off
sl@0
   306
            mpl::identity<save_conditional>
sl@0
   307
    > > >::type typex; 
sl@0
   308
sl@0
   309
    static void invoke(Archive & ar, const T & t){
sl@0
   310
        // check that we're not trying to serialize something that
sl@0
   311
        // has been marked not to be serialized.  If this your program
sl@0
   312
        // traps here, you've tried to serialize a class whose trait
sl@0
   313
        // has been marked "non-serializable". Either reset the trait
sl@0
   314
        // (see level.hpp) or change program not to serialize items of this class
sl@0
   315
        BOOST_STATIC_ASSERT((
sl@0
   316
            mpl::greater_equal<
sl@0
   317
                boost::serialization::implementation_level<T>, 
sl@0
   318
                mpl::int_<boost::serialization::primitive_type>
sl@0
   319
            >::value
sl@0
   320
        ));
sl@0
   321
        typex::invoke(ar, t);
sl@0
   322
    };
sl@0
   323
};
sl@0
   324
sl@0
   325
template<class Archive, class TPtr>
sl@0
   326
struct save_pointer_type {
sl@0
   327
    template<class T>
sl@0
   328
    struct abstract
sl@0
   329
    {
sl@0
   330
        static const basic_pointer_oserializer * register_type(Archive & /* ar */){
sl@0
   331
            // it has? to be polymorphic
sl@0
   332
            BOOST_STATIC_ASSERT(
sl@0
   333
                boost::serialization::type_info_implementation<T>::type::is_polymorphic::value
sl@0
   334
            );
sl@0
   335
            return static_cast<const basic_pointer_oserializer *>(NULL);
sl@0
   336
        }
sl@0
   337
    };
sl@0
   338
sl@0
   339
    template<class T>
sl@0
   340
    struct non_abstract
sl@0
   341
    {
sl@0
   342
        static const basic_pointer_oserializer * register_type(Archive & ar){
sl@0
   343
            return ar.register_type(static_cast<T *>(NULL));
sl@0
   344
        }
sl@0
   345
    };
sl@0
   346
sl@0
   347
    template<class T>
sl@0
   348
    static const basic_pointer_oserializer * register_type(Archive &ar, T & /*t*/){
sl@0
   349
        // there should never be any need to save an abstract polymorphic 
sl@0
   350
        // class pointer.  Inhibiting code generation for this
sl@0
   351
        // permits abstract base classes to be used - note: exception
sl@0
   352
        // virtual serialize functions used for plug-ins
sl@0
   353
        typedef 
sl@0
   354
            BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   355
                serialization::is_abstract<T>,
sl@0
   356
                mpl::identity<abstract<T> >,
sl@0
   357
                mpl::identity<non_abstract<T> >       
sl@0
   358
            >::type typex;
sl@0
   359
        return typex::register_type(ar);
sl@0
   360
    }
sl@0
   361
sl@0
   362
    template<class T>
sl@0
   363
    struct non_polymorphic
sl@0
   364
    {
sl@0
   365
        static void save(
sl@0
   366
            Archive &ar, 
sl@0
   367
            const T & t, 
sl@0
   368
            const basic_pointer_oserializer * bpos_ptr
sl@0
   369
        ){
sl@0
   370
            // save the requested pointer type
sl@0
   371
            ar.save_pointer(& t, bpos_ptr);
sl@0
   372
        }
sl@0
   373
    };
sl@0
   374
sl@0
   375
    template<class T>
sl@0
   376
    struct polymorphic
sl@0
   377
    {
sl@0
   378
        static void save(
sl@0
   379
            Archive &ar, 
sl@0
   380
            const T & t, 
sl@0
   381
            const basic_pointer_oserializer * bpos_ptr
sl@0
   382
        ){
sl@0
   383
            const boost::serialization::extended_type_info * this_type
sl@0
   384
                = boost::serialization::type_info_implementation<T>::type::get_instance();
sl@0
   385
            // retrieve the true type of the object pointed to
sl@0
   386
            // if this assertion fails its an error in this library
sl@0
   387
            assert(NULL != this_type);
sl@0
   388
            const boost::serialization::extended_type_info * true_type 
sl@0
   389
                = boost::serialization::type_info_implementation<T>::type::get_derived_extended_type_info(t);
sl@0
   390
            // note:if this exception is thrown, be sure that derived pointer
sl@0
   391
            // is either regsitered or exported.
sl@0
   392
            if(NULL == true_type){
sl@0
   393
                boost::throw_exception(
sl@0
   394
                    archive_exception(archive_exception::unregistered_class)
sl@0
   395
                );
sl@0
   396
            }
sl@0
   397
sl@0
   398
            // if its not a pointer to a more derived type
sl@0
   399
            const void *vp = static_cast<const void *>(&t);
sl@0
   400
            if(*this_type == *true_type){
sl@0
   401
                ar.save_pointer(vp, bpos_ptr);
sl@0
   402
                return;
sl@0
   403
            }
sl@0
   404
            // convert pointer to more derived type. if this is thrown
sl@0
   405
            // it means that the base/derived relationship hasn't be registered
sl@0
   406
            vp = serialization::void_downcast(*true_type, *this_type, &t);
sl@0
   407
            if(NULL == vp){
sl@0
   408
                boost::throw_exception(
sl@0
   409
                    archive_exception(archive_exception::unregistered_cast)
sl@0
   410
                );
sl@0
   411
            }
sl@0
   412
sl@0
   413
            // sice true_type is valid, and this only gets made if the 
sl@0
   414
            // pointer oserializer object has been created, this should never
sl@0
   415
            // fail
sl@0
   416
            bpos_ptr = archive_pointer_oserializer<Archive>::find(* true_type);
sl@0
   417
            assert(NULL != bpos_ptr);
sl@0
   418
            if(NULL == bpos_ptr)
sl@0
   419
                boost::throw_exception(
sl@0
   420
                    archive_exception(archive_exception::unregistered_class)
sl@0
   421
                );
sl@0
   422
            ar.save_pointer(vp, bpos_ptr);
sl@0
   423
        }
sl@0
   424
    };
sl@0
   425
sl@0
   426
    template<class T>
sl@0
   427
    static void save(
sl@0
   428
        Archive & ar, 
sl@0
   429
        const T &t,
sl@0
   430
        const basic_pointer_oserializer * bpos_ptr
sl@0
   431
    ){
sl@0
   432
        typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<
sl@0
   433
            BOOST_DEDUCED_TYPENAME boost::serialization::
sl@0
   434
                type_info_implementation<T>::type::is_polymorphic,
sl@0
   435
            mpl::identity<polymorphic<T> >,
sl@0
   436
            mpl::identity<non_polymorphic<T> >
sl@0
   437
        >::type typey;
sl@0
   438
        typey::save(ar, const_cast<T &>(t), bpos_ptr);
sl@0
   439
    }
sl@0
   440
sl@0
   441
    template<class T>
sl@0
   442
    static void const_check(T & t){
sl@0
   443
        BOOST_STATIC_ASSERT(! boost::is_const<T>::value);
sl@0
   444
    }
sl@0
   445
sl@0
   446
    static void invoke(Archive &ar, const TPtr t){
sl@0
   447
        #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
   448
            // if your program traps here, its because you tried to do
sl@0
   449
            // something like ar << t where t is a pointer to a const value
sl@0
   450
            // void f3(A const* a, text_oarchive& oa)
sl@0
   451
            // {
sl@0
   452
            //     oa << a;
sl@0
   453
            // }
sl@0
   454
            // with a compiler which doesn't support remove_const
sl@0
   455
            // const_check(* t);
sl@0
   456
        #else
sl@0
   457
            // otherwise remove the const
sl@0
   458
        #endif
sl@0
   459
        const basic_pointer_oserializer * bpos_ptr =  register_type(ar, * t);
sl@0
   460
        if(NULL == t){
sl@0
   461
            basic_oarchive & boa = boost::smart_cast_reference<basic_oarchive &>(ar);
sl@0
   462
            boa.save_null_pointer();
sl@0
   463
            save_access::end_preamble(ar);
sl@0
   464
            return;
sl@0
   465
        }
sl@0
   466
        save(ar, * t, bpos_ptr);
sl@0
   467
    };
sl@0
   468
};
sl@0
   469
sl@0
   470
template<class Archive, class T>
sl@0
   471
struct save_enum_type
sl@0
   472
{
sl@0
   473
    static void invoke(Archive &ar, const T &t){
sl@0
   474
        // convert enum to integers on save
sl@0
   475
        const int i = static_cast<int>(t);
sl@0
   476
        ar << boost::serialization::make_nvp(NULL, i);
sl@0
   477
    }
sl@0
   478
};
sl@0
   479
sl@0
   480
template<class Archive, class T>
sl@0
   481
struct save_array_type
sl@0
   482
{
sl@0
   483
    static void invoke(Archive &ar, const T &t){
sl@0
   484
        save_access::end_preamble(ar);
sl@0
   485
        // consider alignment
sl@0
   486
        int count = sizeof(t) / (
sl@0
   487
            static_cast<const char *>(static_cast<const void *>(&t[1])) 
sl@0
   488
            - static_cast<const char *>(static_cast<const void *>(&t[0]))
sl@0
   489
        );
sl@0
   490
        ar << BOOST_SERIALIZATION_NVP(count);
sl@0
   491
        int i;
sl@0
   492
        for(i = 0; i < count; ++i)
sl@0
   493
            ar << boost::serialization::make_nvp("item", t[i]);
sl@0
   494
    }
sl@0
   495
};
sl@0
   496
sl@0
   497
// note bogus arguments to workaround msvc 6 silent runtime failure
sl@0
   498
// declaration to satisfy gcc
sl@0
   499
template<class Archive, class T>
sl@0
   500
BOOST_DLLEXPORT const basic_pointer_oserializer &
sl@0
   501
instantiate_pointer_oserializer(
sl@0
   502
    Archive * /* ar = NULL */,
sl@0
   503
    T * /* t = NULL */
sl@0
   504
) BOOST_USED ;
sl@0
   505
// definition
sl@0
   506
template<class Archive, class T>
sl@0
   507
BOOST_DLLEXPORT const basic_pointer_oserializer &
sl@0
   508
instantiate_pointer_oserializer(
sl@0
   509
    Archive * /* ar = NULL */,
sl@0
   510
    T * /* t = NULL */
sl@0
   511
){
sl@0
   512
    // note: reversal of order of arguments to work around msvc 6.0 bug
sl@0
   513
    // that manifests itself while trying to link.
sl@0
   514
    return pointer_oserializer<T, Archive>::instantiate();
sl@0
   515
}
sl@0
   516
sl@0
   517
} // detail
sl@0
   518
sl@0
   519
template<class Archive, class T>
sl@0
   520
inline void save(Archive & ar, const T &t){
sl@0
   521
    typedef 
sl@0
   522
        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer<T>,
sl@0
   523
            mpl::identity<detail::save_pointer_type<Archive, T> >,
sl@0
   524
        //else
sl@0
   525
        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum<T>,
sl@0
   526
            mpl::identity<detail::save_enum_type<Archive, T> >,
sl@0
   527
        //else
sl@0
   528
        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array<T>,
sl@0
   529
            mpl::identity<detail::save_array_type<Archive, T> >,
sl@0
   530
        //else
sl@0
   531
            mpl::identity<detail::save_non_pointer_type<Archive, T> >
sl@0
   532
        >
sl@0
   533
        >
sl@0
   534
        >::type typex;
sl@0
   535
    typex::invoke(ar, t);
sl@0
   536
}
sl@0
   537
sl@0
   538
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
sl@0
   539
sl@0
   540
template<class T>
sl@0
   541
struct check_tracking {
sl@0
   542
    typedef BOOST_DEDUCED_TYPENAME mpl::if_<
sl@0
   543
        // if its never tracked.
sl@0
   544
        BOOST_DEDUCED_TYPENAME mpl::equal_to<
sl@0
   545
            serialization::tracking_level<T>,
sl@0
   546
            mpl::int_<serialization::track_never>
sl@0
   547
        >,
sl@0
   548
        // it better not be a pointer
sl@0
   549
        mpl::not_<is_pointer<T> >,
sl@0
   550
    //else
sl@0
   551
        // otherwise if it might be tracked.  So there shouldn't
sl@0
   552
        // be any problem making a const
sl@0
   553
        is_const<T>
sl@0
   554
    >::type typex;
sl@0
   555
    BOOST_STATIC_CONSTANT(bool, value = typex::value);
sl@0
   556
};
sl@0
   557
sl@0
   558
template<class Archive, class T>
sl@0
   559
inline void save(Archive & ar, T &t){
sl@0
   560
    // if your program traps here, it indicates taht your doing one of the following:
sl@0
   561
    // a) serializing an object of a type marked "track_never" through a pointer.
sl@0
   562
    // b) saving an non-const object of a type not markd "track_never)
sl@0
   563
    // Either of these conditions may be an indicator of an error usage of the
sl@0
   564
    // serialization library and should be double checked.  See documentation on
sl@0
   565
    // object tracking.
sl@0
   566
    BOOST_STATIC_ASSERT(check_tracking<T>::value);
sl@0
   567
        save(ar, const_cast<const T &>(t));
sl@0
   568
}
sl@0
   569
#endif
sl@0
   570
sl@0
   571
} // namespace archive
sl@0
   572
} // namespace boost
sl@0
   573
sl@0
   574
#endif // BOOST_ARCHIVE_OSERIALIZER_HPP