ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_stream_iterator.h
Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996-1998
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1997
00010  * Moscow Center for SPARC Technology
00011  *
00012  * Copyright (c) 1999
00013  * Boris Fomitchev
00014  *
00015  * This material is provided "as is", with absolutely no warranty expressed
00016  * or implied. Any use is at your own risk.
00017  *
00018  * Permission to use or copy this software for any purpose is hereby granted
00019  * without fee, provided the above notices are retained on all copies.
00020  * Permission to modify the code and to distribute modified code is granted,
00021  * provided the above notices are retained, and a notice that the code was
00022  * modified is included with the above copyright notice.
00023  *
00024  */
00025 
00026 /* NOTE: This is an internal header file, included by other STL headers.
00027  *   You should not attempt to use it directly.
00028  */
00029 
00030 #if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && !defined (_STLP_USE_NO_IOSTREAMS)
00031 #define _STLP_INTERNAL_STREAM_ITERATOR_H
00032 
00033 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
00034 #  include <stl/_iterator_base.h>
00035 #endif
00036 
00037 // streambuf_iterators predeclarations must appear first
00038 #ifndef _STLP_INTERNAL_IOSFWD
00039 #  include <stl/_iosfwd.h>
00040 #endif
00041 
00042 #ifndef _STLP_INTERNAL_ALGOBASE_H
00043 #  include <stl/_algobase.h>
00044 #endif
00045 
00046 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
00047 #  include <stl/_ostreambuf_iterator.h>
00048 #endif
00049 
00050 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
00051 #  include <stl/_istreambuf_iterator.h>
00052 #endif
00053 
00054 #ifndef _STLP_INTERNAL_ISTREAM
00055 #  include <stl/_istream.h>
00056 #endif
00057 
00058 // istream_iterator and ostream_iterator look very different if we're
00059 // using new, templatized iostreams than if we're using the old cfront
00060 // version.
00061 
00062 _STLP_BEGIN_NAMESPACE
00063 
00064 #if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
00065 #  define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _CharT, class _Traits, class _Dist
00066 #  define __ISI_TMPL_ARGUMENTS _Tp, _CharT, _Traits, _Dist
00067 template <class _Tp,
00068           class _CharT = char, class _Traits = char_traits<_CharT>,
00069           class _Dist = ptrdiff_t>
00070 class istream_iterator : public iterator<input_iterator_tag, _Tp , _Dist,
00071                                          const _Tp*, const _Tp& > {
00072 #else
00073 #  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
00074 #    define __ISI_TMPL_HEADER_ARGUMENTS class _Tp
00075 #    define __ISI_TMPL_ARGUMENTS        _Tp
00076 template <class _Tp>
00077 class istream_iterator : public iterator<input_iterator_tag, _Tp , ptrdiff_t,
00078                                          const _Tp*, const _Tp& > {
00079 #  else
00080 #    define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
00081 #    define __ISI_TMPL_ARGUMENTS        _Tp, _Dist
00082 template <class _Tp, _STLP_DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
00083 class istream_iterator : public iterator<input_iterator_tag, _Tp, _Dist ,
00084                                          const _Tp*, const _Tp& > {
00085 #  endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
00086 #endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
00087 
00088 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
00089   typedef char _CharT;
00090   typedef char_traits<char> _Traits;
00091 #  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
00092   typedef ptrdiff_t _Dist;
00093 #  endif
00094 #endif
00095 
00096   typedef istream_iterator< __ISI_TMPL_ARGUMENTS > _Self;
00097 public:
00098   typedef _CharT                         char_type;
00099   typedef _Traits                        traits_type;
00100   typedef basic_istream<_CharT, _Traits> istream_type;
00101 
00102   typedef input_iterator_tag             iterator_category;
00103   typedef _Tp                            value_type;
00104   typedef _Dist                          difference_type;
00105   typedef const _Tp*                     pointer;
00106   typedef const _Tp&                     reference;
00107 
00108   istream_iterator() : _M_stream(0), _M_ok(false), _M_read_done(true) {}
00109   istream_iterator(istream_type& __s) : _M_stream(&__s), _M_ok(false), _M_read_done(false) {}
00110 
00111   reference operator*() const {
00112     if (!_M_read_done) {
00113       _M_read();
00114     }
00115     return _M_value;
00116   }
00117 
00118   _STLP_DEFINE_ARROW_OPERATOR
00119 
00120   _Self& operator++() {
00121     _M_read();
00122     return *this;
00123   }
00124   _Self operator++(int)  {
00125     _Self __tmp = *this;
00126     _M_read();
00127     return __tmp;
00128   }
00129 
00130   bool _M_equal(const _Self& __x) const {
00131     if (!_M_read_done) {
00132       _M_read();
00133     }
00134     if (!__x._M_read_done) {
00135       __x._M_read();
00136     }
00137     return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream);
00138   }
00139 
00140 private:
00141   istream_type* _M_stream;
00142   mutable _Tp _M_value;
00143   mutable bool _M_ok;
00144   mutable bool _M_read_done;
00145 
00146   void _M_read() const {
00147     _STLP_MUTABLE(_Self, _M_ok) = ((_M_stream != 0) && !_M_stream->fail());
00148     if (_M_ok) {
00149       *_M_stream >> _STLP_MUTABLE(_Self, _M_value);
00150       _STLP_MUTABLE(_Self, _M_ok) = !_M_stream->fail();
00151     }
00152     _STLP_MUTABLE(_Self, _M_read_done) = true;
00153   }
00154 };
00155 
00156 #if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
00157 template <class _TpP,
00158           class _CharT = char, class _Traits = char_traits<_CharT> >
00159 #else
00160 template <class _TpP>
00161 #endif
00162 class ostream_iterator: public iterator<output_iterator_tag, void, void, void, void> {
00163 #if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
00164   typedef char _CharT;
00165   typedef char_traits<char> _Traits;
00166   typedef ostream_iterator<_TpP> _Self;
00167 #else
00168   typedef ostream_iterator<_TpP, _CharT, _Traits> _Self;
00169 #endif
00170 public:
00171   typedef _CharT                         char_type;
00172   typedef _Traits                        traits_type;
00173   typedef basic_ostream<_CharT, _Traits> ostream_type;
00174 
00175   typedef output_iterator_tag            iterator_category;
00176 
00177   ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {}
00178   ostream_iterator(ostream_type& __s, const _CharT* __c)
00179     : _M_stream(&__s), _M_string(__c)  {}
00180   _Self& operator=(const _TpP& __val) {
00181     *_M_stream << __val;
00182     if (_M_string) *_M_stream << _M_string;
00183     return *this;
00184   }
00185   _Self& operator*() { return *this; }
00186   _Self& operator++() { return *this; }
00187   _Self& operator++(int) { return *this; }
00188 private:
00189   ostream_type* _M_stream;
00190   const _CharT* _M_string;
00191 };
00192 
00193 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
00194 #  if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
00195 template <class _TpP>
00196 inline output_iterator_tag _STLP_CALL
00197 iterator_category(const ostream_iterator<_TpP>&) { return output_iterator_tag(); }
00198 #  else
00199 template <class _TpP, class _CharT, class _Traits>
00200 inline output_iterator_tag _STLP_CALL
00201 iterator_category(const ostream_iterator<_TpP, _CharT, _Traits>&) { return output_iterator_tag(); }
00202 #  endif
00203 #endif
00204 
00205 _STLP_END_NAMESPACE
00206 
00207 // form-independent definiotion of stream iterators
00208 _STLP_BEGIN_NAMESPACE
00209 
00210 template < __ISI_TMPL_HEADER_ARGUMENTS >
00211 inline bool _STLP_CALL
00212 operator==(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
00213            const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y)
00214 { return __x._M_equal(__y); }
00215 
00216 #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
00217 template < __ISI_TMPL_HEADER_ARGUMENTS >
00218 inline bool _STLP_CALL
00219 operator!=(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
00220            const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y)
00221 { return !__x._M_equal(__y); }
00222 #endif
00223 
00224 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
00225 template < __ISI_TMPL_HEADER_ARGUMENTS >
00226 inline input_iterator_tag _STLP_CALL
00227 iterator_category(const istream_iterator< __ISI_TMPL_ARGUMENTS >&)
00228 { return input_iterator_tag(); }
00229 template < __ISI_TMPL_HEADER_ARGUMENTS >
00230 inline _Tp* _STLP_CALL
00231 value_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Tp*) 0; }
00232 
00233 #  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
00234 template < __ISI_TMPL_HEADER_ARGUMENTS >
00235 inline ptrdiff_t* _STLP_CALL
00236 distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (ptrdiff_t*)0; }
00237 #  else
00238 template < __ISI_TMPL_HEADER_ARGUMENTS >
00239 inline _Dist* _STLP_CALL
00240 distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Dist*)0; }
00241 #  endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
00242 #endif
00243 
00244 _STLP_END_NAMESPACE
00245 
00246 #undef __ISI_TMPL_HEADER_ARGUMENTS
00247 #undef __ISI_TMPL_ARGUMENTS
00248 
00249 #endif /* _STLP_INTERNAL_STREAM_ITERATOR_H */
00250 
00251 // Local Variables:
00252 // mode:C++
00253 // End:

Generated on Sat May 26 2012 04:28:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.