unescape.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef BOOST_ARCHIVE_ITERATORS_UNESCAPE_HPP
  2. #define BOOST_ARCHIVE_ITERATORS_UNESCAPE_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. // unescape.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 <boost/assert.hpp>
  15. #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
  16. #include <boost/iterator/iterator_adaptor.hpp>
  17. //#include <boost/iterator/iterator_traits.hpp>
  18. #include <boost/pointee.hpp>
  19. namespace boost {
  20. namespace archive {
  21. namespace iterators {
  22. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  23. // class used by text archives to translate char strings to wchar_t
  24. // strings of the currently selected locale
  25. template<class Derived, class Base>
  26. class unescape
  27. : public boost::iterator_adaptor<
  28. unescape<Derived, Base>,
  29. Base,
  30. BOOST_DEDUCED_TYPENAME pointee<Base>::type,
  31. single_pass_traversal_tag,
  32. BOOST_DEDUCED_TYPENAME pointee<Base>::type
  33. >
  34. {
  35. friend class boost::iterator_core_access;
  36. typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor<
  37. unescape<Derived, Base>,
  38. Base,
  39. BOOST_DEDUCED_TYPENAME pointee<Base>::type,
  40. single_pass_traversal_tag,
  41. BOOST_DEDUCED_TYPENAME pointee<Base>::type
  42. > super_t;
  43. typedef unescape<Derived, Base> this_t;
  44. public:
  45. typedef BOOST_DEDUCED_TYPENAME this_t::value_type value_type;
  46. typedef BOOST_DEDUCED_TYPENAME this_t::reference reference;
  47. private:
  48. value_type dereference_impl() {
  49. if(! m_full){
  50. m_current_value = static_cast<Derived *>(this)->drain();
  51. m_full = true;
  52. }
  53. return m_current_value;
  54. }
  55. reference dereference() const {
  56. return const_cast<this_t *>(this)->dereference_impl();
  57. }
  58. value_type m_current_value;
  59. bool m_full;
  60. void increment(){
  61. ++(this->base_reference());
  62. dereference_impl();
  63. m_full = false;
  64. };
  65. public:
  66. unescape(Base base) :
  67. super_t(base),
  68. m_full(false)
  69. {}
  70. };
  71. } // namespace iterators
  72. } // namespace archive
  73. } // namespace boost
  74. #endif // BOOST_ARCHIVE_ITERATORS_UNESCAPE_HPP