Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/serialization/src/codecvt_null.cpp @ 20

Last change on this file since 20 was 12, checked in by landauf, 18 years ago

added boost

File size: 2.5 KB
Line 
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// codecvt_null.cpp
3
4// Copyright © 2004 Robert Ramey, Indiana University (garcia@osl.iu.edu)
5// Andrew Lumsdaine, Indiana University (lums@osl.iu.edu).
6// Use, modification and distribution is subject to the Boost Software
7// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10#include <boost/archive/codecvt_null.hpp>
11
12// codecvt implementation for passing wchar_t objects to char output
13// without any translation whatever.  Used to implement binary output
14// of wchar_t objects.
15
16namespace boost {
17namespace archive {
18
19std::codecvt_base::result
20codecvt_null<wchar_t>::do_out(
21    std::mbstate_t & state,
22    const wchar_t * first1, 
23    const wchar_t * last1,
24    const wchar_t * & next1,
25    char * first2, 
26    char * last2, 
27    char * & next2
28) const {
29    while(first1 != last1){
30        // Per std::22.2.1.5.2/2, we can store no more that
31        // last2-first2 characters. If we need to more encode
32        // next internal char type, return 'partial'.
33        if(static_cast<int>(sizeof(wchar_t)) > (last2 - first2)){
34            next1 = first1;
35            next2 = first2;
36            return std::codecvt_base::partial;
37        }
38        * reinterpret_cast<wchar_t *>(first2) = * first1++;
39        first2 += sizeof(wchar_t);
40
41    }
42    next1 = first1;
43    next2 = first2;
44    return std::codecvt_base::ok;
45}
46
47std::codecvt_base::result
48codecvt_null<wchar_t>::do_in(
49    std::mbstate_t & state,
50    const char * first1, 
51    const char * last1, 
52    const char * & next1,
53    wchar_t * first2,
54    wchar_t * last2,
55    wchar_t * & next2
56) const {
57    // Process input characters until we've run of them,
58    // or the number of remaining characters is not
59    // enough to construct another output character,
60    // or we've run out of place for output characters.
61    while(first2 != last2){
62        // Have we converted all input characters?
63        // Return with 'ok', if so.
64        if (first1 == last1)
65             break;
66        // Do we have less input characters than needed
67        // for a single output character?       
68        if(static_cast<int>(sizeof(wchar_t)) > (last1 - first1)){
69            next1 = first1;
70            next2 = first2;
71            return std::codecvt_base::partial; 
72        }
73        *first2++ = * reinterpret_cast<const wchar_t *>(first1);
74        first1 += sizeof(wchar_t);
75    }
76    next1 = first1;
77    next2 = first2;
78    return std::codecvt_base::ok;
79}
80
81} // namespace archive
82} // namespace boost
Note: See TracBrowser for help on using the repository browser.