os/ossrv/ossrv_pub/boost_apis/boost/serialization/nvp.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_SERIALIZATION_NVP_HPP
sl@0
     2
#define BOOST_SERIALIZATION_NVP_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
#endif
sl@0
     8
sl@0
     9
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
sl@0
    10
// nvp.hpp: interface for serialization system.
sl@0
    11
sl@0
    12
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
sl@0
    13
// Use, modification and distribution is subject to the Boost Software
sl@0
    14
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
    15
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    16
sl@0
    17
//  See http://www.boost.org for updates, documentation, and revision history.
sl@0
    18
sl@0
    19
#include <utility>
sl@0
    20
sl@0
    21
#include <boost/config.hpp>
sl@0
    22
#include <boost/detail/workaround.hpp>
sl@0
    23
// supress noise
sl@0
    24
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
sl@0
    25
# pragma warning (disable : 4786) // too long name, harmless warning
sl@0
    26
#endif
sl@0
    27
sl@0
    28
#include <boost/mpl/integral_c.hpp>
sl@0
    29
#include <boost/mpl/integral_c_tag.hpp>
sl@0
    30
sl@0
    31
#include <boost/serialization/level.hpp>
sl@0
    32
#include <boost/serialization/tracking.hpp>
sl@0
    33
#include <boost/serialization/split_member.hpp>
sl@0
    34
#include <boost/serialization/base_object.hpp>
sl@0
    35
#include <boost/serialization/traits.hpp>
sl@0
    36
sl@0
    37
namespace boost {
sl@0
    38
namespace serialization {
sl@0
    39
sl@0
    40
template<class T>
sl@0
    41
struct nvp : 
sl@0
    42
    public std::pair<const char *, T *>,
sl@0
    43
    public traits<nvp<T>, object_serializable, track_never>
sl@0
    44
{
sl@0
    45
    explicit nvp(const char * name, T & t) :
sl@0
    46
        // note: redundant cast works around borland issue
sl@0
    47
        std::pair<const char *, T *>(name, (T*)(& t))
sl@0
    48
    {}
sl@0
    49
    nvp(const nvp & rhs) : 
sl@0
    50
        // note: redundant cast works around borland issue
sl@0
    51
        std::pair<const char *, T *>(rhs.first, (T*)rhs.second)
sl@0
    52
    {}
sl@0
    53
sl@0
    54
    const char * name() const {
sl@0
    55
        return this->first;
sl@0
    56
    }
sl@0
    57
    T & value() const {
sl@0
    58
        return *(this->second);
sl@0
    59
    }
sl@0
    60
sl@0
    61
    const T & const_value() const {
sl@0
    62
        return *(this->second);
sl@0
    63
    }
sl@0
    64
sl@0
    65
    // True64 compiler complains with a warning about the use of
sl@0
    66
    // the name "Archive" hiding some higher level usage.  I'm sure this
sl@0
    67
    // is an error but I want to accomodated as it generates a long warning
sl@0
    68
    // listing and might be related to a lot of test failures.
sl@0
    69
    // default treatment for name-value pairs. The name is
sl@0
    70
    // just discarded and only the value is serialized. 
sl@0
    71
    template<class Archivex>
sl@0
    72
    void save(
sl@0
    73
        Archivex & ar, 
sl@0
    74
        const unsigned int /* file_version */
sl@0
    75
    ) const {
sl@0
    76
        // CodeWarrior 8.x can't seem to resolve the << op for a rhs of "const T *"
sl@0
    77
        ar.operator<<(const_value());
sl@0
    78
    }
sl@0
    79
    template<class Archivex>
sl@0
    80
    void load(
sl@0
    81
        Archivex & ar, 
sl@0
    82
        const unsigned int /* file_version */
sl@0
    83
    ){
sl@0
    84
        // CodeWarrior 8.x can't seem to resolve the >> op for a rhs of "const T *"
sl@0
    85
        ar.operator>>(value());
sl@0
    86
    }
sl@0
    87
    BOOST_SERIALIZATION_SPLIT_MEMBER()
sl@0
    88
};
sl@0
    89
sl@0
    90
template<class T>
sl@0
    91
inline
sl@0
    92
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
sl@0
    93
const
sl@0
    94
#endif
sl@0
    95
nvp<T> make_nvp(const char * name, T & t){
sl@0
    96
    return nvp<T>(name, t);
sl@0
    97
}
sl@0
    98
sl@0
    99
// to maintain efficiency and portability, we want to assign
sl@0
   100
// specific serialization traits to all instances of this wrappers.
sl@0
   101
// we can't strait forward method below as it depends upon
sl@0
   102
// Partial Template Specialization and doing so would mean that wrappers
sl@0
   103
// wouldn't be treated the same on different platforms.  This would
sl@0
   104
// break archive portability. Leave this here as reminder not to use it !!!
sl@0
   105
#if 0 // #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
   106
sl@0
   107
template <class T>
sl@0
   108
struct implementation_level<nvp<T> >
sl@0
   109
{
sl@0
   110
    typedef mpl::integral_c_tag tag;
sl@0
   111
    typedef mpl::int_<object_serializable> type;
sl@0
   112
    BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value);
sl@0
   113
};
sl@0
   114
sl@0
   115
// nvp objects are generally created on the stack and are never tracked
sl@0
   116
template<class T>
sl@0
   117
struct tracking_level<nvp<T> >
sl@0
   118
{
sl@0
   119
    typedef mpl::integral_c_tag tag;
sl@0
   120
    typedef mpl::int_<track_never> type;
sl@0
   121
    BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
sl@0
   122
};
sl@0
   123
sl@0
   124
#endif
sl@0
   125
sl@0
   126
} // seralization
sl@0
   127
} // boost
sl@0
   128
sl@0
   129
#include <boost/preprocessor/stringize.hpp>
sl@0
   130
sl@0
   131
#define BOOST_SERIALIZATION_NVP(name)                              \
sl@0
   132
    boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name)
sl@0
   133
/**/
sl@0
   134
sl@0
   135
#define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name)                  \
sl@0
   136
    boost::serialization::make_nvp(                                \
sl@0
   137
        BOOST_PP_STRINGIZE(name),                                  \
sl@0
   138
        boost::serialization::base_object<name >(*this)            \
sl@0
   139
    )
sl@0
   140
/**/
sl@0
   141
sl@0
   142
#endif // BOOST_SERIALIZATION_NVP_HPP