]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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> // std::copy | |
12 | #include <string> | |
13 | #include <exception> | |
14 | ||
15 | #include <cstring> // strlen | |
16 | #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings | |
17 | #if defined(BOOST_NO_STDC_NAMESPACE) | |
18 | namespace std{ | |
19 | using ::strlen; | |
20 | } // namespace std | |
21 | #endif | |
22 | ||
23 | #include <boost/archive/iterators/xml_escape.hpp> | |
24 | #include <boost/archive/iterators/ostream_iterator.hpp> | |
25 | ||
26 | #ifndef BOOST_NO_CWCHAR | |
27 | #include <boost/archive/wcslen.hpp> | |
28 | #include <boost/archive/iterators/mb_from_wchar.hpp> | |
29 | #endif | |
30 | ||
31 | namespace boost { | |
32 | namespace archive { | |
33 | ||
34 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
35 | // implemenations of functions specific to char archives | |
36 | ||
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> | |
44 | > translator; | |
45 | std::copy( | |
46 | translator(begin), | |
47 | translator(end), | |
48 | boost::archive::iterators::ostream_iterator<char>(os) | |
49 | ); | |
50 | } | |
51 | ||
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()); | |
60 | } | |
61 | #endif | |
62 | ||
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)); | |
68 | } | |
69 | #endif | |
70 | ||
71 | #endif // BOOST_NO_CWCHAR | |
72 | ||
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< | |
79 | const char * | |
80 | > xml_escape_translator; | |
81 | std::copy( | |
82 | xml_escape_translator(s.data()), | |
83 | xml_escape_translator(s.data()+ s.size()), | |
84 | boost::archive::iterators::ostream_iterator<char>(os) | |
85 | ); | |
86 | } | |
87 | ||
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< | |
92 | const char * | |
93 | > xml_escape_translator; | |
94 | std::copy( | |
95 | xml_escape_translator(s), | |
96 | xml_escape_translator(s + std::strlen(s)), | |
97 | boost::archive::iterators::ostream_iterator<char>(os) | |
98 | ); | |
99 | } | |
100 | ||
101 | template<class Archive> | |
102 | BOOST_ARCHIVE_DECL | |
103 | xml_oarchive_impl<Archive>::xml_oarchive_impl( | |
104 | std::ostream & os_, | |
105 | unsigned int flags | |
106 | ) : | |
107 | basic_text_oprimitive<std::ostream>( | |
108 | os_, | |
109 | 0 != (flags & no_codecvt) | |
110 | ), | |
111 | basic_xml_oarchive<Archive>(flags) | |
112 | { | |
113 | if(0 == (flags & no_header)) | |
114 | this->init(); | |
115 | } | |
116 | ||
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( | |
123 | #else | |
124 | this->basic_text_oprimitive::save_binary( | |
125 | #endif | |
126 | address, | |
127 | count | |
128 | ); | |
129 | this->indent_next = true; | |
130 | } | |
131 | ||
132 | template<class Archive> | |
133 | BOOST_ARCHIVE_DECL | |
134 | xml_oarchive_impl<Archive>::~xml_oarchive_impl(){ | |
135 | if(std::uncaught_exception()) | |
136 | return; | |
137 | if(0 == (this->get_flags() & no_header)) | |
138 | this->windup(); | |
139 | } | |
140 | ||
141 | } // namespace archive | |
142 | } // namespace boost |