os/ossrv/ossrv_pub/boost_apis/boost/serialization/optional.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
     2
sl@0
     3
// (C) Copyright 2002-4 Pavel Vozenilek . 
sl@0
     4
// Use, modification and distribution is subject to the Boost Software
sl@0
     5
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
     6
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     7
sl@0
     8
// Provides non-intrusive serialization for boost::optional.
sl@0
     9
sl@0
    10
#ifndef BOOST_SERIALIZATION_OPTIONAL_HPP_
sl@0
    11
#define BOOST_SERIALIZATION_OPTIONAL_HPP_
sl@0
    12
sl@0
    13
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
sl@0
    14
# pragma once
sl@0
    15
#endif
sl@0
    16
sl@0
    17
#include <boost/config.hpp>
sl@0
    18
sl@0
    19
#include <boost/optional.hpp>
sl@0
    20
#include <boost/serialization/split_free.hpp>
sl@0
    21
#include <boost/serialization/level.hpp>
sl@0
    22
#include <boost/serialization/nvp.hpp>
sl@0
    23
#include <boost/serialization/detail/stack_constructor.hpp>
sl@0
    24
sl@0
    25
// function specializations must be defined in the appropriate
sl@0
    26
// namespace - boost::serialization
sl@0
    27
namespace boost { 
sl@0
    28
namespace serialization {
sl@0
    29
sl@0
    30
template<class Archive, class T>
sl@0
    31
void save(
sl@0
    32
    Archive & ar, 
sl@0
    33
    const boost::optional<T> & t, 
sl@0
    34
    const unsigned int /*version*/
sl@0
    35
){
sl@0
    36
    const bool tflag = t.is_initialized();
sl@0
    37
    ar << boost::serialization::make_nvp("initialized", tflag);
sl@0
    38
    if (tflag){
sl@0
    39
        if(3 < ar.get_library_version()){
sl@0
    40
            const int v = version<T>::value;
sl@0
    41
            ar << make_nvp("item_version", v);
sl@0
    42
        }
sl@0
    43
        ar << boost::serialization::make_nvp("value", *t);
sl@0
    44
    }
sl@0
    45
}
sl@0
    46
sl@0
    47
template<class Archive, class T>
sl@0
    48
void load(
sl@0
    49
    Archive & ar, 
sl@0
    50
    boost::optional<T> & t, 
sl@0
    51
    const unsigned int /*version*/
sl@0
    52
){
sl@0
    53
    bool tflag;
sl@0
    54
    ar >> boost::serialization::make_nvp("initialized", tflag);
sl@0
    55
    if (tflag){
sl@0
    56
        unsigned int v;
sl@0
    57
        if(3 < ar.get_library_version()){
sl@0
    58
            ar >> make_nvp("item_version", v);
sl@0
    59
        }
sl@0
    60
        detail::stack_construct<Archive, T> aux(ar, v);
sl@0
    61
        ar >> boost::serialization::make_nvp("value", aux.reference());
sl@0
    62
        t.reset(aux.reference());
sl@0
    63
    }
sl@0
    64
    else {
sl@0
    65
        t.reset();
sl@0
    66
    }
sl@0
    67
}
sl@0
    68
sl@0
    69
template<class Archive, class T>
sl@0
    70
void serialize(
sl@0
    71
    Archive & ar, 
sl@0
    72
    boost::optional<T> & t, 
sl@0
    73
    const unsigned int version
sl@0
    74
){
sl@0
    75
    boost::serialization::split_free(ar, t, version);
sl@0
    76
}
sl@0
    77
sl@0
    78
// the following would be slightly more efficient.  But it
sl@0
    79
// would mean that archives created with programs that support
sl@0
    80
// TPS wouldn't be readable by programs that don't support TPS.
sl@0
    81
// Hence we decline to support this otherwise convenient optimization.
sl@0
    82
//#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
    83
#if 0
sl@0
    84
sl@0
    85
template <class T>
sl@0
    86
struct implementation_level<optional<T> >
sl@0
    87
{
sl@0
    88
    typedef mpl::integral_c_tag tag;
sl@0
    89
    typedef mpl::int_<boost::serialization::object_serializable> type;
sl@0
    90
    BOOST_STATIC_CONSTANT(
sl@0
    91
        int , 
sl@0
    92
        value = boost::serialization::implementation_level::type::value
sl@0
    93
    );
sl@0
    94
};
sl@0
    95
sl@0
    96
template<class T>
sl@0
    97
struct tracking_level<optional<T> >
sl@0
    98
{
sl@0
    99
    typedef mpl::integral_c_tag tag;
sl@0
   100
    typedef mpl::int_<boost::serialization::track_never> type;
sl@0
   101
    BOOST_STATIC_CONSTANT(
sl@0
   102
        int , 
sl@0
   103
        value = boost::serialization::tracking_level::type::value
sl@0
   104
    );
sl@0
   105
};
sl@0
   106
sl@0
   107
#endif
sl@0
   108
sl@0
   109
} // serialization
sl@0
   110
} // namespace boost
sl@0
   111
sl@0
   112
#endif // BOOST_SERIALIZATION_OPTIONAL_HPP_