1 #ifndef BOOST_SERIALIZATION_NVP_HPP
2 #define BOOST_SERIALIZATION_NVP_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
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 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
25 # pragma warning (disable : 4786) // too long name, harmless warning
28 #include <boost/mpl/integral_c.hpp>
29 #include <boost/mpl/integral_c_tag.hpp>
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>
38 namespace serialization {
42 public std::pair<const char *, T *>,
43 public traits<nvp<T>, object_serializable, track_never>
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))
49 nvp(const nvp & rhs) :
50 // note: redundant cast works around borland issue
51 std::pair<const char *, T *>(rhs.first, (T*)rhs.second)
54 const char * name() const {
58 return *(this->second);
61 const T & const_value() const {
62 return *(this->second);
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>
74 const unsigned int /* file_version */
76 // CodeWarrior 8.x can't seem to resolve the << op for a rhs of "const T *"
77 ar.operator<<(const_value());
79 template<class Archivex>
82 const unsigned int /* file_version */
84 // CodeWarrior 8.x can't seem to resolve the >> op for a rhs of "const T *"
85 ar.operator>>(value());
87 BOOST_SERIALIZATION_SPLIT_MEMBER()
92 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
95 nvp<T> make_nvp(const char * name, T & t){
96 return nvp<T>(name, t);
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
108 struct implementation_level<nvp<T> >
110 typedef mpl::integral_c_tag tag;
111 typedef mpl::int_<object_serializable> type;
112 BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value);
115 // nvp objects are generally created on the stack and are never tracked
117 struct tracking_level<nvp<T> >
119 typedef mpl::integral_c_tag tag;
120 typedef mpl::int_<track_never> type;
121 BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
129 #include <boost/preprocessor/stringize.hpp>
131 #define BOOST_SERIALIZATION_NVP(name) \
132 boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name)
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) \
142 #endif // BOOST_SERIALIZATION_NVP_HPP