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