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