Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/serialization/nvp.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

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