unescape.hpp 2.3 KB

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