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