1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
2 | // basic_text_oprimitive.ipp:
|
---|
3 |
|
---|
4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
---|
5 | // Use, modification and distribution is subject to the Boost Software
|
---|
6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
7 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
8 |
|
---|
9 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
10 |
|
---|
11 | #include <boost/pfto.hpp>
|
---|
12 |
|
---|
13 | #include <boost/archive/basic_text_oprimitive.hpp>
|
---|
14 | #include <boost/archive/codecvt_null.hpp>
|
---|
15 | #include <boost/archive/add_facet.hpp>
|
---|
16 |
|
---|
17 | #include <boost/archive/iterators/base64_from_binary.hpp>
|
---|
18 | #include <boost/archive/iterators/insert_linebreaks.hpp>
|
---|
19 | #include <boost/archive/iterators/transform_width.hpp>
|
---|
20 | #include <boost/archive/iterators/ostream_iterator.hpp>
|
---|
21 | #include <boost/detail/no_exceptions_support.hpp>
|
---|
22 |
|
---|
23 | namespace boost {
|
---|
24 | namespace archive {
|
---|
25 |
|
---|
26 | // translate to base64 and copy in to buffer.
|
---|
27 | template<class OStream>
|
---|
28 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
|
---|
29 | basic_text_oprimitive<OStream>::save_binary(
|
---|
30 | const void *address,
|
---|
31 | std::size_t count
|
---|
32 | ){
|
---|
33 | typedef BOOST_DEDUCED_TYPENAME OStream::char_type CharType;
|
---|
34 |
|
---|
35 | if(0 == count)
|
---|
36 | return;
|
---|
37 |
|
---|
38 | if(os.fail())
|
---|
39 | boost::throw_exception(archive_exception(archive_exception::stream_error));
|
---|
40 |
|
---|
41 | os.put('\n');
|
---|
42 |
|
---|
43 | typedef
|
---|
44 | boost::archive::iterators::insert_linebreaks<
|
---|
45 | boost::archive::iterators::base64_from_binary<
|
---|
46 | boost::archive::iterators::transform_width<
|
---|
47 | const char *,
|
---|
48 | 6,
|
---|
49 | 8
|
---|
50 | >
|
---|
51 | >
|
---|
52 | ,72
|
---|
53 | ,const char // cwpro8 needs this
|
---|
54 | >
|
---|
55 | base64_text;
|
---|
56 |
|
---|
57 | boost::archive::iterators::ostream_iterator<CharType> oi(os);
|
---|
58 | std::copy(
|
---|
59 | base64_text(BOOST_MAKE_PFTO_WRAPPER(static_cast<const char *>(address))),
|
---|
60 | base64_text(
|
---|
61 | BOOST_MAKE_PFTO_WRAPPER(static_cast<const char *>(address) + count)
|
---|
62 | ),
|
---|
63 | oi
|
---|
64 | );
|
---|
65 | std::size_t padding = 2 - count % 3;
|
---|
66 | if(padding > 1)
|
---|
67 | *oi = '=';
|
---|
68 | if(padding > 2)
|
---|
69 | *oi = '=';
|
---|
70 |
|
---|
71 | }
|
---|
72 |
|
---|
73 | template<class OStream>
|
---|
74 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
---|
75 | basic_text_oprimitive<OStream>::basic_text_oprimitive(
|
---|
76 | OStream & os_,
|
---|
77 | bool no_codecvt
|
---|
78 | ) :
|
---|
79 | os(os_),
|
---|
80 | flags_saver(os_),
|
---|
81 | precision_saver(os_),
|
---|
82 | archive_locale(NULL),
|
---|
83 | locale_saver(os_)
|
---|
84 | {
|
---|
85 | if(! no_codecvt){
|
---|
86 | archive_locale.reset(
|
---|
87 | add_facet(
|
---|
88 | std::locale::classic(),
|
---|
89 | new codecvt_null<BOOST_DEDUCED_TYPENAME OStream::char_type>
|
---|
90 | )
|
---|
91 | );
|
---|
92 | os.imbue(* archive_locale);
|
---|
93 | }
|
---|
94 | os << std::noboolalpha;
|
---|
95 | }
|
---|
96 |
|
---|
97 | template<class OStream>
|
---|
98 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
---|
99 | basic_text_oprimitive<OStream>::~basic_text_oprimitive(){
|
---|
100 | BOOST_TRY{
|
---|
101 | os.flush();
|
---|
102 | }
|
---|
103 | BOOST_CATCH(...){}
|
---|
104 | BOOST_CATCH_END
|
---|
105 | }
|
---|
106 |
|
---|
107 | } //namespace boost
|
---|
108 | } //namespace archive
|
---|