unescape.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <cassert>
  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. typedef BOOST_DEDUCED_TYPENAME super_t::reference reference_type;
  45. public:
  46. // gcc 3.4.1 - linux required that this be public
  47. typedef BOOST_DEDUCED_TYPENAME super_t::value_type value_type;
  48. private:
  49. reference_type dereference_impl() {
  50. if(! m_full){
  51. m_current_value = static_cast<Derived *>(this)->drain();
  52. m_full = true;
  53. }
  54. return m_current_value;
  55. }
  56. reference_type dereference() const {
  57. return const_cast<this_t *>(this)->dereference_impl();
  58. }
  59. // value_type is const char - can't be const fix later
  60. value_type m_current_value;
  61. bool m_full;
  62. void increment(){
  63. ++(this->base_reference());
  64. dereference_impl();
  65. m_full = false;
  66. };
  67. public:
  68. unescape(Base base) :
  69. super_t(base),
  70. m_full(false)
  71. {}
  72. };
  73. } // namespace iterators
  74. } // namespace archive
  75. } // namespace boost
  76. #endif // BOOST_ARCHIVE_ITERATORS_UNESCAPE_HPP