escape.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP
  2. #define BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // escape.hpp
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <cassert>
  15. #include <cstddef> // NULL
  16. #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
  17. #include <boost/iterator/iterator_adaptor.hpp>
  18. #include <boost/iterator/iterator_traits.hpp>
  19. namespace boost {
  20. namespace archive {
  21. namespace iterators {
  22. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  23. // insert escapes into text
  24. template<class Derived, class Base>
  25. class escape :
  26. public boost::iterator_adaptor<
  27. Derived,
  28. Base,
  29. BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type,
  30. single_pass_traversal_tag,
  31. BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
  32. >
  33. {
  34. typedef BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type base_value_type;
  35. typedef BOOST_DEDUCED_TYPENAME boost::iterator_reference<Base>::type reference_type;
  36. friend class boost::iterator_core_access;
  37. typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor<
  38. Derived,
  39. Base,
  40. base_value_type,
  41. single_pass_traversal_tag,
  42. base_value_type
  43. > super_t;
  44. typedef escape<Derived, Base> this_t;
  45. void dereference_impl() {
  46. m_current_value = static_cast<Derived *>(this)->fill(m_bnext, m_bend);
  47. m_full = true;
  48. }
  49. //Access the value referred to
  50. reference_type dereference() const {
  51. if(!m_full)
  52. const_cast<this_t *>(this)->dereference_impl();
  53. return m_current_value;
  54. }
  55. bool equal(const this_t & rhs) const {
  56. if(m_full){
  57. if(! rhs.m_full)
  58. const_cast<this_t *>(& rhs)->dereference_impl();
  59. }
  60. else{
  61. if(rhs.m_full)
  62. const_cast<this_t *>(this)->dereference_impl();
  63. }
  64. if(m_bnext != rhs.m_bnext)
  65. return false;
  66. if(this->base_reference() != rhs.base_reference())
  67. return false;
  68. return true;
  69. }
  70. void increment(){
  71. if(++m_bnext < m_bend){
  72. m_current_value = *m_bnext;
  73. return;
  74. }
  75. ++(this->base_reference());
  76. m_bnext = NULL;
  77. m_bend = NULL;
  78. m_full = false;
  79. }
  80. // buffer to handle pending characters
  81. const base_value_type *m_bnext;
  82. const base_value_type *m_bend;
  83. bool m_full;
  84. BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type m_current_value;
  85. public:
  86. escape(Base base) :
  87. super_t(base),
  88. m_bnext(NULL),
  89. m_bend(NULL),
  90. m_full(false)
  91. {
  92. }
  93. };
  94. } // namespace iterators
  95. } // namespace archive
  96. } // namespace boost
  97. #endif // BOOST_ARCHIVE_ITERATORS_ESCAPE_HPP