/project/jni/stlport/stlport/stl/_istreambuf_iterator.h

https://github.com/aichunyu/FFPlayer · C Header · 170 lines · 113 code · 27 blank · 30 comment · 8 complexity · 0b9a3867d5276e1c0be141a423bf8804 MD5 · raw file

  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers. You should not attempt to use this header
  20. // file directly.
  21. #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
  22. #define _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
  23. #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
  24. # include <stl/_iterator_base.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_STREAMBUF
  27. # include <stl/_streambuf.h>
  28. #endif
  29. _STLP_BEGIN_NAMESPACE
  30. // defined in _istream.h
  31. template <class _CharT, class _Traits>
  32. extern basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& ) ;
  33. // We do not read any characters until operator* is called. operator* calls sgetc
  34. // unless the iterator is unchanged from the last call in which case a cached value is
  35. // used. Calls to operator++ use sbumpc.
  36. template<class _CharT, class _Traits>
  37. class istreambuf_iterator :
  38. public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT&>
  39. {
  40. public:
  41. typedef _CharT char_type;
  42. typedef _Traits traits_type;
  43. typedef typename _Traits::int_type int_type;
  44. typedef basic_streambuf<_CharT, _Traits> streambuf_type;
  45. typedef basic_istream<_CharT, _Traits> istream_type;
  46. typedef input_iterator_tag iterator_category;
  47. typedef _CharT value_type;
  48. typedef typename _Traits::off_type difference_type;
  49. typedef const _CharT* pointer;
  50. typedef const _CharT& reference;
  51. public:
  52. istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
  53. // istreambuf_iterator(basic_istream<_CharT, _Traits>& __is) { this->_M_init(_M_get_istreambuf(__is)); }
  54. inline istreambuf_iterator(basic_istream<_CharT, _Traits>& __is);
  55. char_type operator*() const { this->_M_getc(); return _M_c; }
  56. istreambuf_iterator<_CharT, _Traits>& operator++()
  57. {
  58. _M_buf->sbumpc();
  59. _M_have_c = false;
  60. return *this;
  61. }
  62. istreambuf_iterator<_CharT, _Traits> operator++(int);
  63. bool equal(const istreambuf_iterator<_CharT, _Traits>& __i) const {
  64. if (this->_M_buf)
  65. this->_M_getc();
  66. if (__i._M_buf)
  67. __i._M_getc();
  68. return this->_M_eof == __i._M_eof;
  69. }
  70. private:
  71. void _M_init(streambuf_type* __p) {
  72. _M_buf = __p;
  73. _M_eof = (__p == 0);
  74. _M_have_c = false;
  75. }
  76. void _M_getc() const {
  77. if (_M_have_c)
  78. return;
  79. int_type __c = _M_buf->sgetc();
  80. # if !defined (_STLP_NEED_MUTABLE) /* && ! defined (__SUNPRO_CC) */
  81. _M_c = traits_type::to_char_type(__c);
  82. _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
  83. _M_have_c = true;
  84. # else
  85. typedef istreambuf_iterator<_CharT,_Traits> _Self;
  86. _Self* __that = __CONST_CAST(_Self*, this);
  87. __that->_M_c = __STATIC_CAST(_CharT, traits_type::to_char_type(__c));
  88. __that->_M_eof = traits_type::eq_int_type(__c, traits_type::eof());
  89. __that->_M_have_c = true;
  90. # endif
  91. }
  92. private:
  93. streambuf_type* _M_buf;
  94. mutable _CharT _M_c;
  95. mutable bool _M_eof;
  96. mutable bool _M_have_c;
  97. };
  98. template<class _CharT, class _Traits>
  99. inline istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator(basic_istream<_CharT, _Traits>& __is)
  100. { this->_M_init(_M_get_istreambuf(__is)); }
  101. template<class _CharT, class _Traits>
  102. inline bool _STLP_CALL operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
  103. const istreambuf_iterator<_CharT, _Traits>& __y) {
  104. return __x.equal(__y);
  105. }
  106. #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
  107. template<class _CharT, class _Traits>
  108. inline bool _STLP_CALL operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
  109. const istreambuf_iterator<_CharT, _Traits>& __y) {
  110. return !__x.equal(__y);
  111. }
  112. #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  113. # if defined (_STLP_USE_TEMPLATE_EXPORT)
  114. _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<char, char_traits<char> >;
  115. # if defined (INSTANTIATE_WIDE_STREAMS)
  116. _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
  117. # endif
  118. # endif /* _STLP_USE_TEMPLATE_EXPORT */
  119. # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  120. template <class _CharT, class _Traits>
  121. inline input_iterator_tag _STLP_CALL iterator_category(const istreambuf_iterator<_CharT, _Traits>&) { return input_iterator_tag(); }
  122. template <class _CharT, class _Traits>
  123. inline streamoff* _STLP_CALL
  124. distance_type(const istreambuf_iterator<_CharT, _Traits>&) { return (streamoff*)0; }
  125. template <class _CharT, class _Traits>
  126. inline _CharT* _STLP_CALL value_type(const istreambuf_iterator<_CharT, _Traits>&) { return (_CharT*)0; }
  127. # endif
  128. template <class _CharT, class _Traits>
  129. istreambuf_iterator<_CharT, _Traits>
  130. istreambuf_iterator<_CharT, _Traits>::operator++(int) {
  131. _M_getc(); // __tmp should avoid any future actions under
  132. // underlined buffer---during call of operator *()
  133. // (due to buffer for *this and __tmp are the same).
  134. istreambuf_iterator<_CharT, _Traits> __tmp = *this;
  135. _M_buf->sbumpc();
  136. _M_have_c = false;
  137. return __tmp;
  138. }
  139. _STLP_END_NAMESPACE
  140. #endif /* _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H */
  141. // Local Variables:
  142. // mode:C++
  143. // End: