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

_istreambuf_iterator.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 // WARNING: This is an internal header file, included by other C++
00019 // standard library headers.  You should not attempt to use this header
00020 // file directly.
00021 
00022 
00023 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
00024 #define _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
00025 
00026 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
00027 # include <stl/_iterator_base.h>
00028 #endif
00029 
00030 #ifndef _STLP_INTERNAL_STREAMBUF
00031 # include <stl/_streambuf.h>
00032 #endif
00033 
00034 _STLP_BEGIN_NAMESPACE
00035 
00036 // defined in _istream.h
00037 template <class _CharT, class _Traits>
00038 extern basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& ) ;
00039 
00040 // We do not read any characters until operator* is called. operator* calls sgetc
00041 // unless the iterator is unchanged from the last call in which case a cached value is
00042 // used. Calls to operator++ use sbumpc.
00043 
00044 template<class _CharT, class _Traits>
00045 class istreambuf_iterator :
00046   public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT&>
00047 {
00048 public:
00049   typedef _CharT                           char_type;
00050   typedef _Traits                          traits_type;
00051   typedef typename _Traits::int_type       int_type;
00052   typedef basic_streambuf<_CharT, _Traits> streambuf_type;
00053   typedef basic_istream<_CharT, _Traits>   istream_type;
00054 
00055   typedef input_iterator_tag               iterator_category;
00056   typedef _CharT                           value_type;
00057   typedef typename _Traits::off_type       difference_type;
00058   typedef const _CharT*                    pointer;
00059   typedef const _CharT&                    reference;
00060 
00061 public:
00062   istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
00063   //  istreambuf_iterator(basic_istream<_CharT, _Traits>& __is) { this->_M_init(_M_get_istreambuf(__is)); }
00064   inline istreambuf_iterator(basic_istream<_CharT, _Traits>& __is);
00065 
00066   char_type operator*() const { this->_M_getc(); return _M_c; }
00067   istreambuf_iterator<_CharT, _Traits>& operator++() {
00068     _M_buf->sbumpc();
00069     _M_have_c = false;
00070     return *this;
00071   }
00072   istreambuf_iterator<_CharT, _Traits>  operator++(int);
00073 
00074   bool equal(const istreambuf_iterator<_CharT, _Traits>& __i) const {
00075     if (this->_M_buf)
00076       this->_M_getc();
00077     if (__i._M_buf)
00078       __i._M_getc();
00079     return this->_M_eof == __i._M_eof;
00080   }
00081 
00082 private:
00083   void _M_init(streambuf_type* __p) {
00084     _M_buf = __p;
00085     _M_eof = (__p == 0);
00086     _M_have_c = false;
00087   }
00088 
00089   void _M_getc() const {
00090     if (_M_have_c)
00091       return;
00092     int_type __c = _M_buf->sgetc();
00093     _STLP_MUTABLE(_Self, _M_c) = traits_type::to_char_type(__c);
00094     _STLP_MUTABLE(_Self, _M_eof) = traits_type::eq_int_type(__c, traits_type::eof());
00095     _STLP_MUTABLE(_Self, _M_have_c) = true;
00096   }
00097 
00098 private:
00099   streambuf_type* _M_buf;
00100   mutable _CharT _M_c;
00101   mutable bool _M_eof;
00102   mutable bool _M_have_c;
00103 };
00104 
00105 template<class _CharT, class _Traits>
00106 inline istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator(basic_istream<_CharT, _Traits>& __is)
00107 { this->_M_init(_M_get_istreambuf(__is)); }
00108 
00109 template<class _CharT, class _Traits>
00110 inline bool _STLP_CALL operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
00111                                   const istreambuf_iterator<_CharT, _Traits>& __y) {
00112   return __x.equal(__y);
00113 }
00114 
00115 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
00116 
00117 template<class _CharT, class _Traits>
00118 inline bool _STLP_CALL operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
00119                                   const istreambuf_iterator<_CharT, _Traits>& __y) {
00120   return !__x.equal(__y);
00121 }
00122 
00123 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
00124 
00125 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00126 _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<char, char_traits<char> >;
00127 #  if defined (INSTANTIATE_WIDE_STREAMS)
00128 _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
00129 #  endif
00130 # endif /* _STLP_USE_TEMPLATE_EXPORT */
00131 
00132 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
00133 template <class _CharT, class _Traits>
00134 inline input_iterator_tag _STLP_CALL iterator_category(const istreambuf_iterator<_CharT, _Traits>&) { return input_iterator_tag(); }
00135 template <class _CharT, class _Traits>
00136 inline streamoff* _STLP_CALL
00137 distance_type(const istreambuf_iterator<_CharT, _Traits>&) { return (streamoff*)0; }
00138 template <class _CharT, class _Traits>
00139 inline _CharT* _STLP_CALL value_type(const istreambuf_iterator<_CharT, _Traits>&) { return (_CharT*)0; }
00140 # endif
00141 
00142 template <class _CharT, class _Traits>
00143 istreambuf_iterator<_CharT, _Traits>
00144 istreambuf_iterator<_CharT, _Traits>::operator++(int) {
00145   _M_getc(); // __tmp should avoid any future actions under
00146   // underlined buffer---during call of operator *()
00147   // (due to buffer for *this and __tmp are the same).
00148   istreambuf_iterator<_CharT, _Traits> __tmp = *this;
00149   _M_buf->sbumpc();
00150   _M_have_c = false;
00151   return __tmp;
00152 }
00153 
00154 _STLP_END_NAMESPACE
00155 
00156 #endif /* _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H */
00157 
00158 // Local Variables:
00159 // mode:C++
00160 // End:
00161 

Generated on Sun May 27 2012 04:29: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.