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