2001-02-06 Phil Edwards <pme@sources.redhat.com>
[official-gcc.git] / libstdc++-v3 / include / bits / std_istream.h
blob4a0f6602d02d9c837aa4f368d1775977095b0172
1 // Input streams -*- C++ -*-
3 // Copyright (C) 1997-1999 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 27.6.1 Input streams
34 #ifndef _CPP_ISTREAM
35 #define _CPP_ISTREAM 1
37 #include <bits/std_ios.h>
38 #include <bits/std_limits.h> // For numeric_limits
40 namespace std {
42 // 27.6.1.1 Template class basic_istream
43 template<typename _CharT, typename _Traits>
44 class basic_istream : virtual public basic_ios<_CharT, _Traits>
46 public:
48 // Types (inherited from basic_ios (27.4.4)):
49 typedef _CharT char_type;
50 typedef typename _Traits::int_type int_type;
51 typedef typename _Traits::pos_type pos_type;
52 typedef typename _Traits::off_type off_type;
53 typedef _Traits traits_type;
55 // Non-standard Types:
56 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
57 typedef basic_ios<_CharT, _Traits> __ios_type;
58 typedef basic_istream<_CharT, _Traits> __istream_type;
59 typedef istreambuf_iterator<_CharT> __istreambuf_iter;
60 typedef num_get<_CharT, __istreambuf_iter> __numget_type;
61 typedef ctype<_CharT> __ctype_type;
63 protected:
64 // Data Members:
65 streamsize _M_gcount;
67 public:
68 // 27.6.1.1.1 Constructor/destructor:
69 explicit
70 basic_istream(__streambuf_type* __sb)
72 this->init(__sb);
73 _M_gcount = streamsize(0);
76 virtual
77 ~basic_istream()
79 _M_gcount = streamsize(0);
80 _M_fnumget = NULL;
83 // 27.6.1.1.2 Prefix/suffix:
84 class sentry;
85 friend class sentry;
87 // 27.6.1.2 Formatted input:
88 // 27.6.1.2.3 basic_istream::operator>>
89 __istream_type&
90 operator>>(__istream_type& (*__pf)(__istream_type&));
92 __istream_type&
93 operator>>(__ios_type& (*__pf)(__ios_type&));
95 __istream_type&
96 operator>>(ios_base& (*__pf)(ios_base&));
98 // 27.6.1.2.2 Arithmetic Extractors
99 __istream_type&
100 operator>>(bool& __n);
102 __istream_type&
103 operator>>(short& __n);
105 __istream_type&
106 operator>>(unsigned short& __n);
108 __istream_type&
109 operator>>(int& __n);
111 __istream_type&
112 operator>>(unsigned int& __n);
114 __istream_type&
115 operator>>(long& __n);
117 __istream_type&
118 operator>>(unsigned long& __n);
120 #ifdef _GLIBCPP_USE_LONG_LONG
121 __istream_type&
122 operator>>(long long& __n);
124 __istream_type&
125 operator>>(unsigned long long& __n);
126 #endif
128 __istream_type&
129 operator>>(float& __f);
131 __istream_type&
132 operator>>(double& __f);
134 __istream_type&
135 operator>>(long double& __f);
137 __istream_type&
138 operator>>(void*& __p);
140 __istream_type&
141 operator>>(__streambuf_type* __sb);
143 // 27.6.1.3 Unformatted input:
144 inline streamsize
145 gcount(void) const
146 { return _M_gcount; }
148 int_type
149 get(void);
151 __istream_type&
152 get(char_type& __c);
154 __istream_type&
155 get(char_type* __s, streamsize __n, char_type __delim);
157 inline __istream_type&
158 get(char_type* __s, streamsize __n)
159 { return get(__s, __n, this->widen('\n')); }
161 __istream_type&
162 get(__streambuf_type& __sb, char_type __delim);
164 inline __istream_type&
165 get(__streambuf_type& __sb)
166 { return get(__sb, this->widen('\n')); }
168 __istream_type&
169 getline(char_type* __s, streamsize __n, char_type __delim);
171 inline __istream_type&
172 getline(char_type* __s, streamsize __n)
173 { return getline(__s, __n, this->widen('\n')); }
175 __istream_type&
176 ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
178 int_type
179 peek(void);
181 __istream_type&
182 read(char_type* __s, streamsize __n);
184 streamsize
185 readsome(char_type* __s, streamsize __n);
187 __istream_type&
188 putback(char_type __c);
190 __istream_type&
191 unget(void);
193 int
194 sync(void);
196 pos_type
197 tellg(void);
199 __istream_type&
200 seekg(pos_type);
202 __istream_type&
203 seekg(off_type, ios_base::seekdir);
205 private:
206 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
207 // Not defined.
208 __istream_type&
209 operator=(const __istream_type&);
211 basic_istream(const __istream_type&);
212 #endif
215 template<typename _CharT, typename _Traits>
216 class basic_istream<_CharT, _Traits>::sentry
218 public:
220 typedef _Traits traits_type;
221 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
222 typedef basic_istream<_CharT, _Traits> __istream_type;
223 typedef __istream_type::__ctype_type __ctype_type;
224 typedef typename _Traits::int_type __int_type;
226 explicit
227 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
229 operator bool() { return _M_ok; }
231 private:
232 bool _M_ok;
235 // 27.6.1.2.3 Character extraction templates
236 template<typename _CharT, typename _Traits>
237 basic_istream<_CharT, _Traits>&
238 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
240 template<class _Traits>
241 basic_istream<char, _Traits>&
242 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
243 { return (__in >> reinterpret_cast<char&>(__c)); }
245 template<class _Traits>
246 basic_istream<char, _Traits>&
247 operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
248 { return (__in >> reinterpret_cast<char&>(__c)); }
250 template<typename _CharT, typename _Traits>
251 basic_istream<_CharT, _Traits>&
252 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
254 template<class _Traits>
255 basic_istream<char,_Traits>&
256 operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
257 { return (__in >> reinterpret_cast<char*>(__s)); }
259 template<class _Traits>
260 basic_istream<char,_Traits>&
261 operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
262 { return (__in >> reinterpret_cast<char*>(__s)); }
264 // 27.6.1.5 Template class basic_iostream
265 template<typename _CharT, typename _Traits>
266 class basic_iostream
267 : public basic_istream<_CharT, _Traits>,
268 public basic_ostream<_CharT, _Traits>
270 public:
272 // Non-standard Types:
273 typedef basic_istream<_CharT, _Traits> __istream_type;
274 typedef basic_ostream<_CharT, _Traits> __ostream_type;
276 explicit
277 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
278 : __istream_type(__sb), __ostream_type(__sb)
281 virtual
282 ~basic_iostream() { }
285 // 27.6.1.4 Standard basic_istream manipulators
286 template<typename _CharT, typename _Traits>
287 basic_istream<_CharT, _Traits>&
288 ws(basic_istream<_CharT, _Traits>& __is);
290 } // namespace std
292 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
293 # define export
294 #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
295 # include <bits/istream.tcc>
296 #endif
297 #endif
299 #endif /* _CPP_ISTREAM */