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