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
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
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 <cstdlib> // for wctomb()
23 #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
24 #if defined(BOOST_NO_STDC_NAMESPACE)
31 #include <boost/serialization/pfto.hpp>
32 #include <boost/iterator/iterator_adaptor.hpp>
38 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
39 // class used by text archives to translate wide strings and to char
40 // strings of the currently selected locale
41 template<class Base> // the input iterator
43 : public boost::iterator_adaptor<
47 single_pass_traversal_tag,
51 friend class boost::iterator_core_access;
53 typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor<
57 single_pass_traversal_tag,
61 typedef mb_from_wchar<Base> this_t;
63 char dereference_impl() {
68 return m_buffer[m_bnext];
70 char dereference() const {
71 return (const_cast<this_t *>(this))->dereference_impl();
74 // test for iterator equality
75 bool equal(const mb_from_wchar<Base> & rhs) const {
76 // once the value is filled, the base_reference has been incremented
77 // so don't permit comparison anymore.
81 && this->base_reference() == rhs.base_reference()
86 wchar_t value = * this->base_reference();
87 #if (defined(__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 3) \
88 || ((__MINGW32_MAJOR_VERSION == 3) && (__MINGW32_MINOR_VERSION >= 8))))
89 m_bend = std::wcrtomb(m_buffer, value, 0);
91 m_bend = std::wctomb(m_buffer, value);
93 BOOST_ASSERT(-1 != m_bend);
94 BOOST_ASSERT((std::size_t)m_bend <= sizeof(m_buffer));
95 BOOST_ASSERT(m_bend > 0);
100 if(++m_bnext < m_bend)
104 ++(this->base_reference());
108 // buffer to handle pending characters
115 // make composible buy using templated constructor
117 mb_from_wchar(BOOST_PFTO_WRAPPER(T) start) :
118 super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start)))),
123 // intel 7.1 doesn't like default copy constructor
124 mb_from_wchar(const mb_from_wchar & rhs) :
125 super_t(rhs.base_reference()),
127 m_bnext(rhs.m_bnext),
132 } // namespace iterators
133 } // namespace archive
136 #endif // BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP