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