epoc32/include/stdapis/stlportv5/stl/_stream_iterator.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_stream_iterator.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_stream_iterator.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -9,13 +9,13 @@
     1.4   * Copyright (c) 1997
     1.5   * Moscow Center for SPARC Technology
     1.6   *
     1.7 - * Copyright (c) 1999 
     1.8 + * Copyright (c) 1999
     1.9   * Boris Fomitchev
    1.10   *
    1.11   * This material is provided "as is", with absolutely no warranty expressed
    1.12   * or implied. Any use is at your own risk.
    1.13   *
    1.14 - * Permission to use or copy this software for any purpose is hereby granted 
    1.15 + * Permission to use or copy this software for any purpose is hereby granted
    1.16   * without fee, provided the above notices are retained on all copies.
    1.17   * Permission to modify the code and to distribute modified code is granted,
    1.18   * provided the above notices are retained, and a notice that the code was
    1.19 @@ -27,78 +27,71 @@
    1.20   *   You should not attempt to use it directly.
    1.21   */
    1.22  
    1.23 -#if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && ! defined (_STLP_USE_NO_IOSTREAMS)
    1.24 +#if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && !defined (_STLP_USE_NO_IOSTREAMS)
    1.25  #define _STLP_INTERNAL_STREAM_ITERATOR_H
    1.26  
    1.27  #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    1.28 -# include <stl/_iterator_base.h>
    1.29 +#  include <stl/_iterator_base.h>
    1.30  #endif
    1.31  
    1.32  // streambuf_iterators predeclarations must appear first
    1.33  #ifndef _STLP_IOSFWD
    1.34 -# include <iosfwd>
    1.35 +#  include <iosfwd>
    1.36  #endif
    1.37  
    1.38  #ifndef _STLP_INTERNAL_ALGOBASE_H
    1.39 -#include <stl/_algobase.h>
    1.40 +#  include <stl/_algobase.h>
    1.41  #endif
    1.42  
    1.43 -#if defined (_STLP_OWN_IOSTREAMS)
    1.44 -
    1.45  #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
    1.46 -# include <stl/_ostreambuf_iterator.h>
    1.47 +#  include <stl/_ostreambuf_iterator.h>
    1.48  #endif
    1.49  
    1.50  #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
    1.51 -# include <stl/_istreambuf_iterator.h>
    1.52 +#  include <stl/_istreambuf_iterator.h>
    1.53  #endif
    1.54  
    1.55 -#ifndef _STLP_INTERNAL_ISTREAM_H
    1.56 -# include <stl/_istream.h>
    1.57 +#ifndef _STLP_INTERNAL_ISTREAM
    1.58 +#  include <stl/_istream.h>
    1.59  #endif
    1.60 -#endif /* _STLP_OWN_IOSTREAMS */
    1.61  
    1.62  // istream_iterator and ostream_iterator look very different if we're
    1.63  // using new, templatized iostreams than if we're using the old cfront
    1.64  // version.
    1.65  
    1.66 -# if defined (_STLP_USE_NEW_IOSTREAMS) 
    1.67 -
    1.68  _STLP_BEGIN_NAMESPACE
    1.69  
    1.70 -#  ifndef _STLP_LIMITED_DEFAULT_TEMPLATES
    1.71 -template <class _Tp, 
    1.72 +#if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
    1.73 +#  define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _CharT, class _Traits, class _Dist
    1.74 +#  define __ISI_TMPL_ARGUMENTS _Tp, _CharT, _Traits, _Dist
    1.75 +template <class _Tp,
    1.76            class _CharT = _STLP_DEFAULTCHAR, class _Traits = char_traits<_CharT>,
    1.77 -          class _Dist = ptrdiff_t> 
    1.78 -#   define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _CharT, class _Traits, class _Dist
    1.79 -#   define __ISI_TMPL_ARGUMENTS _Tp, _CharT, _Traits, _Dist
    1.80 +          class _Dist = ptrdiff_t>
    1.81  class istream_iterator : public iterator<input_iterator_tag, _Tp , _Dist,
    1.82 -                         const _Tp*, const _Tp& > {
    1.83 -#  else
    1.84 -
    1.85 -#   if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
    1.86 +                                         const _Tp*, const _Tp& > {
    1.87 +#else
    1.88 +#  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
    1.89  #    define __ISI_TMPL_HEADER_ARGUMENTS class _Tp
    1.90  #    define __ISI_TMPL_ARGUMENTS        _Tp
    1.91  template <class _Tp>
    1.92 -class istream_iterator : public iterator<input_iterator_tag, _Tp , ptrdiff_t, 
    1.93 -                         const _Tp*, const _Tp& > {
    1.94 -#   else
    1.95 +class istream_iterator : public iterator<input_iterator_tag, _Tp , ptrdiff_t,
    1.96 +                                         const _Tp*, const _Tp& > {
    1.97 +#  else
    1.98  #    define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
    1.99  #    define __ISI_TMPL_ARGUMENTS        _Tp, _Dist
   1.100 -template <class _Tp,__DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
   1.101 -class istream_iterator : public iterator<input_iterator_tag, _Tp, _Dist , 
   1.102 +template <class _Tp, _STLP_DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
   1.103 +class istream_iterator : public iterator<input_iterator_tag, _Tp, _Dist ,
   1.104                                           const _Tp*, const _Tp& > {
   1.105 -#   endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
   1.106 +#  endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
   1.107 +#endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
   1.108  
   1.109 -#  endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
   1.110 -
   1.111 -# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
   1.112 +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
   1.113    typedef char _CharT;
   1.114    typedef char_traits<char> _Traits;
   1.115 -#  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
   1.116 +#  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
   1.117    typedef ptrdiff_t _Dist;
   1.118  #  endif
   1.119 -# endif
   1.120 +#endif
   1.121  
   1.122    typedef istream_iterator< __ISI_TMPL_ARGUMENTS > _Self;
   1.123  public:
   1.124 @@ -112,15 +105,20 @@
   1.125    typedef const _Tp*                     pointer;
   1.126    typedef const _Tp&                     reference;
   1.127  
   1.128 -  istream_iterator() : _M_stream(0), _M_ok(false) {}
   1.129 -  istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); }
   1.130 +  istream_iterator() : _M_stream(0), _M_ok(false), _M_read_done(true) {}
   1.131 +  istream_iterator(istream_type& __s) : _M_stream(&__s), _M_ok(false), _M_read_done(false) {}
   1.132  
   1.133 -  reference operator*() const { return _M_value; }
   1.134 +  reference operator*() const {
   1.135 +    if (!_M_read_done) {
   1.136 +      _M_read();
   1.137 +    }
   1.138 +    return _M_value;
   1.139 +  }
   1.140  
   1.141    _STLP_DEFINE_ARROW_OPERATOR
   1.142  
   1.143 -  _Self& operator++() { 
   1.144 -    _M_read(); 
   1.145 +  _Self& operator++() {
   1.146 +    _M_read();
   1.147      return *this;
   1.148    }
   1.149    _Self operator++(int)  {
   1.150 @@ -129,37 +127,46 @@
   1.151      return __tmp;
   1.152    }
   1.153  
   1.154 -  bool _M_equal(const _Self& __x) const
   1.155 -    { return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); }
   1.156 +  bool _M_equal(const _Self& __x) const {
   1.157 +    if (!_M_read_done) {
   1.158 +      _M_read();
   1.159 +    }
   1.160 +    if (!__x._M_read_done) {
   1.161 +      __x._M_read();
   1.162 +    }
   1.163 +    return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream);
   1.164 +  }
   1.165  
   1.166  private:
   1.167    istream_type* _M_stream;
   1.168 -  _Tp _M_value;
   1.169 -  bool _M_ok;
   1.170 +  mutable _Tp _M_value;
   1.171 +  mutable bool _M_ok;
   1.172 +  mutable bool _M_read_done;
   1.173  
   1.174 -  void _M_read() {
   1.175 -    _M_ok = (_M_stream && *_M_stream) ? true : false;
   1.176 +  void _M_read() const {
   1.177 +    _M_ok = ((_M_stream != 0) && !_M_stream->fail());
   1.178      if (_M_ok) {
   1.179        *_M_stream >> _M_value;
   1.180 -      _M_ok = *_M_stream ? true : false;
   1.181 +      _M_ok = !_M_stream->fail();
   1.182      }
   1.183 +    _M_read_done = true;
   1.184    }
   1.185  };
   1.186  
   1.187 -#ifndef _STLP_LIMITED_DEFAULT_TEMPLATES
   1.188 +#if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
   1.189  template <class _TpP,
   1.190            class _CharT = _STLP_DEFAULTCHAR, class _Traits = char_traits<_CharT> >
   1.191  #else
   1.192  template <class _TpP>
   1.193  #endif
   1.194  class ostream_iterator: public iterator<output_iterator_tag, void, void, void, void> {
   1.195 -# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
   1.196 +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
   1.197    typedef char _CharT;
   1.198    typedef char_traits<char> _Traits;
   1.199    typedef ostream_iterator<_TpP> _Self;
   1.200 -# else
   1.201 +#else
   1.202    typedef ostream_iterator<_TpP, _CharT, _Traits> _Self;
   1.203 -# endif
   1.204 +#endif
   1.205  public:
   1.206    typedef _CharT                         char_type;
   1.207    typedef _Traits                        traits_type;
   1.208 @@ -168,173 +175,76 @@
   1.209    typedef output_iterator_tag            iterator_category;
   1.210  
   1.211    ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {}
   1.212 -  ostream_iterator(ostream_type& __s, const _CharT* __c) 
   1.213 +  ostream_iterator(ostream_type& __s, const _CharT* __c)
   1.214      : _M_stream(&__s), _M_string(__c)  {}
   1.215 -  _Self& operator=(const _TpP& __val) { 
   1.216 +  _Self& operator=(const _TpP& __val) {
   1.217      *_M_stream << __val;
   1.218      if (_M_string) *_M_stream << _M_string;
   1.219      return *this;
   1.220    }
   1.221    _Self& operator*() { return *this; }
   1.222 -  _Self& operator++() { return *this; } 
   1.223 -  _Self& operator++(int) { return *this; } 
   1.224 +  _Self& operator++() { return *this; }
   1.225 +  _Self& operator++(int) { return *this; }
   1.226  private:
   1.227    ostream_type* _M_stream;
   1.228    const _CharT* _M_string;
   1.229  };
   1.230  
   1.231 -# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   1.232 -#  ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
   1.233 +#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
   1.234 +#  if defined (_STLP_LIMITED_DEFAULT_TEMPLATES)
   1.235  template <class _TpP>
   1.236 -inline output_iterator_tag _STLP_CALL 
   1.237 +inline output_iterator_tag _STLP_CALL
   1.238  iterator_category(const ostream_iterator<_TpP>&) { return output_iterator_tag(); }
   1.239 -# else
   1.240 +#  else
   1.241  template <class _TpP, class _CharT, class _Traits>
   1.242 -inline output_iterator_tag _STLP_CALL 
   1.243 +inline output_iterator_tag _STLP_CALL
   1.244  iterator_category(const ostream_iterator<_TpP, _CharT, _Traits>&) { return output_iterator_tag(); }
   1.245  #  endif
   1.246 -# endif
   1.247 -
   1.248 -_STLP_END_NAMESPACE
   1.249 -
   1.250 -# elif ! defined(_STLP_USE_NO_IOSTREAMS)
   1.251 -
   1.252 -_STLP_BEGIN_NAMESPACE
   1.253 -
   1.254 -#  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
   1.255 -#  define __ISI_TMPL_HEADER_ARGUMENTS class _Tp
   1.256 -#  define __ISI_TMPL_ARGUMENTS        _Tp
   1.257 -template <class _Tp>
   1.258 -class istream_iterator : public iterator<input_iterator_tag, _Tp, ptrdiff_t, 
   1.259 -                         const _Tp*, const _Tp& > {
   1.260 -#  else
   1.261 -#  define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
   1.262 -#  define __ISI_TMPL_ARGUMENTS        _Tp, _Dist
   1.263 -template <class _Tp, __DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
   1.264 -class istream_iterator : public iterator<input_iterator_tag, _Tp, _Dist, 
   1.265 -                         const _Tp*, const _Tp& > {
   1.266 -#  endif
   1.267 -
   1.268 -protected:
   1.269 -  istream* _M_stream;
   1.270 -  _Tp _M_value;
   1.271 -  bool _M_end_marker;
   1.272 -  void _M_read() {
   1.273 -    _M_end_marker = (*_M_stream) ? true : false;
   1.274 -    if (_M_end_marker) *_M_stream >> _M_value;
   1.275 -    _M_end_marker = (*_M_stream) ? true : false;
   1.276 -}
   1.277 -public:
   1.278 -  typedef input_iterator_tag  iterator_category;
   1.279 -  typedef _Tp                 value_type;
   1.280 -  typedef _Dist               difference_type;
   1.281 -  typedef const _Tp*          pointer;
   1.282 -  typedef const _Tp&          reference;
   1.283 -
   1.284 -  istream_iterator() : _M_stream(&cin), _M_end_marker(false) {}
   1.285 -  istream_iterator(istream& __s) : _M_stream(&__s) { _M_read(); }
   1.286 -  reference operator*() const { return _M_value; }
   1.287 -
   1.288 -  _STLP_DEFINE_ARROW_OPERATOR
   1.289 -
   1.290 -  istream_iterator< __ISI_TMPL_ARGUMENTS >& operator++() { 
   1.291 -    _M_read(); 
   1.292 -    return *this;
   1.293 -  }
   1.294 -  istream_iterator< __ISI_TMPL_ARGUMENTS > operator++(int)  {
   1.295 -    istream_iterator< __ISI_TMPL_ARGUMENTS > __tmp = *this;
   1.296 -    _M_read();
   1.297 -    return __tmp;
   1.298 -  }
   1.299 -  inline bool _M_equal(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) const {
   1.300 -    return (_M_stream == __y._M_stream &&
   1.301 -	    _M_end_marker == __y._M_end_marker) ||
   1.302 -      _M_end_marker == false && __y._M_end_marker == false;
   1.303 -  }
   1.304 -};
   1.305 -
   1.306 -template <class _Tp>
   1.307 -class ostream_iterator {
   1.308 -protected:
   1.309 -  ostream* _M_stream;
   1.310 -  const char* _M_string;
   1.311 -public:
   1.312 -  typedef output_iterator_tag iterator_category;
   1.313 -# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
   1.314 -  typedef void                value_type;
   1.315 -  typedef void                difference_type;
   1.316 -  typedef void                pointer;
   1.317 -  typedef void                reference;
   1.318 -# endif
   1.319 -  ostream_iterator(ostream& __s) : _M_stream(&__s), _M_string(0) {}
   1.320 -  ostream_iterator(ostream& __s, const char* __c) 
   1.321 -    : _M_stream(&__s), _M_string(__c)  {}
   1.322 -  ostream_iterator<_Tp>& operator=(const _Tp& __val) { 
   1.323 -    *_M_stream << __val;
   1.324 -    if (_M_string) *_M_stream << _M_string;
   1.325 -    return *this;
   1.326 -  }
   1.327 -  ostream_iterator<_Tp>& operator*() { return *this; }
   1.328 -  ostream_iterator<_Tp>& operator++() { return *this; } 
   1.329 -  ostream_iterator<_Tp>& operator++(int) { return *this; } 
   1.330 -};
   1.331 -
   1.332 -# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   1.333 -template <class _Tp> inline output_iterator_tag 
   1.334 -iterator_category(const ostream_iterator<_Tp>&) { return output_iterator_tag(); }
   1.335  #endif
   1.336  
   1.337  _STLP_END_NAMESPACE
   1.338  
   1.339 -#endif /* _STLP_USE_NEW_IOSTREAMS */
   1.340 -
   1.341  // form-independent definiotion of stream iterators
   1.342  _STLP_BEGIN_NAMESPACE
   1.343  
   1.344  template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.345 -inline bool _STLP_CALL 
   1.346 +inline bool _STLP_CALL
   1.347  operator==(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
   1.348 -           const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) {
   1.349 -  return __x._M_equal(__y);
   1.350 -}
   1.351 +           const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y)
   1.352 +{ return __x._M_equal(__y); }
   1.353  
   1.354 -#  ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   1.355 +#if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
   1.356 +template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.357 +inline bool _STLP_CALL
   1.358 +operator!=(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
   1.359 +           const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y)
   1.360 +{ return !__x._M_equal(__y); }
   1.361 +#endif
   1.362  
   1.363 +#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
   1.364  template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.365 -inline bool _STLP_CALL 
   1.366 -operator!=(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
   1.367 -           const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) {
   1.368 -  return !__x._M_equal(__y);
   1.369 -}
   1.370 -
   1.371 -#  endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
   1.372 -
   1.373 -# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   1.374 -template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.375 -inline input_iterator_tag _STLP_CALL 
   1.376 +inline input_iterator_tag _STLP_CALL
   1.377  iterator_category(const istream_iterator< __ISI_TMPL_ARGUMENTS >&)
   1.378  { return input_iterator_tag(); }
   1.379  template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.380 -inline _Tp* _STLP_CALL 
   1.381 +inline _Tp* _STLP_CALL
   1.382  value_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Tp*) 0; }
   1.383  
   1.384 -#  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
   1.385 +#  if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM)
   1.386  template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.387 -inline ptrdiff_t* _STLP_CALL 
   1.388 +inline ptrdiff_t* _STLP_CALL
   1.389  distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (ptrdiff_t*)0; }
   1.390  #  else
   1.391  template < __ISI_TMPL_HEADER_ARGUMENTS >
   1.392 -inline _Dist* _STLP_CALL 
   1.393 +inline _Dist* _STLP_CALL
   1.394  distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Dist*)0; }
   1.395  #  endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
   1.396 -
   1.397 -# endif 
   1.398 +#endif
   1.399  
   1.400  _STLP_END_NAMESPACE
   1.401  
   1.402 -#  undef __ISI_TMPL_HEADER_ARGUMENTS
   1.403 -#  undef __ISI_TMPL_ARGUMENTS
   1.404 -
   1.405 +#undef __ISI_TMPL_HEADER_ARGUMENTS
   1.406 +#undef __ISI_TMPL_ARGUMENTS
   1.407  
   1.408  #endif /* _STLP_INTERNAL_STREAM_ITERATOR_H */
   1.409