4 * Hewlett-Packard Company
6 * Copyright (c) 1996-1998
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && !defined (_STLP_USE_NO_IOSTREAMS)
31 #define _STLP_INTERNAL_STREAM_ITERATOR_H
33 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
34 # include <stl/_iterator_base.h>
37 // streambuf_iterators predeclarations must appear first
38 #ifndef _STLP_INTERNAL_IOSFWD
39 # include <stl/_iosfwd.h>
42 #ifndef _STLP_INTERNAL_ALGOBASE_H
43 # include <stl/_algobase.h>
46 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
47 # include <stl/_ostreambuf_iterator.h>
50 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
51 # include <stl/_istreambuf_iterator.h>
54 #ifndef _STLP_INTERNAL_ISTREAM
55 # include <stl/_istream.h>
58 // istream_iterator and ostream_iterator look very different if we're
59 // using new, templatized iostreams than if we're using the old cfront
64 #if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
65 # define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _CharT, class _Traits, class _Dist
66 # define __ISI_TMPL_ARGUMENTS _Tp, _CharT, _Traits, _Dist
68 class _CharT
= char, class _Traits
= char_traits
<_CharT
>,
69 class _Dist
= ptrdiff_t>
70 class istream_iterator
: public iterator
<input_iterator_tag
, _Tp
, _Dist
,
71 const _Tp
*, const _Tp
& > {
73 # if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
74 # define __ISI_TMPL_HEADER_ARGUMENTS class _Tp
75 # define __ISI_TMPL_ARGUMENTS _Tp
77 class istream_iterator
: public iterator
<input_iterator_tag
, _Tp
, ptrdiff_t,
78 const _Tp
*, const _Tp
& > {
80 # define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
81 # define __ISI_TMPL_ARGUMENTS _Tp, _Dist
82 template <class _Tp
, _STLP_DFL_TYPE_PARAM(_Dist
, ptrdiff_t)>
83 class istream_iterator
: public iterator
<input_iterator_tag
, _Tp
, _Dist
,
84 const _Tp
*, const _Tp
& > {
85 # endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
86 #endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
88 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
90 typedef char_traits
<char> _Traits
;
91 # if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
92 typedef ptrdiff_t _Dist
;
96 typedef istream_iterator
< __ISI_TMPL_ARGUMENTS
> _Self
;
98 typedef _CharT char_type
;
99 typedef _Traits traits_type
;
100 typedef basic_istream
<_CharT
, _Traits
> istream_type
;
102 typedef input_iterator_tag iterator_category
;
103 typedef _Tp value_type
;
104 typedef _Dist difference_type
;
105 typedef const _Tp
* pointer
;
106 typedef const _Tp
& reference
;
108 istream_iterator() : _M_stream(0), _M_ok(false), _M_read_done(true) {}
109 istream_iterator(istream_type
& __s
) : _M_stream(&__s
), _M_ok(false), _M_read_done(false) {}
111 reference
operator*() const {
118 _STLP_DEFINE_ARROW_OPERATOR
120 _Self
& operator++() {
124 _Self
operator++(int) {
130 bool _M_equal(const _Self
& __x
) const {
134 if (!__x
._M_read_done
) {
137 return (_M_ok
== __x
._M_ok
) && (!_M_ok
|| _M_stream
== __x
._M_stream
);
141 istream_type
* _M_stream
;
142 mutable _Tp _M_value
;
144 mutable bool _M_read_done
;
146 void _M_read() const {
147 _STLP_MUTABLE(_Self
, _M_ok
) = ((_M_stream
!= 0) && !_M_stream
->fail());
149 *_M_stream
>> _STLP_MUTABLE(_Self
, _M_value
);
150 _STLP_MUTABLE(_Self
, _M_ok
) = !_M_stream
->fail();
152 _STLP_MUTABLE(_Self
, _M_read_done
) = true;
156 #if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
157 template <class _TpP
,
158 class _CharT
= char, class _Traits
= char_traits
<_CharT
> >
160 template <class _TpP
>
162 class ostream_iterator
: public iterator
<output_iterator_tag
, void, void, void, void> {
163 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
165 typedef char_traits
<char> _Traits
;
166 typedef ostream_iterator
<_TpP
> _Self
;
168 typedef ostream_iterator
<_TpP
, _CharT
, _Traits
> _Self
;
171 typedef _CharT char_type
;
172 typedef _Traits traits_type
;
173 typedef basic_ostream
<_CharT
, _Traits
> ostream_type
;
175 typedef output_iterator_tag iterator_category
;
177 ostream_iterator(ostream_type
& __s
) : _M_stream(&__s
), _M_string(0) {}
178 ostream_iterator(ostream_type
& __s
, const _CharT
* __c
)
179 : _M_stream(&__s
), _M_string(__c
) {}
180 _Self
& operator=(const _TpP
& __val
) {
182 if (_M_string
) *_M_stream
<< _M_string
;
185 _Self
& operator*() { return *this; }
186 _Self
& operator++() { return *this; }
187 _Self
& operator++(int) { return *this; }
189 ostream_type
* _M_stream
;
190 const _CharT
* _M_string
;
193 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
194 # if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
195 template <class _TpP
>
196 inline output_iterator_tag _STLP_CALL
197 iterator_category(const ostream_iterator
<_TpP
>&) { return output_iterator_tag(); }
199 template <class _TpP
, class _CharT
, class _Traits
>
200 inline output_iterator_tag _STLP_CALL
201 iterator_category(const ostream_iterator
<_TpP
, _CharT
, _Traits
>&) { return output_iterator_tag(); }
207 // form-independent definiotion of stream iterators
208 _STLP_BEGIN_NAMESPACE
210 template < __ISI_TMPL_HEADER_ARGUMENTS
>
211 inline bool _STLP_CALL
212 operator==(const istream_iterator
< __ISI_TMPL_ARGUMENTS
>& __x
,
213 const istream_iterator
< __ISI_TMPL_ARGUMENTS
>& __y
)
214 { return __x
._M_equal(__y
); }
216 #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
217 template < __ISI_TMPL_HEADER_ARGUMENTS
>
218 inline bool _STLP_CALL
219 operator!=(const istream_iterator
< __ISI_TMPL_ARGUMENTS
>& __x
,
220 const istream_iterator
< __ISI_TMPL_ARGUMENTS
>& __y
)
221 { return !__x
._M_equal(__y
); }
224 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
225 template < __ISI_TMPL_HEADER_ARGUMENTS
>
226 inline input_iterator_tag _STLP_CALL
227 iterator_category(const istream_iterator
< __ISI_TMPL_ARGUMENTS
>&)
228 { return input_iterator_tag(); }
229 template < __ISI_TMPL_HEADER_ARGUMENTS
>
230 inline _Tp
* _STLP_CALL
231 value_type(const istream_iterator
< __ISI_TMPL_ARGUMENTS
>&) { return (_Tp
*) 0; }
233 # if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
234 template < __ISI_TMPL_HEADER_ARGUMENTS
>
235 inline ptrdiff_t* _STLP_CALL
236 distance_type(const istream_iterator
< __ISI_TMPL_ARGUMENTS
>&) { return (ptrdiff_t*)0; }
238 template < __ISI_TMPL_HEADER_ARGUMENTS
>
239 inline _Dist
* _STLP_CALL
240 distance_type(const istream_iterator
< __ISI_TMPL_ARGUMENTS
>&) { return (_Dist
*)0; }
241 # endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
246 #undef __ISI_TMPL_HEADER_ARGUMENTS
247 #undef __ISI_TMPL_ARGUMENTS
249 #endif /* _STLP_INTERNAL_STREAM_ITERATOR_H */