ReactOS  0.4.15-dev-1070-ge1a01de
_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
67 template <class _Tp,
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& > {
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
76 template <class _Tp>
77 class 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
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 */
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 
97 public:
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 
140 private:
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)
157 template <class _TpP,
158  class _CharT = char, class _Traits = char_traits<_CharT> >
159 #else
160 template <class _TpP>
161 #endif
162 class 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
170 public:
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; }
188 private:
190  const _CharT* _M_string;
191 };
192 
193 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
194 # if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
195 template <class _TpP>
198 # else
199 template <class _TpP, class _CharT, class _Traits>
202 # endif
203 #endif
204 
206 
207 // form-independent definiotion of stream iterators
209 
210 template < __ISI_TMPL_HEADER_ARGUMENTS >
211 inline bool _STLP_CALL
214 { return __x._M_equal(__y); }
215 
216 #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
217 template < __ISI_TMPL_HEADER_ARGUMENTS >
218 inline bool _STLP_CALL
221 { return !__x._M_equal(__y); }
222 #endif
223 
224 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
225 template < __ISI_TMPL_HEADER_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; }
232 
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; }
237 # else
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 */
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:
bool _STLP_CALL operator!=(const allocator< _T1 > &, const allocator< _T2 > &) _STLP_NOTHROW
Definition: _alloc.h:384
ostream_type * _M_stream
const _Tp & reference
#define output_iterator_tag
Definition: _abbrevs.h:26
bool _M_equal(const _Self &__x) const
istream_type * _M_stream
ostream_iterator(ostream_type &__s, const _CharT *__c)
_STLP_DEFINE_ARROW_OPERATOR _Self & operator++()
bool fail() const
Definition: _ios_base.h:174
#define input_iterator_tag
Definition: _abbrevs.h:25
_Self & operator++(int)
istream_iterator(istream_type &__s)
const _CharT * _M_string
#define __c
Definition: schilyio.h:209
_STLP_END_NAMESPACE _STLP_BEGIN_NAMESPACE bool _STLP_CALL operator==(const istream_iterator< __ISI_TMPL_ARGUMENTS > &__x, const istream_iterator< __ISI_TMPL_ARGUMENTS > &__y)
#define true
Definition: osdep.h:36
output_iterator_tag iterator_category
unsigned char
Definition: typeof.h:29
#define false
Definition: osdep.h:35
istream_iterator< __ISI_TMPL_ARGUMENTS > _Self
#define _STLP_MUTABLE(type, x)
Definition: features.h:634
basic_istream< _CharT, _Traits > istream_type
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
basic_ostream< _CharT, _Traits > ostream_type
_Self & operator=(const _TpP &__val)
input_iterator_tag iterator_category
ostream_iterator(ostream_type &__s)
ostream_iterator< _TpP, _CharT, _Traits > _Self
void _M_read() const
reference operator *() const
#define _STLP_END_NAMESPACE
Definition: features.h:503
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define _STLP_DEFINE_ARROW_OPERATOR
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_CALL
Definition: _bc.h:131