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