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