Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / impl / basic_text_iprimitive.ipp @ 2486

History | View | Annotate | Download (3.7 kB)

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)
16
namespace std{ 
17
    using ::size_t; 
18
} // namespace std
19
#endif
20

    
21
#include <boost/serialization/throw_exception.hpp>
22

    
23
#include <boost/archive/basic_text_iprimitive.hpp>
24
#include <boost/archive/codecvt_null.hpp>
25
#include <boost/archive/add_facet.hpp>
26

    
27
#include <boost/archive/iterators/remove_whitespace.hpp>
28
#include <boost/archive/iterators/istream_iterator.hpp>
29
#include <boost/archive/iterators/binary_from_base64.hpp>
30
#include <boost/archive/iterators/transform_width.hpp>
31

    
32
namespace boost {
33
namespace archive {
34

    
35
namespace detail {
36
    template<class CharType>
37
    static inline bool is_whitespace(CharType c);
38

    
39
    template<>
40
    inline bool is_whitespace(char t){
41
        return 0 != std::isspace(t);
42
    }
43

    
44
    #ifndef BOOST_NO_CWCHAR
45
    template<>
46
    inline bool is_whitespace(wchar_t t){
47
        return 0 != std::iswspace(t);
48
    }
49
    #endif
50
} // detail
51

    
52
// translate base64 text into binary and copy into buffer
53
// until buffer is full.
54
template<class IStream>
55
BOOST_ARCHIVE_OR_WARCHIVE_DECL void
56
basic_text_iprimitive<IStream>::load_binary(
57
    void *address, 
58
    std::size_t count
59
){
60
    typedef typename IStream::char_type CharType;
61
    
62
    if(0 == count)
63
        return;
64
        
65
    BOOST_ASSERT(
66
        static_cast<std::size_t>((std::numeric_limits<std::streamsize>::max)())
67
        > (count + sizeof(CharType) - 1)/sizeof(CharType)
68
    );
69
        
70
    if(is.fail())
71
        boost::serialization::throw_exception(
72
            archive_exception(archive_exception::input_stream_error)
73
        );
74
    // convert from base64 to binary
75
    typedef typename
76
        iterators::transform_width<
77
            iterators::binary_from_base64<
78
                iterators::remove_whitespace<
79
                    iterators::istream_iterator<CharType>
80
                >
81
                ,CharType
82
            >
83
            ,8
84
            ,6
85
            ,CharType
86
        > 
87
        binary;
88
        
89
    binary i = binary(iterators::istream_iterator<CharType>(is));
90

    
91
    char * caddr = static_cast<char *>(address);
92
    
93
    // take care that we don't increment anymore than necessary
94
    while(count-- > 0){
95
        *caddr++ = static_cast<char>(*i++);
96
    }
97

    
98
    // skip over any excess input
99
    for(;;){
100
        typename IStream::int_type r;
101
        r = is.get();
102
        if(is.eof())
103
            break;
104
        if(detail::is_whitespace(static_cast<CharType>(r)))
105
            break;
106
    }
107
}
108
    
109
template<class IStream>
110
BOOST_ARCHIVE_OR_WARCHIVE_DECL
111
basic_text_iprimitive<IStream>::basic_text_iprimitive(
112
    IStream  &is_,
113
    bool no_codecvt
114
) :
115
#ifndef BOOST_NO_STD_LOCALE
116
    is(is_),
117
    flags_saver(is_),
118
    precision_saver(is_),
119
    locale_saver(* is_.rdbuf())
120
{
121
    if(! no_codecvt){
122
        archive_locale.reset(
123
            add_facet(
124
                std::locale::classic(),
125
                new boost::archive::codecvt_null<typename IStream::char_type>
126
            )
127
        );
128
        //is.imbue(* archive_locale);
129
    }
130
    is >> std::noboolalpha;
131
}
132
#else
133
    is(is_),
134
    flags_saver(is_),
135
    precision_saver(is_)
136
{}
137
#endif
138

    
139
template<class IStream>
140
BOOST_ARCHIVE_OR_WARCHIVE_DECL
141
basic_text_iprimitive<IStream>::~basic_text_iprimitive(){
142
    is.sync();
143
}
144

    
145
} // namespace archive
146
} // namespace boost