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