1
/* Copyright (C) 2004 Garrett A. Kajmowicz
3
This file is part of the uClibc++ Library.
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <basic_definitions>
23
#include <char_traits>
24
#include <iterator_base>
28
#ifndef __STD_HEADER_ITERATOR
29
#define __STD_HEADER_ITERATOR 1
31
#pragma GCC visibility push(default)
35
// subclause _lib.stream.iterators_, stream iterators:
36
template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> class istream_iterator;
37
template <class T, class charT, class traits, class Distance> bool
38
operator==(const istream_iterator<T,charT,traits,Distance>& x, const istream_iterator<T,charT,traits,Distance>& y);
39
template <class T, class charT, class traits, class Distance> bool
40
operator!=(const istream_iterator<T,charT,traits,Distance>& x, const istream_iterator<T,charT,traits,Distance>& y);
41
template <class T, class charT = char, class traits = char_traits<charT> > class ostream_iterator;
42
template<class charT, class traits = char_traits<charT> > class istreambuf_iterator;
43
template <class charT, class traits> bool
44
operator==(const istreambuf_iterator<charT,traits>& a, const istreambuf_iterator<charT,traits>& b);
45
template <class charT, class traits> bool
46
operator!=(const istreambuf_iterator<charT,traits>& a, const istreambuf_iterator<charT,traits>& b);
47
template <class charT, class traits = char_traits<charT> > class ostreambuf_iterator;
50
template < class T, class charT, class traits, class Distance > class _UCXXEXPORT istream_iterator
51
: public iterator<input_iterator_tag,T,Distance,const T*, const T&>
54
typedef charT char_type;
55
typedef traits traits_type;
56
typedef basic_istream<charT,traits> istream_type;
57
istream_iterator() : in_stream(0), value(0) {}
58
istream_iterator(istream_type& s) : in_stream(&s), value() {
61
istream_iterator(const istream_iterator<T,charT,traits,Distance>& x)
62
: in_stream(x.in_stream), value(x.value)
64
~istream_iterator() { }
65
const T& operator*() const{
68
const T* operator->() const{
71
istream_iterator<T,charT,traits,Distance>& operator++() {
75
istream_iterator<T,charT,traits,Distance> operator++(int){
76
istream_iterator<T,charT,traits,Distance> tmp = *this;
80
bool m_equal(const istream_iterator<T,charT,traits,Distance>& x) const{
81
return (in_stream == x.in_stream);
84
basic_istream<charT,traits>* in_stream;
88
template <class T, class charT, class traits, class Distance> _UCXXEXPORT
89
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
90
const istream_iterator<T,charT,traits,Distance>& y)
95
template <class T, class charT, class traits, class Distance> _UCXXEXPORT
96
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
97
const istream_iterator<T,charT,traits,Distance>& y)
102
template <class T, class charT, class traits> class _UCXXEXPORT ostream_iterator
103
: public iterator<output_iterator_tag,void,void,void,void>
106
typedef charT char_type;
107
typedef traits traits_type;
108
typedef basic_ostream<charT,traits> ostream_type;
110
ostream_iterator(ostream_type& s) : out_stream(&s), delim(0) { }
111
ostream_iterator(ostream_type& s, const charT* delimiter) : out_stream(&s), delim(delimiter) { }
112
ostream_iterator(const ostream_iterator<T,charT,traits>& x) : out_stream(x.out_stream), delim(x.delim) { }
113
~ostream_iterator() { }
114
ostream_iterator<T,charT,traits>& operator=(const T& value){
115
*out_stream << value;
117
*out_stream << delim;
121
ostream_iterator<T,charT,traits>& operator*(){ return *this; }
122
ostream_iterator<T,charT,traits>& operator++() { return *this; }
123
ostream_iterator<T,charT,traits> operator++(int) { return *this; }
125
basic_ostream<charT,traits>* out_stream;
129
template<class charT, class traits > class _UCXXEXPORT istreambuf_iterator :
130
public iterator<input_iterator_tag, charT, typename traits::off_type, charT*, charT&>
133
typedef charT char_type;
134
typedef traits traits_type;
135
typedef typename traits::int_type int_type;
136
typedef basic_streambuf<charT,traits> streambuf_type;
137
typedef basic_istream<charT,traits> istream_type;
139
class _UCXXEXPORT proxy{
141
basic_streambuf<charT, traits> * buf;
143
proxy(charT v, basic_streambuf<charT, traits> * b) : val(v), buf(b) { }
145
charT operator*() { return val; }
148
istreambuf_iterator() throw() : sbuf(0) { }
149
istreambuf_iterator(istream_type& s) throw() : sbuf(s.rdbuf()) { }
150
istreambuf_iterator(streambuf_type* s) throw() : sbuf(s) { }
151
istreambuf_iterator(const proxy& p) throw() : sbuf(&p.buf) { }
153
charT operator*() const{
154
return sbuf->sgetc();
156
istreambuf_iterator<charT,traits>& operator++(){
160
proxy operator++(int){
161
istreambuf_iterator<charT,traits> tmp = *this;
166
bool equal(const istreambuf_iterator& b) const{
167
return sbuf == b.sbuf || is_eof() && b.is_eof();
170
streambuf_type* sbuf;
171
inline bool is_eof() const{
172
return sbuf == 0 || sbuf->sgetc() == traits_type::eof();
176
template <class charT, class traits> _UCXXEXPORT bool
177
operator==(const istreambuf_iterator<charT,traits>& a,
178
const istreambuf_iterator<charT,traits>& b)
183
template <class charT, class traits> bool _UCXXEXPORT
184
operator!=(const istreambuf_iterator<charT,traits>& a,
185
const istreambuf_iterator<charT,traits>& b)
190
template <class charT, class traits> class _UCXXEXPORT ostreambuf_iterator
191
: iterator<output_iterator_tag,void,void,void,void>
194
typedef charT char_type;
195
typedef traits traits_type;
196
typedef basic_streambuf<charT,traits> streambuf_type;
197
typedef basic_ostream<charT,traits> ostream_type;
199
ostreambuf_iterator(ostream_type& s) throw() : sbuf(s.rdbuf()), f(false) { }
200
ostreambuf_iterator(streambuf_type* s) throw() : sbuf(s), f(false) { }
201
ostreambuf_iterator& operator=(charT c){
202
if(failed() == false){
203
if(sbuf->sputc(c) == traits::eof()){
209
ostreambuf_iterator& operator*(){
212
ostreambuf_iterator& operator++() { return *this; }
213
ostreambuf_iterator operator++(int) { return *this; }
214
bool failed() const throw(){
219
streambuf_type* sbuf;
225
#pragma GCC visibility pop