Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_ioiter.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_RW_IOITER_H_INCLUDED
33#define _RWSTD_RW_IOITER_H_INCLUDED
34
35#ifndef _RWSTD_RW_IOSFWD_H_INCLUDED
36# include <rw/_iosfwd.h>
37#endif // _RWSTD_RW_IOSFWD_H_INCLUDED
38
39#ifndef _RWSTD_RW_ITERBASE_H_INCLUDED
40# include <rw/_iterbase.h>
41#endif // _RWSTD_RW_ITERBASE_H_INCLUDED
42
43
45
46
47#ifndef _RWSTD_IOSFWD_INCLUDED
48
49template <class _CharT, class _Traits = char_traits<_CharT> >
50struct istreambuf_iterator;
51
52template <class _CharT, class _Traits = char_traits<_CharT> >
53struct ostreambuf_iterator;
54
55#endif // _RWSTD_IOSFWD_INCLUDED
56
57
58// 24.5.3
59template <class _CharT, class _Traits>
60struct istreambuf_iterator
61 : iterator<input_iterator_tag, _CharT,
62 typename _Traits::off_type, _CharT*, _CharT&>
63{
64 typedef _CharT char_type;
65 typedef _Traits traits_type;
66 typedef typename traits_type::int_type int_type;
67 typedef basic_streambuf<char_type, traits_type> streambuf_type;
68 typedef basic_istream<char_type, traits_type> istream_type;
69
70private:
71
72 // 24.5.3.1 (exposition only)
73 class _C_proxy {
74 char_type _C_keep;
75 streambuf_type *_C_sb;
76
77 _C_proxy (char_type __c, streambuf_type *__sb)
78 : _C_keep (__c), _C_sb (__sb) { }
79
80 public:
81
82 char_type operator* () const {
83 return _C_keep;
84 }
85
86 friend struct istreambuf_iterator<char_type, traits_type>;
87 };
88
89public:
90
91#ifndef _RWSTD_STRICT_ANSI
92
93 // expose proxy in relaxed mode
94 typedef _C_proxy proxy;
95
96#endif // _RWSTD_STRICT_ANSI
97
98 // 24.5.3.2, p1
99 istreambuf_iterator (streambuf_type *__sb = 0) _THROWS (())
100 : _C_sb (__sb) { }
101
102 // 24.5.3.2, p2
103 istreambuf_iterator (istream_type&) _THROWS (());
104
105 // 24.5.3.2, p3
106 istreambuf_iterator (const _C_proxy &__proxy) _THROWS (())
107 : _C_sb (__proxy._C_sb) { }
108
109 // 24.5.3.3, p1
110 char_type operator*() const;
111
112 // 24.5.3.4, p1
113 istreambuf_iterator& operator++ ();
114
115 // 24.5.3.4, p3
116 _C_proxy operator++ (int);
117
118 // 24.5.3.5, p1 - const follows the resolution of lwg issue 110
119 bool equal (const istreambuf_iterator&) const;
120
121private:
122 streambuf_type *_C_sb;
123};
124
125
126// defined here as opposed to within the body of the class
127// to work around IBM VisualAge C++ bug #396 (PMR 02173)
128template <class _CharT, class _Traits>
129inline istreambuf_iterator<_CharT, _Traits>::
130istreambuf_iterator (istream_type &__strm) _THROWS (())
131 : _C_sb (__strm.rdbuf ())
132{
133 // no-op
134}
135
136
137template <class _CharT, class _Traits>
138inline typename istreambuf_iterator<_CharT, _Traits>::char_type
139istreambuf_iterator<_CharT, _Traits>::
140operator*() const
141{
142 _RWSTD_ASSERT (0 != _C_sb);
143 _RWSTD_ASSERT (!equal (istreambuf_iterator ()));
144
145 return traits_type::to_char_type (_C_sb->sgetc ());
146}
147
148
149template <class _CharT, class _Traits>
150inline istreambuf_iterator<_CharT, _Traits>&
151istreambuf_iterator<_CharT, _Traits>::
152operator++()
153{
154 _RWSTD_ASSERT (0 != _C_sb);
155 _RWSTD_ASSERT (!equal (istreambuf_iterator ()));
156
157 _C_sb->sbumpc ();
158
159 return *this;
160}
161
162
163template <class _CharT, class _Traits>
164inline typename istreambuf_iterator<_CharT, _Traits>::_C_proxy
165istreambuf_iterator<_CharT, _Traits>::
166operator++(int)
167{
168 _RWSTD_ASSERT (0 != _C_sb);
169 _RWSTD_ASSERT (!equal (istreambuf_iterator ()));
170
171 return _C_proxy (traits_type::to_char_type (_C_sb->sbumpc ()), _C_sb);
172}
173
174
175template <class _CharT, class _Traits>
176inline bool
177istreambuf_iterator<_CharT, _Traits>::
178equal (const istreambuf_iterator &__rhs) const
179{
180 // Returns true if and only if both iterators are at end-of-stream,
181 // or neither is at end-of-stream, regardless of what streambuf
182 // object they use.
183 // See also lwg issue 111.
184
185 const int_type __eof = traits_type::eof ();
186
187 const bool __eof_lhs =
188 !_C_sb || traits_type::eq_int_type (_C_sb->sgetc (), __eof);
189
190 const bool __eof_rhs =
191 !__rhs._C_sb || traits_type::eq_int_type (__rhs._C_sb->sgetc(), __eof);
192
193 return __eof_lhs == __eof_rhs;
194}
195
196
197// 24.5.3.6
198template <class _CharT, class _Traits>
199inline bool
200operator== (const istreambuf_iterator<_CharT, _Traits>& __x,
201 const istreambuf_iterator<_CharT, _Traits>& __y)
202{
203 return __x.equal (__y);
204}
205
206
207// 24.5.3.7
208template <class _CharT, class _Traits>
209inline bool
210operator!= (const istreambuf_iterator<_CharT, _Traits>& __x,
211 const istreambuf_iterator<_CharT, _Traits>& __y)
212{
213 return !__x.equal (__y);
214}
215
216
217// 24.5.4
218template <class _CharT, class _Traits>
219struct ostreambuf_iterator
220 : public iterator<output_iterator_tag, void, void, void, void>
221{
222 typedef _CharT char_type;
223 typedef _Traits traits_type;
224 typedef basic_streambuf<char_type, traits_type> streambuf_type;
225 typedef basic_ostream<char_type, traits_type> ostream_type;
226
227 // 24.5.4.1, p1
228 ostreambuf_iterator (ostream_type&) _THROWS (());
229
230 // 24.5.4.1, p2
231 ostreambuf_iterator (streambuf_type *__sb) _THROWS (())
232 : _C_sb (__sb) {
233 _RWSTD_ASSERT (__sb != 0);
234 }
235
236 // 24.5.4.2, p3
237 ostreambuf_iterator& operator* () {
238 return *this;
239 }
240
241 // 24.5.4.2, p4
242 ostreambuf_iterator& operator++ () {
243 return *this;
244 }
245
246 // 24.5.4.2, p4
247 ostreambuf_iterator& operator++ (int) {
248 return *this;
249 }
250
251 // 24.5.4.2, p1
252 ostreambuf_iterator& operator= (char_type __c) {
253 if (_C_sb && traits_type::eq_int_type (_C_sb->sputc (__c),
254 traits_type::eof ()))
255 _C_sb = 0;
256 return *this;
257 }
258
259 // 24.5.4.2, p5
260 bool failed () const _THROWS (()) {
261 return !_C_sb;
262 }
263
264private:
265 streambuf_type *_C_sb;
266};
267
268
269// defined here as opposed to within the body of the class
270// to work around IBM VisualAge C++ bug #396 (PMR 02173)
271template <class _CharT, class _Traits>
272inline ostreambuf_iterator<_CharT, _Traits>::
273ostreambuf_iterator (ostream_type &__strm) _THROWS (())
274 : _C_sb (__strm.rdbuf ())
275{
276 _RWSTD_ASSERT (__strm.rdbuf () != 0); // lwg issue 112
277}
278
279
280} // namespace std
281
282
283#endif // _RWSTD_RW_IOITER_H_INCLUDED
bool equal(const T &x, const U &y)
const plus_asgn< T > & operator*(const plus_asgn< T > &lhs, const plus_asgn< T > &rhs)
#define _THROWS()
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
Definition json.h:5363