aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/serialization/src/codecvt_null.cpp
blob: 2011e77b587f9d9d1265f5fc3bc5d1dbfaa6d1a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// codecvt_null.cpp

// Copyright (c) 2004 Robert Ramey, Indiana University (garcia@osl.iu.edu)
// Andrew Lumsdaine, Indiana University (lums@osl.iu.edu). 
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#define BOOST_WARCHIVE_SOURCE
#include <boost/serialization/config.hpp>
#include <boost/archive/codecvt_null.hpp>

// codecvt implementation for passing wchar_t objects to char output
// without any translation whatever.  Used to implement binary output
// of wchar_t objects.

namespace boost {
namespace archive {

BOOST_SYMBOL_EXPORT std::codecvt_base::result
codecvt_null<wchar_t>::do_out(
    std::mbstate_t & /*state*/,
    const wchar_t * first1, 
    const wchar_t * last1,
    const wchar_t * & next1,
    char * first2, 
    char * last2, 
    char * & next2
) const {
    while(first1 != last1){
        // Per std::22.2.1.5.2/2, we can store no more that
        // last2-first2 characters. If we need to more encode
        // next internal char type, return 'partial'.
        if(static_cast<int>(sizeof(wchar_t)) > (last2 - first2)){
            next1 = first1;
            next2 = first2;
            return std::codecvt_base::partial;
        }
        * reinterpret_cast<wchar_t *>(first2) = * first1++;
        first2 += sizeof(wchar_t);

    }
    next1 = first1;
    next2 = first2;
    return std::codecvt_base::ok;
}

BOOST_SYMBOL_EXPORT std::codecvt_base::result
codecvt_null<wchar_t>::do_in(
    std::mbstate_t & /*state*/,
    const char * first1, 
    const char * last1, 
    const char * & next1,
    wchar_t * first2,
    wchar_t * last2,
    wchar_t * & next2
) const {
    // Process input characters until we've run of them,
    // or the number of remaining characters is not
    // enough to construct another output character,
    // or we've run out of place for output characters.
    while(first2 != last2){
        // Have we converted all input characters? 
        // Return with 'ok', if so.
        if (first1 == last1)
             break;
        // Do we have less input characters than needed
        // for a single output character?        
        if(static_cast<int>(sizeof(wchar_t)) > (last1 - first1)){
            next1 = first1;
            next2 = first2;
            return std::codecvt_base::partial; 
        }
        *first2++ = * reinterpret_cast<const wchar_t *>(first1);
        first1 += sizeof(wchar_t);
    }
    next1 = first1;
    next2 = first2;
    return std::codecvt_base::ok;
}

BOOST_SYMBOL_EXPORT codecvt_null<wchar_t>::codecvt_null(std::size_t no_locale_manage) :
    std::codecvt<wchar_t, char, std::mbstate_t>(no_locale_manage)
{}

BOOST_SYMBOL_EXPORT codecvt_null<wchar_t>::~codecvt_null()
{}

} // namespace archive
} // namespace boost