]>
gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/include/bits/ios_base.h
1 // Iostreams base classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 27.8 File-based streams
36 * This is an internal header file, included by other library headers.
37 * You should not attempt to use it directly.
40 #ifndef _CPP_BITS_IOSBASE_H
41 #define _CPP_BITS_IOSBASE_H 1
43 #pragma GCC system_header
45 #include <bits/atomicity.h>
49 // The following definitions of bitmask types are enums, not ints,
50 // as permitted (but not required) in the standard, in order to provide
51 // better type safety in iostream calls. A side effect is that
52 // expressions involving them are no longer compile-time constants.
53 enum _Ios_Fmtflags
{ _M_ios_fmtflags_end
= 1L << 16 };
56 operator&(_Ios_Fmtflags __a
, _Ios_Fmtflags __b
)
57 { return _Ios_Fmtflags(static_cast<int>(__a
) & static_cast<int>(__b
)); }
60 operator|(_Ios_Fmtflags __a
, _Ios_Fmtflags __b
)
61 { return _Ios_Fmtflags(static_cast<int>(__a
) | static_cast<int>(__b
)); }
64 operator^(_Ios_Fmtflags __a
, _Ios_Fmtflags __b
)
65 { return _Ios_Fmtflags(static_cast<int>(__a
) ^ static_cast<int>(__b
)); }
68 operator|=(_Ios_Fmtflags
& __a
, _Ios_Fmtflags __b
)
69 { return __a
= __a
| __b
; }
72 operator&=(_Ios_Fmtflags
& __a
, _Ios_Fmtflags __b
)
73 { return __a
= __a
& __b
; }
76 operator^=(_Ios_Fmtflags
& __a
, _Ios_Fmtflags __b
)
77 { return __a
= __a
^ __b
; }
80 operator~(_Ios_Fmtflags __a
)
81 { return _Ios_Fmtflags(~static_cast<int>(__a
)); }
84 enum _Ios_Openmode
{ _M_ios_openmode_end
= 1L << 16 };
87 operator&(_Ios_Openmode __a
, _Ios_Openmode __b
)
88 { return _Ios_Openmode(static_cast<int>(__a
) & static_cast<int>(__b
)); }
91 operator|(_Ios_Openmode __a
, _Ios_Openmode __b
)
92 { return _Ios_Openmode(static_cast<int>(__a
) | static_cast<int>(__b
)); }
95 operator^(_Ios_Openmode __a
, _Ios_Openmode __b
)
96 { return _Ios_Openmode(static_cast<int>(__a
) ^ static_cast<int>(__b
)); }
99 operator|=(_Ios_Openmode
& __a
, _Ios_Openmode __b
)
100 { return __a
= __a
| __b
; }
103 operator&=(_Ios_Openmode
& __a
, _Ios_Openmode __b
)
104 { return __a
= __a
& __b
; }
107 operator^=(_Ios_Openmode
& __a
, _Ios_Openmode __b
)
108 { return __a
= __a
^ __b
; }
111 operator~(_Ios_Openmode __a
)
112 { return _Ios_Openmode(~static_cast<int>(__a
)); }
115 enum _Ios_Iostate
{ _M_ios_iostate_end
= 1L << 16 };
118 operator&(_Ios_Iostate __a
, _Ios_Iostate __b
)
119 { return _Ios_Iostate(static_cast<int>(__a
) & static_cast<int>(__b
)); }
122 operator|(_Ios_Iostate __a
, _Ios_Iostate __b
)
123 { return _Ios_Iostate(static_cast<int>(__a
) | static_cast<int>(__b
)); }
126 operator^(_Ios_Iostate __a
, _Ios_Iostate __b
)
127 { return _Ios_Iostate(static_cast<int>(__a
) ^ static_cast<int>(__b
)); }
130 operator|=(_Ios_Iostate
& __a
, _Ios_Iostate __b
)
131 { return __a
= __a
| __b
; }
134 operator&=(_Ios_Iostate
& __a
, _Ios_Iostate __b
)
135 { return __a
= __a
& __b
; }
138 operator^=(_Ios_Iostate
& __a
, _Ios_Iostate __b
)
139 { return __a
= __a
^ __b
; }
142 operator~(_Ios_Iostate __a
)
143 { return _Ios_Iostate(~static_cast<int>(__a
)); }
145 enum _Ios_Seekdir
{ _M_ios_seekdir_end
= 1L << 16 };
147 // 27.4.2 Class ios_base
152 // 27.4.2.1.1 Class ios_base::failure
153 class failure
: public exception
156 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
157 //48. Use of non-existent exception constructor
159 failure(const string
& __str
) throw();
165 what() const throw();
168 enum { _M_bufsize
= 256 };
169 char _M_name
[_M_bufsize
];
173 // 27.4.2.1.2 Type ios_base::fmtflags
174 typedef _Ios_Fmtflags fmtflags
;
175 // 27.4.2.1.2 Type fmtflags
176 static const fmtflags boolalpha
= fmtflags(__ios_flags::_S_boolalpha
);
177 static const fmtflags dec
= fmtflags(__ios_flags::_S_dec
);
178 static const fmtflags fixed
= fmtflags(__ios_flags::_S_fixed
);
179 static const fmtflags hex
= fmtflags(__ios_flags::_S_hex
);
180 static const fmtflags internal
= fmtflags(__ios_flags::_S_internal
);
181 static const fmtflags left
= fmtflags(__ios_flags::_S_left
);
182 static const fmtflags oct
= fmtflags(__ios_flags::_S_oct
);
183 static const fmtflags right
= fmtflags(__ios_flags::_S_right
);
184 static const fmtflags scientific
= fmtflags(__ios_flags::_S_scientific
);
185 static const fmtflags showbase
= fmtflags(__ios_flags::_S_showbase
);
186 static const fmtflags showpoint
= fmtflags(__ios_flags::_S_showpoint
);
187 static const fmtflags showpos
= fmtflags(__ios_flags::_S_showpos
);
188 static const fmtflags skipws
= fmtflags(__ios_flags::_S_skipws
);
189 static const fmtflags unitbuf
= fmtflags(__ios_flags::_S_unitbuf
);
190 static const fmtflags uppercase
= fmtflags(__ios_flags::_S_uppercase
);
191 static const fmtflags adjustfield
= fmtflags(__ios_flags::_S_adjustfield
);
192 static const fmtflags basefield
= fmtflags(__ios_flags::_S_basefield
);
193 static const fmtflags floatfield
= fmtflags(__ios_flags::_S_floatfield
);
195 // 27.4.2.1.3 Type ios_base::iostate
196 typedef _Ios_Iostate iostate
;
197 static const iostate badbit
= iostate(__ios_flags::_S_badbit
);
198 static const iostate eofbit
= iostate(__ios_flags::_S_eofbit
);
199 static const iostate failbit
= iostate(__ios_flags::_S_failbit
);
200 static const iostate goodbit
= iostate(0);
202 // 27.4.2.1.4 Type openmode
203 typedef _Ios_Openmode openmode
;
204 static const openmode app
= openmode(__ios_flags::_S_app
);
205 static const openmode ate
= openmode(__ios_flags::_S_ate
);
206 static const openmode binary
= openmode(__ios_flags::_S_bin
);
207 static const openmode in
= openmode(__ios_flags::_S_in
);
208 static const openmode out
= openmode(__ios_flags::_S_out
);
209 static const openmode trunc
= openmode(__ios_flags::_S_trunc
);
211 // 27.4.2.1.5 Type seekdir
212 typedef _Ios_Seekdir seekdir
;
213 static const seekdir beg
= seekdir(0);
214 static const seekdir cur
= seekdir(SEEK_CUR
);
215 static const seekdir end
= seekdir(SEEK_END
);
217 #ifdef _GLIBCPP_DEPRECATED
218 typedef int io_state
;
219 typedef int open_mode
;
220 typedef int seek_dir
;
231 typedef void (*event_callback
) (event
, ios_base
&, int);
234 register_callback(event_callback __fn
, int __index
);
238 streamsize _M_precision
;
242 // 27.4.2.6 Members for callbacks
243 // 27.4.2.6 ios_base callbacks
244 struct _Callback_list
247 _Callback_list
* _M_next
;
248 ios_base::event_callback _M_fn
;
250 _Atomic_word _M_refcount
; // 0 means one reference.
252 _Callback_list(ios_base::event_callback __fn
, int __index
,
253 _Callback_list
* __cb
)
254 : _M_next(__cb
), _M_fn(__fn
), _M_index(__index
), _M_refcount(0) { }
257 _M_add_reference() { __atomic_add(&_M_refcount
, 1); }
260 _M_remove_reference() { return __exchange_and_add(&_M_refcount
, -1); }
264 _Callback_list
* _M_callbacks
;
267 _M_call_callbacks(event __ev
) throw();
270 _M_dispose_callbacks(void);
272 // 27.4.2.5 Members for iword/pword storage
279 static const int _S_local_words
= 8;
280 _Words _M_word_array
[_S_local_words
]; // Guaranteed storage
281 _Words _M_dummy
; // Only for failed iword/pword calls.
286 _M_grow_words(int __index
);
288 // Members for locale and locale caching.
289 locale _M_ios_locale
;
296 // 27.4.2.1.6 Class ios_base::Init
297 // Used to initialize standard streams. In theory, g++ could use
298 // -finit-priority to order this stuff correctly without going
299 // through these machinations.
302 friend class ios_base
;
308 _S_ios_create(bool __sync
);
314 static int _S_ios_base_init
;
315 static bool _S_synced_with_stdio
;
320 flags() const { return _M_flags
; }
323 flags(fmtflags __fmtfl
)
325 fmtflags __old
= _M_flags
;
331 setf(fmtflags __fmtfl
)
333 fmtflags __old
= _M_flags
;
339 setf(fmtflags __fmtfl
, fmtflags __mask
)
341 fmtflags __old
= _M_flags
;
343 _M_flags
|= (__fmtfl
& __mask
);
348 unsetf(fmtflags __mask
) { _M_flags
&= ~__mask
; }
351 precision() const { return _M_precision
; }
354 precision(streamsize __prec
)
356 streamsize __old
= _M_precision
;
357 _M_precision
= __prec
;
362 width() const { return _M_width
; }
365 width(streamsize __wide
)
367 streamsize __old
= _M_width
;
373 sync_with_stdio(bool __sync
= true);
377 imbue(const locale
& __loc
);
380 getloc() const { return _M_ios_locale
; }
389 _Words
& __word
= (__ix
< _M_word_limit
)
390 ? _M_words
[__ix
] : _M_grow_words(__ix
);
391 return __word
._M_iword
;
397 _Words
& __word
= (__ix
< _M_word_limit
)
398 ? _M_words
[__ix
] : _M_grow_words(__ix
);
399 return __word
._M_pword
;
408 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
409 //50. Copy constructor and assignment operator of ios_base
411 ios_base(const ios_base
&);
414 operator=(const ios_base
&);
418 // 27.4.5.1 fmtflags manipulators:
420 boolalpha(ios_base
& __base
)
422 __base
.setf(ios_base::boolalpha
);
427 noboolalpha(ios_base
& __base
)
429 __base
.unsetf(ios_base::boolalpha
);
434 showbase(ios_base
& __base
)
436 __base
.setf(ios_base::showbase
);
441 noshowbase(ios_base
& __base
)
443 __base
.unsetf(ios_base::showbase
);
448 showpoint(ios_base
& __base
)
450 __base
.setf(ios_base::showpoint
);
455 noshowpoint(ios_base
& __base
)
457 __base
.unsetf(ios_base::showpoint
);
462 showpos(ios_base
& __base
)
464 __base
.setf(ios_base::showpos
);
469 noshowpos(ios_base
& __base
)
471 __base
.unsetf(ios_base::showpos
);
476 skipws(ios_base
& __base
)
478 __base
.setf(ios_base::skipws
);
483 noskipws(ios_base
& __base
)
485 __base
.unsetf(ios_base::skipws
);
490 uppercase(ios_base
& __base
)
492 __base
.setf(ios_base::uppercase
);
497 nouppercase(ios_base
& __base
)
499 __base
.unsetf(ios_base::uppercase
);
504 unitbuf(ios_base
& __base
)
506 __base
.setf(ios_base::unitbuf
);
511 nounitbuf(ios_base
& __base
)
513 __base
.unsetf(ios_base::unitbuf
);
517 // 27.4.5.2 adjustfield anipulators:
519 internal(ios_base
& __base
)
521 __base
.setf(ios_base::internal
, ios_base::adjustfield
);
526 left(ios_base
& __base
)
528 __base
.setf(ios_base::left
, ios_base::adjustfield
);
533 right(ios_base
& __base
)
535 __base
.setf(ios_base::right
, ios_base::adjustfield
);
539 // 27.4.5.3 basefield anipulators:
541 dec(ios_base
& __base
)
543 __base
.setf(ios_base::dec
, ios_base::basefield
);
548 hex(ios_base
& __base
)
550 __base
.setf(ios_base::hex
, ios_base::basefield
);
555 oct(ios_base
& __base
)
557 __base
.setf(ios_base::oct
, ios_base::basefield
);
561 // 27.4.5.4 floatfield anipulators:
563 fixed(ios_base
& __base
)
565 __base
.setf(ios_base::fixed
, ios_base::floatfield
);
570 scientific(ios_base
& __base
)
572 __base
.setf(ios_base::scientific
, ios_base::floatfield
);
578 #endif /* _CPP_BITS_IOSBASE_H */
This page took 0.070455 seconds and 6 git commands to generate.