Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_ESCAPE_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: // escape.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 // NULL 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: // insert escapes into text Chris@16: Chris@16: template Chris@16: class escape : Chris@16: public boost::iterator_adaptor< Chris@16: Derived, Chris@16: Base, Chris@101: typename boost::iterator_value::type, Chris@16: single_pass_traversal_tag, Chris@101: typename boost::iterator_value::type Chris@16: > Chris@16: { Chris@101: typedef typename boost::iterator_value::type base_value_type; Chris@101: typedef typename boost::iterator_reference::type reference_type; Chris@16: friend class boost::iterator_core_access; Chris@16: Chris@101: typedef typename boost::iterator_adaptor< Chris@16: Derived, Chris@16: Base, Chris@16: base_value_type, Chris@16: single_pass_traversal_tag, Chris@16: base_value_type Chris@16: > super_t; Chris@16: Chris@16: typedef escape this_t; Chris@16: Chris@16: void dereference_impl() { Chris@16: m_current_value = static_cast(this)->fill(m_bnext, m_bend); Chris@16: m_full = true; Chris@16: } Chris@16: Chris@16: //Access the value referred to Chris@16: reference_type dereference() const { Chris@16: if(!m_full) Chris@16: const_cast(this)->dereference_impl(); Chris@16: return m_current_value; Chris@16: } Chris@16: Chris@16: bool equal(const this_t & rhs) const { Chris@16: if(m_full){ Chris@16: if(! rhs.m_full) Chris@16: const_cast(& rhs)->dereference_impl(); Chris@16: } Chris@16: else{ Chris@16: if(rhs.m_full) Chris@16: const_cast(this)->dereference_impl(); Chris@16: } Chris@16: if(m_bnext != rhs.m_bnext) Chris@16: return false; Chris@16: if(this->base_reference() != rhs.base_reference()) Chris@16: return false; Chris@16: return true; Chris@16: } Chris@16: Chris@16: void increment(){ Chris@16: if(++m_bnext < m_bend){ Chris@16: m_current_value = *m_bnext; Chris@16: return; Chris@16: } Chris@16: ++(this->base_reference()); Chris@16: m_bnext = NULL; Chris@16: m_bend = NULL; Chris@16: m_full = false; Chris@16: } Chris@16: Chris@16: // buffer to handle pending characters Chris@16: const base_value_type *m_bnext; Chris@16: const base_value_type *m_bend; Chris@16: bool m_full; Chris@16: base_value_type m_current_value; Chris@16: public: Chris@16: escape(Base base) : Chris@16: super_t(base), Chris@16: m_bnext(NULL), Chris@16: m_bend(NULL), Chris@16: m_full(false) Chris@16: { 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_ESCAPE_HPP