File indexing completed on 2025-01-18 09:28:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <ostream>
0010 #include <iomanip>
0011 #include <algorithm> // std::copy
0012 #include <string>
0013
0014 #include <cstring> // strlen
0015 #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
0016 #if defined(BOOST_NO_STDC_NAMESPACE)
0017 namespace std{
0018 using ::strlen;
0019 }
0020 #endif
0021
0022 #include <boost/core/uncaught_exceptions.hpp>
0023 #include <boost/archive/iterators/xml_escape.hpp>
0024 #include <boost/archive/iterators/ostream_iterator.hpp>
0025
0026 #ifndef BOOST_NO_CWCHAR
0027 #include <boost/archive/wcslen.hpp>
0028 #include <boost/archive/iterators/mb_from_wchar.hpp>
0029 #endif
0030
0031 namespace boost {
0032 namespace archive {
0033
0034
0035
0036
0037
0038 #ifndef BOOST_NO_CWCHAR
0039
0040 template<class InputIterator>
0041 void save_iterator(std::ostream &os, InputIterator begin, InputIterator end){
0042 typedef boost::archive::iterators::mb_from_wchar<
0043 boost::archive::iterators::xml_escape<InputIterator>
0044 > translator;
0045 std::copy(
0046 translator(begin),
0047 translator(end),
0048 boost::archive::iterators::ostream_iterator<char>(os)
0049 );
0050 }
0051
0052 #ifndef BOOST_NO_STD_WSTRING
0053 template<class Archive>
0054 BOOST_ARCHIVE_DECL void
0055 xml_oarchive_impl<Archive>::save(const std::wstring & ws){
0056
0057
0058
0059 save_iterator(os, ws.data(), ws.data() + ws.size());
0060 }
0061 #endif
0062
0063 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0064 template<class Archive>
0065 BOOST_ARCHIVE_DECL void
0066 xml_oarchive_impl<Archive>::save(const wchar_t * ws){
0067 save_iterator(os, ws, ws + std::wcslen(ws));
0068 }
0069 #endif
0070
0071 #endif
0072
0073 template<class Archive>
0074 BOOST_ARCHIVE_DECL void
0075 xml_oarchive_impl<Archive>::save(const std::string & s){
0076
0077
0078 typedef boost::archive::iterators::xml_escape<
0079 const char *
0080 > xml_escape_translator;
0081 std::copy(
0082 xml_escape_translator(s.data()),
0083 xml_escape_translator(s.data()+ s.size()),
0084 boost::archive::iterators::ostream_iterator<char>(os)
0085 );
0086 }
0087
0088 template<class Archive>
0089 BOOST_ARCHIVE_DECL void
0090 xml_oarchive_impl<Archive>::save(const char * s){
0091 typedef boost::archive::iterators::xml_escape<
0092 const char *
0093 > xml_escape_translator;
0094 std::copy(
0095 xml_escape_translator(s),
0096 xml_escape_translator(s + std::strlen(s)),
0097 boost::archive::iterators::ostream_iterator<char>(os)
0098 );
0099 }
0100
0101 template<class Archive>
0102 BOOST_ARCHIVE_DECL
0103 xml_oarchive_impl<Archive>::xml_oarchive_impl(
0104 std::ostream & os_,
0105 unsigned int flags
0106 ) :
0107 basic_text_oprimitive<std::ostream>(
0108 os_,
0109 0 != (flags & no_codecvt)
0110 ),
0111 basic_xml_oarchive<Archive>(flags)
0112 {}
0113
0114 template<class Archive>
0115 BOOST_ARCHIVE_DECL void
0116 xml_oarchive_impl<Archive>::save_binary(const void *address, std::size_t count){
0117 this->end_preamble();
0118 #if ! defined(__MWERKS__)
0119 this->basic_text_oprimitive<std::ostream>::save_binary(
0120 #else
0121 this->basic_text_oprimitive::save_binary(
0122 #endif
0123 address,
0124 count
0125 );
0126 this->indent_next = true;
0127 }
0128
0129 template<class Archive>
0130 BOOST_ARCHIVE_DECL
0131 xml_oarchive_impl<Archive>::~xml_oarchive_impl(){
0132 if(boost::core::uncaught_exceptions() > 0)
0133 return;
0134 if(0 == (this->get_flags() & no_header)){
0135 this->put("</boost_serialization>\n");
0136 }
0137 }
0138
0139 }
0140 }