PageRenderTime 31ms CodeModel.GetById 25ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/archive/impl/basic_text_iprimitive.ipp

http://hadesmem.googlecode.com/
C++ Header | 154 lines | 121 code | 22 blank | 11 comment | 9 complexity | 96816dadd65c31686c7fc01d822f0475 MD5 | raw file
  1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2// basic_text_iprimitive.ipp:
  3
  4// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  5// Distributed under the Boost Software License, Version 1.0. (See
  6// 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> // size_t
 12#include <cstddef> // NULL
 13
 14#include <boost/config.hpp>
 15#if defined(BOOST_NO_STDC_NAMESPACE)
 16namespace std{ 
 17    using ::size_t; 
 18} // namespace std
 19#endif
 20
 21#include <boost/serialization/throw_exception.hpp>
 22#include <boost/serialization/pfto.hpp>
 23
 24#include <boost/archive/basic_text_iprimitive.hpp>
 25#include <boost/archive/codecvt_null.hpp>
 26#include <boost/archive/add_facet.hpp>
 27
 28#include <boost/archive/iterators/remove_whitespace.hpp>
 29#include <boost/archive/iterators/istream_iterator.hpp>
 30#include <boost/archive/iterators/binary_from_base64.hpp>
 31#include <boost/archive/iterators/transform_width.hpp>
 32
 33namespace boost { 
 34namespace archive {
 35
 36namespace {
 37    template<class CharType>
 38    bool is_whitespace(CharType c);
 39
 40    template<>
 41    bool is_whitespace(char t){
 42        return 0 != std::isspace(t);
 43    }
 44
 45    #ifndef BOOST_NO_CWCHAR
 46    template<>
 47    bool is_whitespace(wchar_t t){
 48        return 0 != std::iswspace(t);
 49    }
 50    #endif
 51}
 52
 53// translate base64 text into binary and copy into buffer
 54// until buffer is full.
 55template<class IStream>
 56BOOST_ARCHIVE_OR_WARCHIVE_DECL(void)
 57basic_text_iprimitive<IStream>::load_binary(
 58    void *address, 
 59    std::size_t count
 60){
 61    typedef BOOST_DEDUCED_TYPENAME IStream::char_type CharType;
 62    
 63    if(0 == count)
 64        return;
 65        
 66    BOOST_ASSERT(
 67        static_cast<std::size_t>((std::numeric_limits<std::streamsize>::max)())
 68        > (count + sizeof(CharType) - 1)/sizeof(CharType)
 69    );
 70        
 71    if(is.fail())
 72        boost::serialization::throw_exception(
 73            archive_exception(archive_exception::input_stream_error)
 74        );
 75    // convert from base64 to binary
 76    typedef BOOST_DEDUCED_TYPENAME
 77        iterators::transform_width<
 78            iterators::binary_from_base64<
 79                iterators::remove_whitespace<
 80                    iterators::istream_iterator<CharType>
 81                >
 82                ,CharType
 83            >
 84            ,8
 85            ,6
 86            ,CharType
 87        > 
 88        binary;
 89
 90    binary ti_begin = binary(
 91        BOOST_MAKE_PFTO_WRAPPER(
 92            iterators::istream_iterator<CharType>(is)
 93        )
 94    );
 95                
 96    char * caddr = static_cast<char *>(address);
 97    
 98    // take care that we don't increment anymore than necessary
 99    while(--count > 0){
100        *caddr++ = static_cast<char>(*ti_begin);
101        ++ti_begin;
102    }
103    *caddr++ = static_cast<char>(*ti_begin);
104    
105    iterators::istream_iterator<CharType> i;
106    for(;;){
107        BOOST_DEDUCED_TYPENAME IStream::int_type r;
108        r = is.get();
109        if(is.eof())
110            break;
111        if(is_whitespace(static_cast<CharType>(r)))
112            break;
113    }
114}
115
116template<class IStream>
117BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
118basic_text_iprimitive<IStream>::basic_text_iprimitive(
119    IStream  &is_,
120    bool no_codecvt
121) :
122#ifndef BOOST_NO_STD_LOCALE
123    is(is_),
124    flags_saver(is_),
125    precision_saver(is_),
126    archive_locale(NULL),
127    locale_saver(* is_.rdbuf())
128{
129    if(! no_codecvt){
130        archive_locale.reset(
131            add_facet(
132                std::locale::classic(), 
133                new codecvt_null<BOOST_DEDUCED_TYPENAME IStream::char_type>
134            )
135        );
136        is.imbue(* archive_locale);
137    }
138    is >> std::noboolalpha;
139}
140#else
141    is(is_),
142    flags_saver(is_),
143    precision_saver(is_)
144{}
145#endif
146
147template<class IStream>
148BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
149basic_text_iprimitive<IStream>::~basic_text_iprimitive(){
150    is.sync();
151}
152
153} // namespace archive
154} // namespace boost