1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
---|
2 | // xml_oarchive_impl.ipp: |
---|
3 | |
---|
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) |
---|
8 | |
---|
9 | #include <ostream> |
---|
10 | #include <iomanip> |
---|
11 | #include <algorithm> |
---|
12 | #include <string> |
---|
13 | |
---|
14 | #include <cstring> // strlen |
---|
15 | #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings |
---|
16 | #if defined(BOOST_NO_STDC_NAMESPACE) |
---|
17 | namespace std{ |
---|
18 | using ::strlen; |
---|
19 | } // namespace std |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <boost/archive/iterators/xml_escape.hpp> |
---|
23 | #include <boost/archive/iterators/ostream_iterator.hpp> |
---|
24 | |
---|
25 | #ifndef BOOST_NO_CWCHAR |
---|
26 | #include <boost/archive/wcslen.hpp> |
---|
27 | #include <boost/archive/iterators/mb_from_wchar.hpp> |
---|
28 | #endif |
---|
29 | |
---|
30 | namespace boost { |
---|
31 | namespace archive { |
---|
32 | |
---|
33 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
---|
34 | // implemenations of functions specific to char archives |
---|
35 | |
---|
36 | // wide char stuff used by char archives |
---|
37 | #ifndef BOOST_NO_CWCHAR |
---|
38 | // copy chars to output escaping to xml and translating wide chars to mb chars |
---|
39 | template<class InputIterator> |
---|
40 | void save_iterator(std::ostream &os, InputIterator begin, InputIterator end){ |
---|
41 | typedef boost::archive::iterators::mb_from_wchar< |
---|
42 | boost::archive::iterators::xml_escape<InputIterator> |
---|
43 | > translator; |
---|
44 | std::copy( |
---|
45 | translator(BOOST_MAKE_PFTO_WRAPPER(begin)), |
---|
46 | translator(BOOST_MAKE_PFTO_WRAPPER(end)), |
---|
47 | boost::archive::iterators::ostream_iterator<char>(os) |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | #ifndef BOOST_NO_STD_WSTRING |
---|
52 | template<class Archive> |
---|
53 | BOOST_ARCHIVE_DECL(void) |
---|
54 | xml_oarchive_impl<Archive>::save(const std::wstring & ws){ |
---|
55 | // at least one library doesn't typedef value_type for strings |
---|
56 | // so rather than using string directly make a pointer iterator out of it |
---|
57 | // save_iterator(os, ws.data(), ws.data() + std::wcslen(ws.data())); |
---|
58 | save_iterator(os, ws.data(), ws.data() + ws.size()); |
---|
59 | } |
---|
60 | #endif |
---|
61 | |
---|
62 | #ifndef BOOST_NO_INTRINSIC_WCHAR_T |
---|
63 | template<class Archive> |
---|
64 | BOOST_ARCHIVE_DECL(void) |
---|
65 | xml_oarchive_impl<Archive>::save(const wchar_t * ws){ |
---|
66 | save_iterator(os, ws, ws + std::wcslen(ws)); |
---|
67 | } |
---|
68 | #endif |
---|
69 | |
---|
70 | #endif // BOOST_NO_CWCHAR |
---|
71 | |
---|
72 | template<class Archive> |
---|
73 | BOOST_ARCHIVE_DECL(void) |
---|
74 | xml_oarchive_impl<Archive>::save(const std::string & s){ |
---|
75 | // at least one library doesn't typedef value_type for strings |
---|
76 | // so rather than using string directly make a pointer iterator out of it |
---|
77 | typedef boost::archive::iterators::xml_escape< |
---|
78 | const char * |
---|
79 | > xml_escape_translator; |
---|
80 | std::copy( |
---|
81 | xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s.data())), |
---|
82 | xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s.data()+ s.size())), |
---|
83 | boost::archive::iterators::ostream_iterator<char>(os) |
---|
84 | ); |
---|
85 | } |
---|
86 | |
---|
87 | template<class Archive> |
---|
88 | BOOST_ARCHIVE_DECL(void) |
---|
89 | xml_oarchive_impl<Archive>::save(const char * s){ |
---|
90 | typedef boost::archive::iterators::xml_escape< |
---|
91 | const char * |
---|
92 | > xml_escape_translator; |
---|
93 | std::copy( |
---|
94 | xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s)), |
---|
95 | xml_escape_translator(BOOST_MAKE_PFTO_WRAPPER(s + std::strlen(s))), |
---|
96 | boost::archive::iterators::ostream_iterator<char>(os) |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | template<class Archive> |
---|
101 | BOOST_ARCHIVE_DECL(BOOST_PP_EMPTY()) |
---|
102 | xml_oarchive_impl<Archive>::xml_oarchive_impl( |
---|
103 | std::ostream & os_, |
---|
104 | unsigned int flags |
---|
105 | ) : |
---|
106 | basic_text_oprimitive<std::ostream>( |
---|
107 | os_, |
---|
108 | 0 != (flags & no_codecvt) |
---|
109 | ), |
---|
110 | basic_xml_oarchive<Archive>(flags) |
---|
111 | { |
---|
112 | if(0 == (flags & no_header)) |
---|
113 | this->init(); |
---|
114 | } |
---|
115 | |
---|
116 | } // namespace archive |
---|
117 | } // namespace boost |
---|