ReactOS 0.4.15-dev-7918-g2a2556c
_stream_iterator.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
5 *
6 * Copyright (c) 1996-1998
7 * Silicon Graphics Computer Systems, Inc.
8 *
9 * Copyright (c) 1997
10 * Moscow Center for SPARC Technology
11 *
12 * Copyright (c) 1999
13 * Boris Fomitchev
14 *
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
17 *
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.
23 *
24 */
25
26/* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
28 */
29
30#if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && !defined (_STLP_USE_NO_IOSTREAMS)
31#define _STLP_INTERNAL_STREAM_ITERATOR_H
32
33#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
34# include <stl/_iterator_base.h>
35#endif
36
37// streambuf_iterators predeclarations must appear first
38#ifndef _STLP_INTERNAL_IOSFWD
39# include <stl/_iosfwd.h>
40#endif
41
42#ifndef _STLP_INTERNAL_ALGOBASE_H
43# include <stl/_algobase.h>
44#endif
45
46#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
48#endif
49
50#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
52#endif
53
54#ifndef _STLP_INTERNAL_ISTREAM
55# include <stl/_istream.h>
56#endif
57
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
60// version.
61
63
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
67template <class _Tp,
68 class _CharT = char, class _Traits = char_traits<_CharT>,
69 class _Dist = ptrdiff_t>
70class istream_iterator : public iterator<input_iterator_tag, _Tp , _Dist,
71 const _Tp*, const _Tp& > {
72#else
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
76template <class _Tp>
77class istream_iterator : public iterator<input_iterator_tag, _Tp , ptrdiff_t,
78 const _Tp*, const _Tp& > {
79# else
80# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
81# define __ISI_TMPL_ARGUMENTS _Tp, _Dist
82template <class _Tp, _STLP_DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
83class 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 */
87
88#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
89 typedef char _CharT;
90 typedef char_traits<char> _Traits;
91# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
92 typedef ptrdiff_t _Dist;
93# endif
94#endif
95
97public:
98 typedef _CharT char_type;
99 typedef _Traits traits_type;
101
103 typedef _Tp value_type;
104 typedef _Dist difference_type;
105 typedef const _Tp* pointer;
106 typedef const _Tp& reference;
107
110
112 if (!_M_read_done) {
113 _M_read();
114 }
115 return _M_value;
116 }
117
119
121 _M_read();
122 return *this;
123 }
125 _Self __tmp = *this;
126 _M_read();
127 return __tmp;
128 }
129
130 bool _M_equal(const _Self& __x) const {
131 if (!_M_read_done) {
132 _M_read();
133 }
134 if (!__x._M_read_done) {
135 __x._M_read();
136 }
137 return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream);
138 }
139
140private:
142 mutable _Tp _M_value;
143 mutable bool _M_ok;
144 mutable bool _M_read_done;
145
146 void _M_read() const {
147 _STLP_MUTABLE(_Self, _M_ok) = ((_M_stream != 0) && !_M_stream->fail());
148 if (_M_ok) {
151 }
153 }
154};
155
156#if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
157template <class _TpP,
158 class _CharT = char, class _Traits = char_traits<_CharT> >
159#else
160template <class _TpP>
161#endif
162class ostream_iterator: public iterator<output_iterator_tag, void, void, void, void> {
163#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
164 typedef char _CharT;
165 typedef char_traits<char> _Traits;
167#else
169#endif
170public:
171 typedef _CharT char_type;
172 typedef _Traits traits_type;
174
176
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) {
181 *_M_stream << __val;
182 if (_M_string) *_M_stream << _M_string;
183 return *this;
184 }
185 _Self& operator*() { return *this; }
186 _Self& operator++() { return *this; }
187 _Self& operator++(int) { return *this; }
188private:
190 const _CharT* _M_string;
191};
192
193#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
194# if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
195template <class _TpP>
198# else
199template <class _TpP, class _CharT, class _Traits>
202# endif
203#endif
204
206
207// form-independent definiotion of stream iterators
209
210template < __ISI_TMPL_HEADER_ARGUMENTS >
211inline bool _STLP_CALL
214{ return __x._M_equal(__y); }
215
216#if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
217template < __ISI_TMPL_HEADER_ARGUMENTS >
218inline bool _STLP_CALL
221{ return !__x._M_equal(__y); }
222#endif
223
224#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
225template < __ISI_TMPL_HEADER_ARGUMENTS >
228{ return input_iterator_tag(); }
229template < __ISI_TMPL_HEADER_ARGUMENTS >
230inline _Tp* _STLP_CALL
231value_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Tp*) 0; }
232
233# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
234template < __ISI_TMPL_HEADER_ARGUMENTS >
235inline ptrdiff_t* _STLP_CALL
236distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (ptrdiff_t*)0; }
237# else
238template < __ISI_TMPL_HEADER_ARGUMENTS >
239inline _Dist* _STLP_CALL
240distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Dist*)0; }
241# endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
242#endif
243
245
246#undef __ISI_TMPL_HEADER_ARGUMENTS
247#undef __ISI_TMPL_ARGUMENTS
248
249#endif /* _STLP_INTERNAL_STREAM_ITERATOR_H */
250
251// Local Variables:
252// mode:C++
253// End:
#define input_iterator_tag
Definition: _abbrevs.h:25
#define output_iterator_tag
Definition: _abbrevs.h:26
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
bool _STLP_CALL operator!=(const allocator< _T1 > &, const allocator< _T2 > &) _STLP_NOTHROW
Definition: _alloc.h:384
#define _STLP_CALL
Definition: _bc.h:131
#define _STLP_DEFINE_ARROW_OPERATOR
_STLP_END_NAMESPACE _STLP_BEGIN_NAMESPACE bool _STLP_CALL operator==(const istream_iterator< __ISI_TMPL_ARGUMENTS > &__x, const istream_iterator< __ISI_TMPL_ARGUMENTS > &__y)
bool fail() const
Definition: _ios_base.h:174
reference operator*() const
const _Tp & reference
void _M_read() const
istream_iterator(istream_type &__s)
input_iterator_tag iterator_category
istream_type * _M_stream
basic_istream< _CharT, _Traits > istream_type
bool _M_equal(const _Self &__x) const
istream_iterator< __ISI_TMPL_ARGUMENTS > _Self
_STLP_DEFINE_ARROW_OPERATOR _Self & operator++()
ostream_iterator(ostream_type &__s)
ostream_iterator< _TpP, _CharT, _Traits > _Self
_Self & operator=(const _TpP &__val)
basic_ostream< _CharT, _Traits > ostream_type
ostream_iterator(ostream_type &__s, const _CharT *__c)
ostream_type * _M_stream
_Self & operator++(int)
const _CharT * _M_string
output_iterator_tag iterator_category
unsigned char
Definition: typeof.h:29
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define _STLP_MUTABLE(type, x)
Definition: features.h:634
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define __c
Definition: schilyio.h:209
#define true
Definition: stdbool.h:36
#define false
Definition: stdbool.h:37