diff -r e1b950c65cb4 -r 837f303aceeb epoc32/include/stdapis/stlportv5/stl/_stream_iterator.h --- a/epoc32/include/stdapis/stlportv5/stl/_stream_iterator.h Wed Mar 31 12:27:01 2010 +0100 +++ b/epoc32/include/stdapis/stlportv5/stl/_stream_iterator.h Wed Mar 31 12:33:34 2010 +0100 @@ -9,13 +9,13 @@ * Copyright (c) 1997 * Moscow Center for SPARC Technology * - * Copyright (c) 1999 + * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * - * Permission to use or copy this software for any purpose is hereby granted + * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was @@ -27,78 +27,71 @@ * You should not attempt to use it directly. */ -#if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && ! defined (_STLP_USE_NO_IOSTREAMS) +#if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && !defined (_STLP_USE_NO_IOSTREAMS) #define _STLP_INTERNAL_STREAM_ITERATOR_H #ifndef _STLP_INTERNAL_ITERATOR_BASE_H -# include +# include #endif // streambuf_iterators predeclarations must appear first #ifndef _STLP_IOSFWD -# include +# include #endif #ifndef _STLP_INTERNAL_ALGOBASE_H -#include +# include #endif -#if defined (_STLP_OWN_IOSTREAMS) - #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H -# include +# include #endif #ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H -# include +# include #endif -#ifndef _STLP_INTERNAL_ISTREAM_H -# include +#ifndef _STLP_INTERNAL_ISTREAM +# include #endif -#endif /* _STLP_OWN_IOSTREAMS */ // istream_iterator and ostream_iterator look very different if we're // using new, templatized iostreams than if we're using the old cfront // version. -# if defined (_STLP_USE_NEW_IOSTREAMS) - _STLP_BEGIN_NAMESPACE -# ifndef _STLP_LIMITED_DEFAULT_TEMPLATES -template , - class _Dist = ptrdiff_t> -# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _CharT, class _Traits, class _Dist -# define __ISI_TMPL_ARGUMENTS _Tp, _CharT, _Traits, _Dist + class _Dist = ptrdiff_t> class istream_iterator : public iterator { -# else - -# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM) + const _Tp*, const _Tp& > { +#else +# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM) # define __ISI_TMPL_HEADER_ARGUMENTS class _Tp # define __ISI_TMPL_ARGUMENTS _Tp template -class istream_iterator : public iterator { -# else +class istream_iterator : public iterator { +# else # define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist # define __ISI_TMPL_ARGUMENTS _Tp, _Dist -template -class istream_iterator : public iterator +class istream_iterator : public iterator { -# endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */ +# endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */ +#endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */ -# endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */ - -# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES) typedef char _CharT; typedef char_traits _Traits; -# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM) +# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM) typedef ptrdiff_t _Dist; # endif -# endif +#endif typedef istream_iterator< __ISI_TMPL_ARGUMENTS > _Self; public: @@ -112,15 +105,20 @@ typedef const _Tp* pointer; typedef const _Tp& reference; - istream_iterator() : _M_stream(0), _M_ok(false) {} - istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); } + istream_iterator() : _M_stream(0), _M_ok(false), _M_read_done(true) {} + istream_iterator(istream_type& __s) : _M_stream(&__s), _M_ok(false), _M_read_done(false) {} - reference operator*() const { return _M_value; } + reference operator*() const { + if (!_M_read_done) { + _M_read(); + } + return _M_value; + } _STLP_DEFINE_ARROW_OPERATOR - _Self& operator++() { - _M_read(); + _Self& operator++() { + _M_read(); return *this; } _Self operator++(int) { @@ -129,37 +127,46 @@ return __tmp; } - bool _M_equal(const _Self& __x) const - { return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); } + bool _M_equal(const _Self& __x) const { + if (!_M_read_done) { + _M_read(); + } + if (!__x._M_read_done) { + __x._M_read(); + } + return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); + } private: istream_type* _M_stream; - _Tp _M_value; - bool _M_ok; + mutable _Tp _M_value; + mutable bool _M_ok; + mutable bool _M_read_done; - void _M_read() { - _M_ok = (_M_stream && *_M_stream) ? true : false; + void _M_read() const { + _M_ok = ((_M_stream != 0) && !_M_stream->fail()); if (_M_ok) { *_M_stream >> _M_value; - _M_ok = *_M_stream ? true : false; + _M_ok = !_M_stream->fail(); } + _M_read_done = true; } }; -#ifndef _STLP_LIMITED_DEFAULT_TEMPLATES +#if !defined (_STLP_LIMITED_DEFAULT_TEMPLATES) template > #else template #endif class ostream_iterator: public iterator { -# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES +#if defined (_STLP_LIMITED_DEFAULT_TEMPLATES) typedef char _CharT; typedef char_traits _Traits; typedef ostream_iterator<_TpP> _Self; -# else +#else typedef ostream_iterator<_TpP, _CharT, _Traits> _Self; -# endif +#endif public: typedef _CharT char_type; typedef _Traits traits_type; @@ -168,173 +175,76 @@ typedef output_iterator_tag iterator_category; ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {} - ostream_iterator(ostream_type& __s, const _CharT* __c) + ostream_iterator(ostream_type& __s, const _CharT* __c) : _M_stream(&__s), _M_string(__c) {} - _Self& operator=(const _TpP& __val) { + _Self& operator=(const _TpP& __val) { *_M_stream << __val; if (_M_string) *_M_stream << _M_string; return *this; } _Self& operator*() { return *this; } - _Self& operator++() { return *this; } - _Self& operator++(int) { return *this; } + _Self& operator++() { return *this; } + _Self& operator++(int) { return *this; } private: ostream_type* _M_stream; const _CharT* _M_string; }; -# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES -# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES +#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES) +# if defined (_STLP_LIMITED_DEFAULT_TEMPLATES) template -inline output_iterator_tag _STLP_CALL +inline output_iterator_tag _STLP_CALL iterator_category(const ostream_iterator<_TpP>&) { return output_iterator_tag(); } -# else +# else template -inline output_iterator_tag _STLP_CALL +inline output_iterator_tag _STLP_CALL iterator_category(const ostream_iterator<_TpP, _CharT, _Traits>&) { return output_iterator_tag(); } # endif -# endif - -_STLP_END_NAMESPACE - -# elif ! defined(_STLP_USE_NO_IOSTREAMS) - -_STLP_BEGIN_NAMESPACE - -# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM) -# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp -# define __ISI_TMPL_ARGUMENTS _Tp -template -class istream_iterator : public iterator { -# else -# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist -# define __ISI_TMPL_ARGUMENTS _Tp, _Dist -template -class istream_iterator : public iterator { -# endif - -protected: - istream* _M_stream; - _Tp _M_value; - bool _M_end_marker; - void _M_read() { - _M_end_marker = (*_M_stream) ? true : false; - if (_M_end_marker) *_M_stream >> _M_value; - _M_end_marker = (*_M_stream) ? true : false; -} -public: - typedef input_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Dist difference_type; - typedef const _Tp* pointer; - typedef const _Tp& reference; - - istream_iterator() : _M_stream(&cin), _M_end_marker(false) {} - istream_iterator(istream& __s) : _M_stream(&__s) { _M_read(); } - reference operator*() const { return _M_value; } - - _STLP_DEFINE_ARROW_OPERATOR - - istream_iterator< __ISI_TMPL_ARGUMENTS >& operator++() { - _M_read(); - return *this; - } - istream_iterator< __ISI_TMPL_ARGUMENTS > operator++(int) { - istream_iterator< __ISI_TMPL_ARGUMENTS > __tmp = *this; - _M_read(); - return __tmp; - } - inline bool _M_equal(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) const { - return (_M_stream == __y._M_stream && - _M_end_marker == __y._M_end_marker) || - _M_end_marker == false && __y._M_end_marker == false; - } -}; - -template -class ostream_iterator { -protected: - ostream* _M_stream; - const char* _M_string; -public: - typedef output_iterator_tag iterator_category; -# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; -# endif - ostream_iterator(ostream& __s) : _M_stream(&__s), _M_string(0) {} - ostream_iterator(ostream& __s, const char* __c) - : _M_stream(&__s), _M_string(__c) {} - ostream_iterator<_Tp>& operator=(const _Tp& __val) { - *_M_stream << __val; - if (_M_string) *_M_stream << _M_string; - return *this; - } - ostream_iterator<_Tp>& operator*() { return *this; } - ostream_iterator<_Tp>& operator++() { return *this; } - ostream_iterator<_Tp>& operator++(int) { return *this; } -}; - -# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES -template inline output_iterator_tag -iterator_category(const ostream_iterator<_Tp>&) { return output_iterator_tag(); } #endif _STLP_END_NAMESPACE -#endif /* _STLP_USE_NEW_IOSTREAMS */ - // form-independent definiotion of stream iterators _STLP_BEGIN_NAMESPACE template < __ISI_TMPL_HEADER_ARGUMENTS > -inline bool _STLP_CALL +inline bool _STLP_CALL operator==(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x, - const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) { - return __x._M_equal(__y); -} + const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) +{ return __x._M_equal(__y); } -# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE +#if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE) +template < __ISI_TMPL_HEADER_ARGUMENTS > +inline bool _STLP_CALL +operator!=(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x, + const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) +{ return !__x._M_equal(__y); } +#endif +#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES) template < __ISI_TMPL_HEADER_ARGUMENTS > -inline bool _STLP_CALL -operator!=(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x, - const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) { - return !__x._M_equal(__y); -} - -# endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */ - -# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES -template < __ISI_TMPL_HEADER_ARGUMENTS > -inline input_iterator_tag _STLP_CALL +inline input_iterator_tag _STLP_CALL iterator_category(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return input_iterator_tag(); } template < __ISI_TMPL_HEADER_ARGUMENTS > -inline _Tp* _STLP_CALL +inline _Tp* _STLP_CALL value_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Tp*) 0; } -# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM) +# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && !defined (_STLP_DEFAULT_TYPE_PARAM) template < __ISI_TMPL_HEADER_ARGUMENTS > -inline ptrdiff_t* _STLP_CALL +inline ptrdiff_t* _STLP_CALL distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (ptrdiff_t*)0; } # else template < __ISI_TMPL_HEADER_ARGUMENTS > -inline _Dist* _STLP_CALL +inline _Dist* _STLP_CALL distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Dist*)0; } # endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */ - -# endif +#endif _STLP_END_NAMESPACE -# undef __ISI_TMPL_HEADER_ARGUMENTS -# undef __ISI_TMPL_ARGUMENTS - +#undef __ISI_TMPL_HEADER_ARGUMENTS +#undef __ISI_TMPL_ARGUMENTS #endif /* _STLP_INTERNAL_STREAM_ITERATOR_H */