epoc32/include/stdapis/stlportv5/stl/_istreambuf_iterator.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_istreambuf_iterator.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  * Copyright (c) 1999
     3  * Silicon Graphics Computer Systems, Inc.
     4  *
     5  * Copyright (c) 1999 
     6  * Boris Fomitchev
     7  *
     8  * This material is provided "as is", with absolutely no warranty expressed
     9  * or implied. Any use is at your own risk.
    10  *
    11  * Permission to use or copy this software for any purpose is hereby granted 
    12  * without fee, provided the above notices are retained on all copies.
    13  * Permission to modify the code and to distribute modified code is granted,
    14  * provided the above notices are retained, and a notice that the code was
    15  * modified is included with the above copyright notice.
    16  *
    17  */ 
    18 // WARNING: This is an internal header file, included by other C++
    19 // standard library headers.  You should not attempt to use this header
    20 // file directly.
    21 
    22 
    23 #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
    24 #define _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
    25 
    26 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    27 # include <stl/_iterator_base.h>
    28 #endif
    29 
    30 #ifndef _STLP_INTERNAL_STREAMBUF
    31 # include <stl/_streambuf.h>
    32 #endif
    33 
    34 _STLP_BEGIN_NAMESPACE
    35 
    36 // defined in _istream.h
    37 template <class _CharT, class _Traits>
    38 extern basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& ) ;
    39 
    40 // We do not read any characters until operator* is called. operator* calls sgetc 
    41 // unless the iterator is unchanged from the last call in which case a cached value is
    42 // used. Calls to operator++ use sbumpc.
    43 
    44 template<class _CharT, class _Traits>
    45 class istreambuf_iterator
    46 {
    47 public:
    48   typedef _CharT                           char_type;
    49   typedef _Traits                          traits_type;
    50   typedef typename _Traits::int_type       int_type;
    51   typedef basic_streambuf<_CharT, _Traits> streambuf_type;
    52   typedef basic_istream<_CharT, _Traits>   istream_type;
    53 
    54   typedef input_iterator_tag               iterator_category;
    55   typedef _CharT                           value_type;
    56   typedef typename _Traits::off_type       difference_type;
    57   typedef const _CharT*                    pointer;
    58   typedef const _CharT&                    reference;
    59 
    60 public:
    61   istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
    62   //  istreambuf_iterator(basic_istream<_CharT, _Traits>& __is) { this->_M_init(_M_get_istreambuf(__is)); }
    63   inline istreambuf_iterator(basic_istream<_CharT, _Traits>& __is);
    64 
    65   char_type operator*() const { this->_M_getc(); return _M_c; }
    66   istreambuf_iterator<_CharT, _Traits>& operator++() { this->_M_bumpc(); return *this; }
    67   istreambuf_iterator<_CharT, _Traits>  operator++(int);
    68 
    69   bool equal(const istreambuf_iterator<_CharT, _Traits>& __i) const {
    70     if (this->_M_buf)
    71       this->_M_getc();
    72     if (__i._M_buf)
    73       __i._M_getc(); 
    74     return this->_M_eof == __i._M_eof;
    75   }
    76 
    77 private:
    78   void _M_init(streambuf_type* __p) {
    79     _M_buf = __p;
    80     _M_eof = !__p;
    81     //    _M_is_initialized = _M_eof;
    82     _M_have_c = false;
    83   }
    84 
    85   void _M_getc() const {
    86     if (_M_have_c)
    87       return;
    88     int_type __c = _M_buf->sgetc();
    89 # if !defined (_STLP_NEED_MUTABLE) /* && ! defined (__SUNPRO_CC) */
    90     _M_c = traits_type::to_char_type(__c);
    91     _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
    92     _M_have_c = true;
    93 # else
    94     typedef istreambuf_iterator<_CharT,_Traits> _Self;
    95     _Self* __that = __CONST_CAST(_Self*, this);
    96     __that->_M_c = __STATIC_CAST(_CharT, traits_type::to_char_type(__c));
    97     __that->_M_eof = traits_type::eq_int_type(__c, traits_type::eof());
    98     __that->_M_have_c = true;
    99 # endif
   100   }
   101 
   102   int_type _M_bumpc() {
   103   	int_type ch = _M_buf->sbumpc();
   104      _M_have_c = false;
   105 	 return ch;
   106   }
   107 
   108 private:
   109   streambuf_type* _M_buf;
   110   mutable _CharT _M_c;
   111   mutable unsigned char _M_eof;
   112   mutable unsigned char _M_have_c;
   113 };
   114 
   115 template<class _CharT, class _Traits>
   116 inline istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator(basic_istream<_CharT, _Traits>& __is) 
   117 { this->_M_init(_M_get_istreambuf(__is)); }
   118 
   119 template<class _CharT, class _Traits>
   120 inline bool _STLP_CALL operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
   121                                   const istreambuf_iterator<_CharT, _Traits>& __y) {
   122   return __x.equal(__y);
   123 }
   124 
   125 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   126 
   127 template<class _CharT, class _Traits>
   128 inline bool _STLP_CALL operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
   129                                   const istreambuf_iterator<_CharT, _Traits>& __y) {
   130   return !__x.equal(__y);
   131 }
   132 
   133 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
   134 
   135 # if defined (_STLP_USE_TEMPLATE_EXPORT)
   136 _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<char, char_traits<char> >;
   137 #  if defined (INSTANTIATE_WIDE_STREAMS)
   138 _STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
   139 #  endif
   140 # endif /* _STLP_USE_TEMPLATE_EXPORT */
   141 
   142 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   143 template <class _CharT, class _Traits>
   144 inline input_iterator_tag _STLP_CALL iterator_category(const istreambuf_iterator<_CharT, _Traits>&) { return input_iterator_tag(); }
   145 template <class _CharT, class _Traits>
   146 inline streamoff* _STLP_CALL 
   147 distance_type(const istreambuf_iterator<_CharT, _Traits>&) { return (streamoff*)0; }
   148 template <class _CharT, class _Traits>
   149 inline _CharT* _STLP_CALL value_type(const istreambuf_iterator<_CharT, _Traits>&) { return (_CharT*)0; }
   150 # endif
   151 
   152 template <class _CharT, class _Traits>
   153 istreambuf_iterator<_CharT, _Traits>
   154 istreambuf_iterator<_CharT, _Traits>::operator++(int) {
   155   istreambuf_iterator<_CharT, _Traits> __tmp = *this;
   156   __tmp._M_c = this->_M_bumpc();
   157   __tmp._M_have_c = true;
   158   this->_M_have_c = false;
   159   return __tmp;
   160 }
   161 
   162 _STLP_END_NAMESPACE
   163 
   164 #endif /* _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H */
   165 
   166 // Local Variables:
   167 // mode:C++
   168 // End:
   169