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