Chris@16
|
1 #ifndef BOOST_ARCHIVE_BASIC_XML_OARCHIVE_HPP
|
Chris@16
|
2 #define BOOST_ARCHIVE_BASIC_XML_OARCHIVE_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 // basic_xml_oarchive.hpp
|
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 <boost/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/archive/detail/common_oarchive.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/serialization/nvp.hpp>
|
Chris@16
|
24 #include <boost/serialization/tracking.hpp>
|
Chris@16
|
25 #include <boost/serialization/string.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/mpl/assert.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header
|
Chris@16
|
30
|
Chris@16
|
31 #ifdef BOOST_MSVC
|
Chris@16
|
32 # pragma warning(push)
|
Chris@16
|
33 # pragma warning(disable : 4511 4512)
|
Chris@16
|
34 #endif
|
Chris@16
|
35
|
Chris@16
|
36 namespace boost {
|
Chris@16
|
37 namespace archive {
|
Chris@16
|
38
|
Chris@16
|
39 //////////////////////////////////////////////////////////////////////
|
Chris@16
|
40 // class basic_xml_oarchive - write serialized objects to a xml output stream
|
Chris@16
|
41 template<class Archive>
|
Chris@16
|
42 class basic_xml_oarchive :
|
Chris@16
|
43 public detail::common_oarchive<Archive>
|
Chris@16
|
44 {
|
Chris@16
|
45 protected:
|
Chris@16
|
46 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
Chris@16
|
47 public:
|
Chris@16
|
48 #elif defined(BOOST_MSVC)
|
Chris@16
|
49 // for some inexplicable reason insertion of "class" generates compile erro
|
Chris@16
|
50 // on msvc 7.1
|
Chris@16
|
51 friend detail::interface_oarchive<Archive>;
|
Chris@16
|
52 friend class save_access;
|
Chris@16
|
53 #else
|
Chris@16
|
54 friend class detail::interface_oarchive<Archive>;
|
Chris@16
|
55 friend class save_access;
|
Chris@16
|
56 #endif
|
Chris@16
|
57 // special stuff for xml output
|
Chris@16
|
58 unsigned int depth;
|
Chris@16
|
59 bool indent_next;
|
Chris@16
|
60 bool pending_preamble;
|
Chris@16
|
61 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
62 indent();
|
Chris@16
|
63 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
64 init();
|
Chris@16
|
65 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
66 write_attribute(
|
Chris@16
|
67 const char *attribute_name,
|
Chris@16
|
68 int t,
|
Chris@16
|
69 const char *conjunction = "=\""
|
Chris@16
|
70 );
|
Chris@16
|
71 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
72 write_attribute(
|
Chris@16
|
73 const char *attribute_name,
|
Chris@16
|
74 const char *key
|
Chris@16
|
75 );
|
Chris@16
|
76 // helpers used below
|
Chris@16
|
77 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
78 save_start(const char *name);
|
Chris@16
|
79 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
80 save_end(const char *name);
|
Chris@16
|
81 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
82 end_preamble();
|
Chris@16
|
83
|
Chris@16
|
84 // Anything not an attribute and not a name-value pair is an
|
Chris@16
|
85 // error and should be trapped here.
|
Chris@16
|
86 template<class T>
|
Chris@16
|
87 void save_override(T & t, BOOST_PFTO int)
|
Chris@16
|
88 {
|
Chris@16
|
89 // If your program fails to compile here, its most likely due to
|
Chris@16
|
90 // not specifying an nvp wrapper around the variable to
|
Chris@16
|
91 // be serialized.
|
Chris@16
|
92 BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
|
Chris@16
|
93 this->detail_common_oarchive::save_override(t, 0);
|
Chris@16
|
94 }
|
Chris@16
|
95
|
Chris@16
|
96 // special treatment for name-value pairs.
|
Chris@16
|
97 typedef detail::common_oarchive<Archive> detail_common_oarchive;
|
Chris@16
|
98 template<class T>
|
Chris@16
|
99 void save_override(
|
Chris@16
|
100 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
Chris@16
|
101 const
|
Chris@16
|
102 #endif
|
Chris@16
|
103 ::boost::serialization::nvp< T > & t,
|
Chris@16
|
104 int
|
Chris@16
|
105 ){
|
Chris@16
|
106 this->This()->save_start(t.name());
|
Chris@16
|
107 this->detail_common_oarchive::save_override(t.const_value(), 0);
|
Chris@16
|
108 this->This()->save_end(t.name());
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 // specific overrides for attributes - not name value pairs so we
|
Chris@16
|
112 // want to trap them before the above "fall through"
|
Chris@16
|
113 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
114 save_override(const object_id_type & t, int);
|
Chris@16
|
115 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
116 save_override(const object_reference_type & t, int);
|
Chris@16
|
117 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
118 save_override(const version_type & t, int);
|
Chris@16
|
119 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
120 save_override(const class_id_type & t, int);
|
Chris@16
|
121 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
122 save_override(const class_id_optional_type & t, int);
|
Chris@16
|
123 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
124 save_override(const class_id_reference_type & t, int);
|
Chris@16
|
125 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
126 save_override(const class_name_type & t, int);
|
Chris@16
|
127 BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
Chris@16
|
128 save_override(const tracking_type & t, int);
|
Chris@16
|
129
|
Chris@16
|
130 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
Chris@16
|
131 basic_xml_oarchive(unsigned int flags);
|
Chris@16
|
132 BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
Chris@16
|
133 ~basic_xml_oarchive();
|
Chris@16
|
134 };
|
Chris@16
|
135
|
Chris@16
|
136 } // namespace archive
|
Chris@16
|
137 } // namespace boost
|
Chris@16
|
138
|
Chris@16
|
139 #ifdef BOOST_MSVC
|
Chris@16
|
140 #pragma warning(pop)
|
Chris@16
|
141 #endif
|
Chris@16
|
142
|
Chris@16
|
143 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
|
Chris@16
|
144
|
Chris@16
|
145 #endif // BOOST_ARCHIVE_BASIC_XML_OARCHIVE_HPP
|