]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/archive/impl/basic_text_oprimitive.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / archive / impl / basic_text_oprimitive.ipp
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 <cstddef> // NULL
12 #include <algorithm> // std::copy
13 #include <exception> // std::uncaught_exception
14 #include <boost/config.hpp>
15 #if defined(BOOST_NO_STDC_NAMESPACE)
16 namespace std{
17 using ::size_t;
18 } // namespace std
19 #endif
20
21 #include <boost/archive/basic_text_oprimitive.hpp>
22
23 #include <boost/archive/iterators/base64_from_binary.hpp>
24 #include <boost/archive/iterators/insert_linebreaks.hpp>
25 #include <boost/archive/iterators/transform_width.hpp>
26 #include <boost/archive/iterators/ostream_iterator.hpp>
27
28 namespace boost {
29 namespace archive {
30
31 // translate to base64 and copy in to buffer.
32 template<class OStream>
33 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
34 basic_text_oprimitive<OStream>::save_binary(
35 const void *address,
36 std::size_t count
37 ){
38 typedef typename OStream::char_type CharType;
39
40 if(0 == count)
41 return;
42
43 if(os.fail())
44 boost::serialization::throw_exception(
45 archive_exception(archive_exception::output_stream_error)
46 );
47
48 os.put('\n');
49
50 typedef
51 boost::archive::iterators::insert_linebreaks<
52 boost::archive::iterators::base64_from_binary<
53 boost::archive::iterators::transform_width<
54 const char *,
55 6,
56 8
57 >
58 >
59 ,76
60 ,const char // cwpro8 needs this
61 >
62 base64_text;
63
64 boost::archive::iterators::ostream_iterator<CharType> oi(os);
65 std::copy(
66 base64_text(static_cast<const char *>(address)),
67 base64_text(
68 static_cast<const char *>(address) + count
69 ),
70 oi
71 );
72
73 std::size_t tail = count % 3;
74 if(tail > 0){
75 *oi++ = '=';
76 if(tail < 2)
77 *oi = '=';
78 }
79 }
80
81 template<class OStream>
82 BOOST_ARCHIVE_OR_WARCHIVE_DECL
83 basic_text_oprimitive<OStream>::basic_text_oprimitive(
84 OStream & os_,
85 bool no_codecvt
86 ) :
87 os(os_),
88 flags_saver(os_),
89 precision_saver(os_),
90 #ifndef BOOST_NO_STD_LOCALE
91 codecvt_null_facet(1),
92 archive_locale(os.getloc(), & codecvt_null_facet),
93 locale_saver(os)
94 {
95 if(! no_codecvt){
96 os_.flush();
97 os_.imbue(archive_locale);
98 }
99 os_ << std::noboolalpha;
100 }
101 #else
102 {}
103 #endif
104
105
106 template<class OStream>
107 BOOST_ARCHIVE_OR_WARCHIVE_DECL
108 basic_text_oprimitive<OStream>::~basic_text_oprimitive(){
109 if(std::uncaught_exception())
110 return;
111 os << std::endl;
112 }
113
114 } //namespace boost
115 } //namespace archive