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)
30 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
31 #include <boost/iterator/iterator_adaptor.hpp>
37 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
38 // class used by text archives to translate wide strings and to char
39 // strings of the currently selected locale
40 template<class Base> // the input iterator
42 : public boost::iterator_adaptor<
46 single_pass_traversal_tag,
50 friend class boost::iterator_core_access;
52 typedef typename boost::iterator_adaptor<
56 single_pass_traversal_tag,
60 typedef mb_from_wchar<Base> this_t;
62 char dereference_impl() {
67 return m_buffer[m_bnext];
70 char dereference() const {
71 return (const_cast<this_t *>(this))->dereference_impl();
73 // test for iterator equality
74 bool equal(const mb_from_wchar<Base> & rhs) const {
75 // once the value is filled, the base_reference has been incremented
76 // so don't permit comparison anymore.
80 && this->base_reference() == rhs.base_reference()
85 wchar_t value = * this->base_reference();
88 std::codecvt_base::result r = m_codecvt_facet.out(
90 & value, & value + 1, wend,
91 m_buffer, m_buffer + sizeof(m_buffer), bend
93 BOOST_ASSERT(std::codecvt_base::ok == r);
95 m_bend = bend - m_buffer;
99 if(++m_bnext < m_bend)
103 ++(this->base_reference());
107 boost::archive::detail::utf8_codecvt_facet m_codecvt_facet;
108 std::mbstate_t m_mbs;
109 // buffer to handle pending characters
110 char m_buffer[9 /* MB_CUR_MAX */];
116 // make composible buy using templated constructor
118 mb_from_wchar(T start) :
119 super_t(Base(static_cast< T >(start))),
120 m_mbs(std::mbstate_t()),
125 // intel 7.1 doesn't like default copy constructor
126 mb_from_wchar(const mb_from_wchar & rhs) :
127 super_t(rhs.base_reference()),
129 m_bnext(rhs.m_bnext),
134 } // namespace iterators
135 } // namespace archive
138 #endif // BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP