1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // xml_oarchive_impl.ipp:
4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
11 #include <algorithm> // std::copy
15 #include <cstring> // strlen
16 #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
17 #if defined(BOOST_NO_STDC_NAMESPACE)
23 #include <boost/archive/iterators/xml_escape.hpp>
24 #include <boost/archive/iterators/ostream_iterator.hpp>
26 #ifndef BOOST_NO_CWCHAR
27 #include <boost/archive/wcslen.hpp>
28 #include <boost/archive/iterators/mb_from_wchar.hpp>
34 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
35 // implemenations of functions specific to char archives
37 // wide char stuff used by char archives
38 #ifndef BOOST_NO_CWCHAR
39 // copy chars to output escaping to xml and translating wide chars to mb chars
40 template<class InputIterator>
41 void save_iterator(std::ostream &os, InputIterator begin, InputIterator end){
42 typedef boost::archive::iterators::mb_from_wchar<
43 boost::archive::iterators::xml_escape<InputIterator>
48 boost::archive::iterators::ostream_iterator<char>(os)
52 #ifndef BOOST_NO_STD_WSTRING
53 template<class Archive>
54 BOOST_ARCHIVE_DECL void
55 xml_oarchive_impl<Archive>::save(const std::wstring & ws){
56 // at least one library doesn't typedef value_type for strings
57 // so rather than using string directly make a pointer iterator out of it
58 // save_iterator(os, ws.data(), ws.data() + std::wcslen(ws.data()));
59 save_iterator(os, ws.data(), ws.data() + ws.size());
63 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
64 template<class Archive>
65 BOOST_ARCHIVE_DECL void
66 xml_oarchive_impl<Archive>::save(const wchar_t * ws){
67 save_iterator(os, ws, ws + std::wcslen(ws));
71 #endif // BOOST_NO_CWCHAR
73 template<class Archive>
74 BOOST_ARCHIVE_DECL void
75 xml_oarchive_impl<Archive>::save(const std::string & s){
76 // at least one library doesn't typedef value_type for strings
77 // so rather than using string directly make a pointer iterator out of it
78 typedef boost::archive::iterators::xml_escape<
80 > xml_escape_translator;
82 xml_escape_translator(s.data()),
83 xml_escape_translator(s.data()+ s.size()),
84 boost::archive::iterators::ostream_iterator<char>(os)
88 template<class Archive>
89 BOOST_ARCHIVE_DECL void
90 xml_oarchive_impl<Archive>::save(const char * s){
91 typedef boost::archive::iterators::xml_escape<
93 > xml_escape_translator;
95 xml_escape_translator(s),
96 xml_escape_translator(s + std::strlen(s)),
97 boost::archive::iterators::ostream_iterator<char>(os)
101 template<class Archive>
103 xml_oarchive_impl<Archive>::xml_oarchive_impl(
107 basic_text_oprimitive<std::ostream>(
109 0 != (flags & no_codecvt)
111 basic_xml_oarchive<Archive>(flags)
113 if(0 == (flags & no_header))
117 template<class Archive>
118 BOOST_ARCHIVE_DECL void
119 xml_oarchive_impl<Archive>::save_binary(const void *address, std::size_t count){
120 this->end_preamble();
121 #if ! defined(__MWERKS__)
122 this->basic_text_oprimitive<std::ostream>::save_binary(
124 this->basic_text_oprimitive::save_binary(
129 this->indent_next = true;
132 template<class Archive>
134 xml_oarchive_impl<Archive>::~xml_oarchive_impl(){
135 if(std::uncaught_exception())
137 if(0 == (this->get_flags() & no_header))
141 } // namespace archive