1 #ifndef BOOST_SERIALIZATION_NVP_HPP
2 #define BOOST_SERIALIZATION_NVP_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // nvp.hpp: interface for serialization system.
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)
17 // See http://www.boost.org for updates, documentation, and revision history.
21 #include <boost/config.hpp>
22 #include <boost/detail/workaround.hpp>
24 #include <boost/serialization/level.hpp>
25 #include <boost/serialization/tracking.hpp>
26 #include <boost/serialization/split_member.hpp>
27 #include <boost/serialization/base_object.hpp>
28 #include <boost/serialization/traits.hpp>
29 #include <boost/serialization/wrapper.hpp>
32 namespace serialization {
36 public std::pair<const char *, T *>,
37 public wrapper_traits<const nvp< T > >
40 nvp(const nvp & rhs) :
41 std::pair<const char *, T *>(rhs.first, rhs.second)
44 explicit nvp(const char * name_, T & t) :
45 // note: added _ to suppress useless gcc warning
46 std::pair<const char *, T *>(name_, & t)
49 const char * name() const {
53 return *(this->second);
56 const T & const_value() const {
57 return *(this->second);
60 template<class Archive>
63 const unsigned int /* file_version */
65 ar.operator<<(const_value());
67 template<class Archive>
70 const unsigned int /* file_version */
72 ar.operator>>(value());
74 BOOST_SERIALIZATION_SPLIT_MEMBER()
79 const nvp< T > make_nvp(const char * name, T & t){
80 return nvp< T >(name, t);
83 // to maintain efficiency and portability, we want to assign
84 // specific serialization traits to all instances of this wrappers.
85 // we can't strait forward method below as it depends upon
86 // Partial Template Specialization and doing so would mean that wrappers
87 // wouldn't be treated the same on different platforms. This would
88 // break archive portability. Leave this here as reminder not to use it !!!
91 struct implementation_level<nvp< T > >
93 typedef mpl::integral_c_tag tag;
94 typedef mpl::int_<object_serializable> type;
95 BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value);
98 // nvp objects are generally created on the stack and are never tracked
100 struct tracking_level<nvp< T > >
102 typedef mpl::integral_c_tag tag;
103 typedef mpl::int_<track_never> type;
104 BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
110 #include <boost/preprocessor/stringize.hpp>
112 #define BOOST_SERIALIZATION_NVP(name) \
113 boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name)
116 #define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name) \
117 boost::serialization::make_nvp( \
118 BOOST_PP_STRINGIZE(name), \
119 boost::serialization::base_object<name >(*this) \
123 #endif // BOOST_SERIALIZATION_NVP_HPP