1 #ifndef BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP
2 #define BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 #include <boost/assert.hpp>
21 #include <cstddef> // size_t
22 #include <cstdlib> // mblen
24 #include <boost/config.hpp>
25 #if defined(BOOST_NO_STDC_NAMESPACE)
32 #include <boost/serialization/throw_exception.hpp>
33 #include <boost/serialization/pfto.hpp>
35 #include <boost/iterator/iterator_adaptor.hpp>
36 #include <boost/archive/iterators/dataflow_exception.hpp>
42 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
43 // class used by text archives to translate char strings to wchar_t
44 // strings of the currently selected locale
47 : public boost::iterator_adaptor<
51 single_pass_traversal_tag,
55 friend class boost::iterator_core_access;
56 typedef typename boost::iterator_adaptor<
60 single_pass_traversal_tag,
64 typedef wchar_from_mb<Base> this_t;
68 wchar_t dereference_impl() {
70 m_current_value = drain();
73 return m_current_value;
76 wchar_t dereference() const {
77 return const_cast<this_t *>(this)->dereference_impl();
83 ++(this->base_reference());
86 wchar_t m_current_value;
90 // make composible buy using templated constructor
92 wchar_from_mb(BOOST_PFTO_WRAPPER(T) start) :
93 super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start)))),
96 // intel 7.1 doesn't like default copy constructor
97 wchar_from_mb(const wchar_from_mb & rhs) :
98 super_t(rhs.base_reference()),
104 wchar_t wchar_from_mb<Base>::drain(){
106 char * bptr = buffer;
108 for(std::size_t i = 0; i++ < (unsigned)MB_CUR_MAX;){
109 val = * this->base_reference();
111 int result = std::mblen(buffer, i);
114 ++(this->base_reference());
117 int result = std::mbtowc(& retval, buffer, MB_CUR_MAX);
119 boost::serialization::throw_exception(iterators::dataflow_exception(
120 iterators::dataflow_exception::invalid_conversion
125 } // namespace iterators
126 } // namespace archive
129 #endif // BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP