Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:28

0001 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0002 // basic_text_oprimitive.ipp:
0003 
0004 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
0005 // Use, modification and distribution is subject to the Boost Software
0006 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org for updates, documentation, and revision history.
0010 
0011 #include <cstddef> // NULL
0012 #include <algorithm> // std::copy
0013 #include <boost/config.hpp>
0014 #if defined(BOOST_NO_STDC_NAMESPACE)
0015 namespace std{ 
0016     using ::size_t; 
0017 } // namespace std
0018 #endif
0019 
0020 #include <boost/core/uncaught_exceptions.hpp>
0021 
0022 #include <boost/archive/basic_text_oprimitive.hpp>
0023 
0024 #include <boost/archive/iterators/base64_from_binary.hpp>
0025 #include <boost/archive/iterators/insert_linebreaks.hpp>
0026 #include <boost/archive/iterators/transform_width.hpp>
0027 #include <boost/archive/iterators/ostream_iterator.hpp>
0028 
0029 namespace boost {
0030 namespace archive {
0031 
0032 // translate to base64 and copy in to buffer.
0033 template<class OStream>
0034 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0035 basic_text_oprimitive<OStream>::save_binary(
0036     const void *address, 
0037     std::size_t count
0038 ){
0039     typedef typename OStream::char_type CharType;
0040     
0041     if(0 == count)
0042         return;
0043     
0044     if(os.fail())
0045         boost::serialization::throw_exception(
0046             archive_exception(archive_exception::output_stream_error)
0047         );
0048         
0049     os.put('\n');
0050     
0051     typedef 
0052         boost::archive::iterators::insert_linebreaks<
0053             boost::archive::iterators::base64_from_binary<
0054                 boost::archive::iterators::transform_width<
0055                     const char *,
0056                     6,
0057                     8
0058                 >
0059             > 
0060             ,76
0061             ,const char // cwpro8 needs this
0062         > 
0063         base64_text;
0064 
0065     boost::archive::iterators::ostream_iterator<CharType> oi(os);
0066     std::copy(
0067         base64_text(static_cast<const char *>(address)),
0068         base64_text(
0069             static_cast<const char *>(address) + count
0070         ),
0071         oi
0072     );
0073     
0074     std::size_t tail = count % 3;
0075     if(tail > 0){
0076         *oi++ = '=';
0077         if(tail < 2)
0078             *oi = '=';
0079     }
0080 }
0081 
0082 template<class OStream>
0083 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0084 basic_text_oprimitive<OStream>::basic_text_oprimitive(
0085     OStream & os_,
0086     bool no_codecvt
0087 ) : 
0088     os(os_),
0089     flags_saver(os_),
0090 #ifndef BOOST_NO_STD_LOCALE
0091     precision_saver(os_),
0092     codecvt_null_facet(1),
0093     archive_locale(os.getloc(), & codecvt_null_facet),
0094     locale_saver(os)
0095 {
0096     if(! no_codecvt){
0097         os_.flush();
0098         os_.imbue(archive_locale);
0099     }
0100     os_ << std::noboolalpha;
0101 }
0102 #else
0103     precision_saver(os_)
0104 {}
0105 #endif
0106 
0107 
0108 template<class OStream>
0109 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0110 basic_text_oprimitive<OStream>::~basic_text_oprimitive(){
0111     if(boost::core::uncaught_exceptions() > 0)
0112         return;
0113     os << std::endl;
0114 }
0115 
0116 } //namespace boost 
0117 } //namespace archive