source: NonGTP/Boost/boost/archive/basic_xml_oarchive.hpp @ 857

Revision 857, 4.5 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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) && (_MSC_VER >= 1020)
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
21#include <boost/archive/detail/oserializer.hpp>
22#include <boost/archive/detail/interface_oarchive.hpp>
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#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
30
31namespace boost {
32namespace archive {
33       
34//////////////////////////////////////////////////////////////////////
35// class xml_oarchive - write serialized objects to a xml output stream
36template<class Archive>
37class basic_xml_oarchive :
38    public detail::common_oarchive<Archive>
39{
40#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
41public:
42#elif defined(BOOST_MSVC)
43    // for some inexplicable reason insertion of "class" generates compile erro
44    // on msvc 7.1
45    friend detail::interface_oarchive<Archive>;
46protected:
47#else
48    friend class detail::interface_oarchive<Archive>;
49protected:
50#endif
51    // special stuff for xml output
52    unsigned int depth;
53    bool indent_next;
54    bool pending_preamble;
55    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
56    indent();
57    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
58    init();
59    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
60    write_attribute(
61        const char *attribute_name,
62        int t,
63        const char *conjunction = "=\""
64    );
65    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
66    write_attribute(
67        const char *attribute_name,
68        const char *key
69    );
70    // helpers used below
71    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
72    save_start(const char *name);
73    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
74    save_end(const char *name);
75    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
76    end_preamble();
77
78    // Anything not an attribute and not a name-value pair is an
79    // error and should be trapped here.
80    template<class T>
81    void save_override(T & t, BOOST_PFTO int)
82    {
83        // If your program fails to compile here, its most likely due to
84        // not specifying an nvp wrapper around the variable to
85        // be serialized.
86        BOOST_STATIC_ASSERT(0 == sizeof(T));
87    }
88
89   // special treatment for name-value pairs.
90    template<class T>
91    void save_override(
92                #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
93                const
94                #endif
95                ::boost::serialization::nvp<T> & t,
96                int
97        ){
98        this->This()->save_start(t.name());
99        archive::save(* this->This(), t.const_value());
100        this->This()->save_end(t.name());
101    }
102
103    // specific overrides for attributes - not name value pairs so we
104    // want to trap them before the above "fall through"
105    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
106    save_override(const object_id_type & t, int);
107    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
108    save_override(const object_reference_type & t, int);
109    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
110    save_override(const version_type & t, int);
111    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
112    save_override(const class_id_type & t, int);
113    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
114    save_override(const class_id_optional_type & t, int);
115    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
116    save_override(const class_id_reference_type & t, int);
117    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
118    save_override(const class_name_type & t, int);
119    BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
120    save_override(const tracking_type & t, int);
121
122    BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
123    basic_xml_oarchive(unsigned int flags);
124    BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
125    ~basic_xml_oarchive();
126};
127
128} // namespace archive
129} // namespace boost
130
131#include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
132
133#endif // BOOST_ARCHIVE_BASIC_XML_OARCHIVE_HPP
Note: See TracBrowser for help on using the repository browser.