1 #ifndef BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP
2 #define BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_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>
20 #include <cstddef> // size_t
21 #include <cwchar> // mbstate_t
23 #include <boost/config.hpp>
24 #if defined(BOOST_NO_STDC_NAMESPACE)
29 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
30 #include <boost/iterator/iterator_adaptor.hpp>
36 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
37 // class used by text archives to translate wide strings and to char
38 // strings of the currently selected locale
39 template<class Base> // the input iterator
41 : public boost::iterator_adaptor<
45 single_pass_traversal_tag,
49 friend class boost::iterator_core_access;
51 typedef typename boost::iterator_adaptor<
55 single_pass_traversal_tag,
59 typedef mb_from_wchar<Base> this_t;
61 char dereference_impl() {
66 return m_buffer[m_bnext];
69 char dereference() const {
70 return (const_cast<this_t *>(this))->dereference_impl();
72 // test for iterator equality
73 bool equal(const mb_from_wchar<Base> & rhs) const {
74 // once the value is filled, the base_reference has been incremented
75 // so don't permit comparison anymore.
79 && this->base_reference() == rhs.base_reference()
84 wchar_t value = * this->base_reference();
87 std::codecvt_base::result r = m_codecvt_facet.out(
89 & value, & value + 1, wend,
90 m_buffer, m_buffer + sizeof(m_buffer), bend
92 BOOST_ASSERT(std::codecvt_base::ok == r);
94 m_bend = bend - m_buffer;
98 if(++m_bnext < m_bend)
102 ++(this->base_reference());
106 boost::archive::detail::utf8_codecvt_facet m_codecvt_facet;
107 std::mbstate_t m_mbs;
108 // buffer to handle pending characters
109 char m_buffer[9 /* MB_CUR_MAX */];
115 // make composible buy using templated constructor
117 mb_from_wchar(T start) :
118 super_t(Base(static_cast< T >(start))),
119 m_mbs(std::mbstate_t()),
124 // intel 7.1 doesn't like default copy constructor
125 mb_from_wchar(const mb_from_wchar & rhs) :
126 super_t(rhs.base_reference()),
128 m_bnext(rhs.m_bnext),
133 } // namespace iterators
134 } // namespace archive
137 #endif // BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP