ReactOS  0.4.15-dev-1201-gb2cf5a4
_istreambuf_iterator.h
Go to the documentation of this 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 
22 
23 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
24 #define _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
25 
26 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
27 # include <stl/_iterator_base.h>
28 #endif
29 
30 #ifndef _STLP_INTERNAL_STREAMBUF
31 # include <stl/_streambuf.h>
32 #endif
33 
35 
36 // defined in _istream.h
37 template <class _CharT, class _Traits>
39 
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.
43 
44 template<class _CharT, class _Traits>
45 class istreambuf_iterator :
46  public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT&>
47 {
48 public:
49  typedef _CharT char_type;
50  typedef _Traits traits_type;
51  typedef typename _Traits::int_type int_type;
54 
56  typedef _CharT value_type;
57  typedef typename _Traits::off_type difference_type;
58  typedef const _CharT* pointer;
59  typedef const _CharT& reference;
60 
61 public:
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)); }
65 
66  char_type operator*() const { this->_M_getc(); return _M_c; }
68  _M_buf->sbumpc();
69  _M_have_c = false;
70  return *this;
71  }
73 
75  if (this->_M_buf)
76  this->_M_getc();
77  if (__i._M_buf)
78  __i._M_getc();
79  return this->_M_eof == __i._M_eof;
80  }
81 
82 private:
83  void _M_init(streambuf_type* __p) {
84  _M_buf = __p;
85  _M_eof = (__p == 0);
86  _M_have_c = false;
87  }
88 
89  void _M_getc() const {
90  if (_M_have_c)
91  return;
92  int_type __c = _M_buf->sgetc();
93  _STLP_MUTABLE(_Self, _M_c) = traits_type::to_char_type(__c);
94  _STLP_MUTABLE(_Self, _M_eof) = traits_type::eq_int_type(__c, traits_type::eof());
95  _STLP_MUTABLE(_Self, _M_have_c) = true;
96  }
97 
98 private:
100  mutable _CharT _M_c;
101  mutable bool _M_eof;
102  mutable bool _M_have_c;
103 };
104 
105 template<class _CharT, class _Traits>
107 { this->_M_init(_M_get_istreambuf(__is)); }
108 
109 template<class _CharT, class _Traits>
112  return __x.equal(__y);
113 }
114 
115 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
116 
117 template<class _CharT, class _Traits>
120  return !__x.equal(__y);
121 }
122 
123 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
124 
125 # if defined (_STLP_USE_TEMPLATE_EXPORT)
127 # if defined (INSTANTIATE_WIDE_STREAMS)
129 # endif
130 # endif /* _STLP_USE_TEMPLATE_EXPORT */
131 
132 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
133 template <class _CharT, class _Traits>
134 inline input_iterator_tag _STLP_CALL iterator_category(const istreambuf_iterator<_CharT, _Traits>&) { return input_iterator_tag(); }
135 template <class _CharT, class _Traits>
136 inline streamoff* _STLP_CALL
137 distance_type(const istreambuf_iterator<_CharT, _Traits>&) { return (streamoff*)0; }
138 template <class _CharT, class _Traits>
139 inline _CharT* _STLP_CALL value_type(const istreambuf_iterator<_CharT, _Traits>&) { return (_CharT*)0; }
140 # endif
141 
142 template <class _CharT, class _Traits>
145  _M_getc(); // __tmp should avoid any future actions under
146  // underlined buffer---during call of operator *()
147  // (due to buffer for *this and __tmp are the same).
149  _M_buf->sbumpc();
150  _M_have_c = false;
151  return __tmp;
152 }
153 
155 
156 #endif /* _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H */
157 
158 // Local Variables:
159 // mode:C++
160 // End:
161 
bool _STLP_CALL operator!=(const allocator< _T1 > &, const allocator< _T2 > &) _STLP_NOTHROW
Definition: _alloc.h:384
off_t streamoff
Definition: char_traits.h:74
istreambuf_iterator< _CharT, _Traits > & operator++()
#define input_iterator_tag
Definition: _abbrevs.h:25
#define __c
Definition: schilyio.h:209
void _M_init(streambuf_type *__p)
basic_streambuf< _CharT, _Traits > streambuf_type
int_type sbumpc()
Definition: _streambuf.h:227
input_iterator_tag iterator_category
#define _STLP_MUTABLE(type, x)
Definition: features.h:634
#define _STLP_EXPORT_TEMPLATE_CLASS
Definition: features.h:987
bool equal(const istreambuf_iterator< _CharT, _Traits > &__i) const
char_type operator *() const
bool _STLP_CALL operator==(const istreambuf_iterator< _CharT, _Traits > &__x, const istreambuf_iterator< _CharT, _Traits > &__y)
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
_STLP_BEGIN_NAMESPACE basic_streambuf< _CharT, _Traits > *_STLP_CALL _M_get_istreambuf(basic_istream< _CharT, _Traits > &)
Definition: _istream.h:346
#define _STLP_END_NAMESPACE
Definition: features.h:503
basic_istream< _CharT, _Traits > istream_type
istreambuf_iterator(streambuf_type *__p=0)
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
streambuf_type * _M_buf
_Traits::off_type difference_type
#define _STLP_CALL
Definition: _bc.h:131
_Traits::int_type int_type
int_type sgetc()
Definition: _streambuf.h:233