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_iprimitive.ipp:
0003 
0004 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // 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> // size_t, NULL
0012 #include <limits> // NULL
0013 
0014 #include <boost/config.hpp>
0015 #if defined(BOOST_NO_STDC_NAMESPACE)
0016 namespace std{ 
0017     using ::size_t; 
0018 } // namespace std
0019 #endif
0020 
0021 #include <boost/serialization/throw_exception.hpp>
0022 
0023 #include <boost/archive/basic_text_iprimitive.hpp>
0024 
0025 #include <boost/archive/iterators/remove_whitespace.hpp>
0026 #include <boost/archive/iterators/istream_iterator.hpp>
0027 #include <boost/archive/iterators/binary_from_base64.hpp>
0028 #include <boost/archive/iterators/transform_width.hpp>
0029 
0030 namespace boost {
0031 namespace archive {
0032 
0033 namespace detail {
0034     template<class CharType>
0035     static inline bool is_whitespace(CharType c);
0036 
0037     template<>
0038     inline bool is_whitespace(char t){
0039         return 0 != std::isspace(t);
0040     }
0041 
0042     #ifndef BOOST_NO_CWCHAR
0043     template<>
0044     inline bool is_whitespace(wchar_t t){
0045         return 0 != std::iswspace(t);
0046     }
0047     #endif
0048 } // detail
0049 
0050 // translate base64 text into binary and copy into buffer
0051 // until buffer is full.
0052 template<class IStream>
0053 BOOST_ARCHIVE_OR_WARCHIVE_DECL void
0054 basic_text_iprimitive<IStream>::load_binary(
0055     void *address, 
0056     std::size_t count
0057 ){
0058     typedef typename IStream::char_type CharType;
0059     
0060     if(0 == count)
0061         return;
0062         
0063     BOOST_ASSERT(
0064         static_cast<std::size_t>((std::numeric_limits<std::streamsize>::max)())
0065         > (count + sizeof(CharType) - 1)/sizeof(CharType)
0066     );
0067         
0068     if(is.fail())
0069         boost::serialization::throw_exception(
0070             archive_exception(archive_exception::input_stream_error)
0071         );
0072     // convert from base64 to binary
0073     typedef typename
0074         iterators::transform_width<
0075             iterators::binary_from_base64<
0076                 iterators::remove_whitespace<
0077                     iterators::istream_iterator<CharType>
0078                 >
0079                 ,typename IStream::int_type
0080             >
0081             ,8
0082             ,6
0083             ,CharType
0084         > 
0085         binary;
0086         
0087     binary i = binary(iterators::istream_iterator<CharType>(is));
0088 
0089     char * caddr = static_cast<char *>(address);
0090     
0091     // take care that we don't increment anymore than necessary
0092     while(count-- > 0){
0093         *caddr++ = static_cast<char>(*i++);
0094     }
0095 
0096     // skip over any excess input
0097     for(;;){
0098         typename IStream::int_type r;
0099         r = is.get();
0100         if(is.eof())
0101             break;
0102         if(detail::is_whitespace(static_cast<CharType>(r)))
0103             break;
0104     }
0105 }
0106     
0107 template<class IStream>
0108 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0109 basic_text_iprimitive<IStream>::basic_text_iprimitive(
0110     IStream  &is_,
0111     bool no_codecvt
0112 ) :
0113     is(is_),
0114     flags_saver(is_),
0115 #ifndef BOOST_NO_STD_LOCALE
0116     precision_saver(is_),
0117     codecvt_null_facet(1),
0118     archive_locale(is.getloc(), & codecvt_null_facet),
0119     locale_saver(is)
0120 {
0121     if(! no_codecvt){
0122         is_.sync();
0123         is_.imbue(archive_locale);
0124     }
0125     is_ >> std::noboolalpha;
0126 }
0127 #else
0128     precision_saver(is_)
0129 {}
0130 #endif
0131 
0132 template<class IStream>
0133 BOOST_ARCHIVE_OR_WARCHIVE_DECL
0134 basic_text_iprimitive<IStream>::~basic_text_iprimitive(){
0135 }
0136 
0137 } // namespace archive
0138 } // namespace boost