Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // mb_from_wchar.hpp Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: #include Chris@16: #include // size_t Chris@16: #include // for wctomb() Chris@16: Chris@101: #include Chris@16: #if defined(BOOST_NO_STDC_NAMESPACE) Chris@16: namespace std{ Chris@16: using ::size_t; Chris@16: using ::wctomb; Chris@16: } // namespace std Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: namespace iterators { Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // class used by text archives to translate wide strings and to char Chris@16: // strings of the currently selected locale Chris@16: template // the input iterator Chris@16: class mb_from_wchar Chris@16: : public boost::iterator_adaptor< Chris@16: mb_from_wchar, Chris@16: Base, Chris@16: wchar_t, Chris@16: single_pass_traversal_tag, Chris@16: char Chris@16: > Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@16: Chris@101: typedef typename boost::iterator_adaptor< Chris@16: mb_from_wchar, Chris@16: Base, Chris@16: wchar_t, Chris@16: single_pass_traversal_tag, Chris@16: char Chris@16: > super_t; Chris@16: Chris@16: typedef mb_from_wchar this_t; Chris@16: Chris@16: char dereference_impl() { Chris@16: if(! m_full){ Chris@16: fill(); Chris@16: m_full = true; Chris@16: } Chris@16: return m_buffer[m_bnext]; Chris@16: } Chris@16: char dereference() const { Chris@16: return (const_cast(this))->dereference_impl(); Chris@16: } Chris@16: Chris@16: // test for iterator equality Chris@16: bool equal(const mb_from_wchar & rhs) const { Chris@16: // once the value is filled, the base_reference has been incremented Chris@16: // so don't permit comparison anymore. Chris@16: return Chris@16: 0 == m_bend Chris@16: && 0 == m_bnext Chris@16: && this->base_reference() == rhs.base_reference() Chris@16: ; Chris@16: } Chris@16: Chris@16: void fill(){ Chris@16: wchar_t value = * this->base_reference(); Chris@16: #if (defined(__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 3) \ Chris@16: || ((__MINGW32_MAJOR_VERSION == 3) && (__MINGW32_MINOR_VERSION >= 8)))) Chris@16: m_bend = std::wcrtomb(m_buffer, value, 0); Chris@16: #else Chris@16: m_bend = std::wctomb(m_buffer, value); Chris@16: #endif Chris@16: BOOST_ASSERT(-1 != m_bend); Chris@16: BOOST_ASSERT((std::size_t)m_bend <= sizeof(m_buffer)); Chris@16: BOOST_ASSERT(m_bend > 0); Chris@16: m_bnext = 0; Chris@16: } Chris@16: Chris@16: void increment(){ Chris@16: if(++m_bnext < m_bend) Chris@16: return; Chris@16: m_bend = Chris@16: m_bnext = 0; Chris@16: ++(this->base_reference()); Chris@16: m_full = false; Chris@16: } Chris@16: Chris@16: // buffer to handle pending characters Chris@16: int m_bend; Chris@16: int m_bnext; Chris@16: char m_buffer[9]; Chris@16: bool m_full; Chris@16: Chris@16: public: Chris@16: // make composible buy using templated constructor Chris@16: template Chris@16: mb_from_wchar(BOOST_PFTO_WRAPPER(T) start) : Chris@16: super_t(Base(BOOST_MAKE_PFTO_WRAPPER(static_cast< T >(start)))), Chris@16: m_bend(0), Chris@16: m_bnext(0), Chris@16: m_full(false) Chris@16: {} Chris@16: // intel 7.1 doesn't like default copy constructor Chris@16: mb_from_wchar(const mb_from_wchar & rhs) : Chris@16: super_t(rhs.base_reference()), Chris@16: m_bend(rhs.m_bend), Chris@16: m_bnext(rhs.m_bnext), Chris@16: m_full(rhs.m_full) Chris@16: {} Chris@16: }; Chris@16: Chris@16: } // namespace iterators Chris@16: } // namespace archive Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_ARCHIVE_ITERATORS_MB_FROM_WCHAR_HPP