3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
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.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
23 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
24 #define _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
26 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
27 # include <stl/_iterator_base.h>
30 #ifndef _STLP_INTERNAL_STREAMBUF
31 # include <stl/_streambuf.h>
36 // defined in _istream.h
37 template <class _CharT, class _Traits>
38 extern basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& ) ;
40 // We do not read any characters until operator* is called. operator* calls sgetc
41 // unless the iterator is unchanged from the last call in which case a cached value is
42 // used. Calls to operator++ use sbumpc.
44 template<class _CharT, class _Traits>
45 class istreambuf_iterator :
46 public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT&>
49 typedef _CharT char_type;
50 typedef _Traits traits_type;
51 typedef typename _Traits::int_type int_type;
52 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
53 typedef basic_istream<_CharT, _Traits> istream_type;
55 typedef input_iterator_tag iterator_category;
56 typedef _CharT value_type;
57 typedef typename _Traits::off_type difference_type;
58 typedef const _CharT* pointer;
59 typedef const _CharT& reference;
62 istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
63 // istreambuf_iterator(basic_istream<_CharT, _Traits>& __is) { this->_M_init(_M_get_istreambuf(__is)); }
64 inline istreambuf_iterator(basic_istream<_CharT, _Traits>& __is);
66 char_type operator*() const { this->_M_getc(); return _M_c; }
67 istreambuf_iterator<_CharT, _Traits>& operator++()
73 istreambuf_iterator<_CharT, _Traits> operator++(int);
75 bool equal(const istreambuf_iterator<_CharT, _Traits>& __i) const {
80 return this->_M_eof == __i._M_eof;
84 void _M_init(streambuf_type* __p) {
90 void _M_getc() const {
93 int_type __c = _M_buf->sgetc();
94 # if !defined (_STLP_NEED_MUTABLE) /* && ! defined (__SUNPRO_CC) */
95 _M_c = traits_type::to_char_type(__c);
96 _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
99 typedef istreambuf_iterator<_CharT,_Traits> _Self;
100 _Self* __that = __CONST_CAST(_Self*, this);
101 __that->_M_c = __STATIC_CAST(_CharT, traits_type::to_char_type(__c));
102 __that->_M_eof = traits_type::eq_int_type(__c, traits_type::eof());
103 __that->_M_have_c = true;
108 streambuf_type* _M_buf;
111 mutable bool _M_have_c;
114 template<class _CharT, class _Traits>
115 inline istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator(basic_istream<_CharT, _Traits>& __is)
116 { this->_M_init(_M_get_istreambuf(__is)); }
118 template<class _CharT, class _Traits>
119 inline bool _STLP_CALL operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
120 const istreambuf_iterator<_CharT, _Traits>& __y) {
121 return __x.equal(__y);
124 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
126 template<class _CharT, class _Traits>
127 inline bool _STLP_CALL operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
128 const istreambuf_iterator<_CharT, _Traits>& __y) {
129 return !__x.equal(__y);
132 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
134 # if defined (_STLP_USE_TEMPLATE_EXPORT)
135 _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<char, char_traits<char> >;
136 # if defined (INSTANTIATE_WIDE_STREAMS)
137 _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
139 # endif /* _STLP_USE_TEMPLATE_EXPORT */
141 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
142 template <class _CharT, class _Traits>
143 inline input_iterator_tag _STLP_CALL iterator_category(const istreambuf_iterator<_CharT, _Traits>&) { return input_iterator_tag(); }
144 template <class _CharT, class _Traits>
145 inline streamoff* _STLP_CALL
146 distance_type(const istreambuf_iterator<_CharT, _Traits>&) { return (streamoff*)0; }
147 template <class _CharT, class _Traits>
148 inline _CharT* _STLP_CALL value_type(const istreambuf_iterator<_CharT, _Traits>&) { return (_CharT*)0; }
151 template <class _CharT, class _Traits>
152 istreambuf_iterator<_CharT, _Traits>
153 istreambuf_iterator<_CharT, _Traits>::operator++(int) {
154 _M_getc(); // __tmp should avoid any future actions under
155 // underlined buffer---during call of operator *()
156 // (due to buffer for *this and __tmp are the same).
157 istreambuf_iterator<_CharT, _Traits> __tmp = *this;
165 #endif /* _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H */