3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
18 #ifndef _STLP_IOS_BASE_H
19 #define _STLP_IOS_BASE_H
21 #ifndef _STLP_INTERNAL_STDEXCEPT_BASE
22 # include <stl/_stdexcept_base.h>
25 #ifndef _STLP_INTERNAL_PAIR_H
26 # include <stl/_pair.h>
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 # include <stl/_locale.h>
33 #ifndef _STLP_INTERNAL_STRING_H
34 # include <stl/_string.h>
39 // ----------------------------------------------------------------------
41 // Class ios_base. This is the base class of the ios hierarchy, which
42 // includes basic_istream and basic_ostream. Classes in the ios
43 // hierarchy are actually quite simple: they are just glorified
44 // wrapper classes. They delegate buffering and physical character
45 // manipulation to the streambuf classes, and they delegate most
46 // formatting tasks to a locale.
48 class _STLP_CLASS_DECLSPEC ios_base
{
51 class _STLP_CLASS_DECLSPEC failure
: public __Named_exception
{
53 explicit failure(const string
&);
54 virtual ~failure() _STLP_NOTHROW_INHERENTLY
;
62 # ifndef _STLP_NO_ANACHRONISMS
63 typedef fmtflags fmt_flags
;
67 _STLP_STATIC_CONSTANT(int, left
= 0x0001);
68 _STLP_STATIC_CONSTANT(int, right
= 0x0002);
69 _STLP_STATIC_CONSTANT(int, internal
= 0x0004);
70 _STLP_STATIC_CONSTANT(int, dec
= 0x0008);
71 _STLP_STATIC_CONSTANT(int, hex
= 0x0010);
72 _STLP_STATIC_CONSTANT(int, oct
= 0x0020);
73 _STLP_STATIC_CONSTANT(int, fixed
= 0x0040);
74 _STLP_STATIC_CONSTANT(int, scientific
= 0x0080);
75 _STLP_STATIC_CONSTANT(int, boolalpha
= 0x0100);
76 _STLP_STATIC_CONSTANT(int, showbase
= 0x0200);
77 _STLP_STATIC_CONSTANT(int, showpoint
= 0x0400);
78 _STLP_STATIC_CONSTANT(int, showpos
= 0x0800);
79 _STLP_STATIC_CONSTANT(int, skipws
= 0x1000);
80 _STLP_STATIC_CONSTANT(int, unitbuf
= 0x2000);
81 _STLP_STATIC_CONSTANT(int, uppercase
= 0x4000);
82 _STLP_STATIC_CONSTANT(int, adjustfield
= left
| right
| internal
);
83 _STLP_STATIC_CONSTANT(int, basefield
= dec
| hex
| oct
);
84 _STLP_STATIC_CONSTANT(int, floatfield
= scientific
| fixed
);
87 _STLP_STATIC_CONSTANT(int, goodbit
= 0x00);
88 _STLP_STATIC_CONSTANT(int, badbit
= 0x01);
89 _STLP_STATIC_CONSTANT(int, eofbit
= 0x02);
90 _STLP_STATIC_CONSTANT(int, failbit
= 0x04);
93 _STLP_STATIC_CONSTANT(int, __default_mode
= 0x0); /* implementation detail */
94 _STLP_STATIC_CONSTANT(int, app
= 0x01);
95 _STLP_STATIC_CONSTANT(int, ate
= 0x02);
96 _STLP_STATIC_CONSTANT(int, binary
= 0x04);
97 _STLP_STATIC_CONSTANT(int, in
= 0x08);
98 _STLP_STATIC_CONSTANT(int, out
= 0x10);
99 _STLP_STATIC_CONSTANT(int, trunc
= 0x20);
102 _STLP_STATIC_CONSTANT(int, beg
= 0x01);
103 _STLP_STATIC_CONSTANT(int, cur
= 0x02);
104 _STLP_STATIC_CONSTANT(int, end
= 0x04);
106 public: // Flag-manipulation functions.
107 fmtflags
flags() const { return _M_fmtflags
; }
108 fmtflags
flags(fmtflags __flags
) {
109 fmtflags __tmp
= _M_fmtflags
;
110 _M_fmtflags
= __flags
;
114 fmtflags
setf(fmtflags __flag
) {
115 fmtflags __tmp
= _M_fmtflags
;
116 _M_fmtflags
|= __flag
;
119 fmtflags
setf(fmtflags __flag
, fmtflags __mask
) {
120 fmtflags __tmp
= _M_fmtflags
;
121 _M_fmtflags
&= ~__mask
;
122 _M_fmtflags
|= __flag
& __mask
;
125 void unsetf(fmtflags __mask
) { _M_fmtflags
&= ~__mask
; }
127 streamsize
precision() const { return _M_precision
; }
128 streamsize
precision(streamsize __newprecision
) {
129 streamsize __tmp
= _M_precision
;
130 _M_precision
= __newprecision
;
134 streamsize
width() const { return _M_width
; }
135 streamsize
width(streamsize __newwidth
) {
136 streamsize __tmp
= _M_width
;
137 _M_width
= __newwidth
;
142 locale
imbue(const locale
&);
143 locale
getloc() const { return _M_locale
; }
145 public: // Auxiliary storage.
146 static int _STLP_CALL
xalloc();
147 long& iword(int __index
);
148 void*& pword(int __index
);
150 public: // Destructor.
153 public: // Callbacks.
154 enum event
{ erase_event
, imbue_event
, copyfmt_event
};
155 typedef void (*event_callback
)(event
, ios_base
&, int __index
);
156 void register_callback(event_callback __fn
, int __index
);
158 public: // This member function affects only
159 // the eight predefined ios objects:
161 static bool _STLP_CALL
sync_with_stdio(bool __sync
= true);
163 public: // The C++ standard requires only that these
164 // member functions be defined in basic_ios.
165 // We define them in the non-template
166 // base class to avoid code duplication.
167 operator void*() const { return !fail() ? (void*) __CONST_CAST(ios_base
*,this) : (void*) 0; }
168 bool operator!() const { return fail(); }
170 iostate
rdstate() const { return _M_iostate
; }
172 bool good() const { return _M_iostate
== 0; }
173 bool eof() const { return (_M_iostate
& eofbit
) != 0; }
174 bool fail() const { return (_M_iostate
& (failbit
| badbit
)) != 0; }
175 bool bad() const { return (_M_iostate
& badbit
) != 0; }
177 protected: // The functional protected interface.
179 // Copies the state of __x to *this. This member function makes it
180 // possible to implement basic_ios::copyfmt without having to expose
181 // ios_base's private data members. Does not copy _M_exception_mask
183 void _M_copy_state(const ios_base
& __x
);
185 void _M_setstate_nothrow(iostate __state
) { _M_iostate
|= __state
; }
186 void _M_clear_nothrow(iostate __state
) { _M_iostate
= __state
; }
187 iostate
_M_get_exception_mask() const { return _M_exception_mask
; }
188 void _M_set_exception_mask(iostate __mask
) { _M_exception_mask
= __mask
; }
189 void _M_check_exception_mask() {
190 if (_M_iostate
& _M_exception_mask
)
194 void _M_invoke_callbacks(event
);
195 void _STLP_FUNCTION_THROWS
_M_throw_failure();
197 ios_base(); // Default constructor.
199 protected: // Initialization of the I/O system
200 static void _STLP_CALL
_S_initialize();
201 static void _STLP_CALL
_S_uninitialize();
202 static bool _S_is_synced
;
204 private: // Invalidate the copy constructor and
205 // assignment operator.
206 ios_base(const ios_base
&);
207 void operator=(const ios_base
&);
209 private: // Data members.
211 fmtflags _M_fmtflags
; // Flags
213 openmode _M_openmode
;
215 iostate _M_exception_mask
;
217 streamsize _M_precision
;
222 pair
<event_callback
, int>* _M_callbacks
;
223 size_t _M_num_callbacks
; // Size of the callback array.
224 size_t _M_callback_index
; // Index of the next available callback;
227 long* _M_iwords
; // Auxiliary storage. The count is zero
228 size_t _M_num_iwords
; // if and only if the pointer is null.
231 size_t _M_num_pwords
;
234 // ----------------------------------------------------------------------
235 // Nested initializer class. This is an implementation detail, but it's
236 // prescribed by the standard. The static initializer object (on
237 // implementations where such a thing is required) is declared in
239 class _STLP_CLASS_DECLSPEC Init
245 static long _S_count
;
246 friend class ios_base
;
252 # ifndef _STLP_NO_ANACHRONISMS
253 // 31.6 Old iostreams members [depr.ios.members]
254 typedef iostate io_state
;
255 typedef openmode open_mode
;
256 typedef seekdir seek_dir
;
257 typedef _STLP_STD::streamoff streamoff
;
258 typedef _STLP_STD::streampos streampos
;
262 // ----------------------------------------------------------------------
263 // ios_base manipulator functions, from section 27.4.5 of the C++ standard.
264 // All of them are trivial one-line wrapper functions.
266 // fmtflag manipulators, section 27.4.5.1
267 inline ios_base
& _STLP_CALL
boolalpha(ios_base
& __s
)
268 { __s
.setf(ios_base::boolalpha
); return __s
;}
270 inline ios_base
& _STLP_CALL
noboolalpha(ios_base
& __s
)
271 { __s
.unsetf(ios_base::boolalpha
); return __s
;}
273 inline ios_base
& _STLP_CALL
showbase(ios_base
& __s
)
274 { __s
.setf(ios_base::showbase
); return __s
;}
276 inline ios_base
& _STLP_CALL
noshowbase(ios_base
& __s
)
277 { __s
.unsetf(ios_base::showbase
); return __s
;}
279 inline ios_base
& _STLP_CALL
showpoint(ios_base
& __s
)
280 { __s
.setf(ios_base::showpoint
); return __s
;}
282 inline ios_base
& _STLP_CALL
noshowpoint(ios_base
& __s
)
283 { __s
.unsetf(ios_base::showpoint
); return __s
;}
285 inline ios_base
& _STLP_CALL
showpos(ios_base
& __s
)
286 { __s
.setf(ios_base::showpos
); return __s
;}
288 inline ios_base
& _STLP_CALL
noshowpos(ios_base
& __s
)
289 { __s
.unsetf(ios_base::showpos
); return __s
;}
291 inline ios_base
& _STLP_CALL
skipws(ios_base
& __s
)
292 { __s
.setf(ios_base::skipws
); return __s
;}
294 inline ios_base
& _STLP_CALL
noskipws(ios_base
& __s
)
295 { __s
.unsetf(ios_base::skipws
); return __s
;}
297 inline ios_base
& _STLP_CALL
uppercase(ios_base
& __s
)
298 { __s
.setf(ios_base::uppercase
); return __s
;}
300 inline ios_base
& _STLP_CALL
nouppercase(ios_base
& __s
)
301 { __s
.unsetf(ios_base::uppercase
); return __s
;}
303 inline ios_base
& _STLP_CALL
unitbuf(ios_base
& __s
)
304 { __s
.setf(ios_base::unitbuf
); return __s
;}
306 inline ios_base
& _STLP_CALL
nounitbuf(ios_base
& __s
)
307 { __s
.unsetf(ios_base::unitbuf
); return __s
;}
310 // adjustfield manipulators, section 27.4.5.2
311 inline ios_base
& _STLP_CALL
internal(ios_base
& __s
)
312 { __s
.setf(ios_base::internal
, ios_base::adjustfield
); return __s
; }
314 inline ios_base
& _STLP_CALL
left(ios_base
& __s
)
315 { __s
.setf(ios_base::left
, ios_base::adjustfield
); return __s
; }
317 inline ios_base
& _STLP_CALL
right(ios_base
& __s
)
318 { __s
.setf(ios_base::right
, ios_base::adjustfield
); return __s
; }
320 // basefield manipulators, section 27.4.5.3
321 inline ios_base
& _STLP_CALL
dec(ios_base
& __s
)
322 { __s
.setf(ios_base::dec
, ios_base::basefield
); return __s
; }
324 inline ios_base
& _STLP_CALL
hex(ios_base
& __s
)
325 { __s
.setf(ios_base::hex
, ios_base::basefield
); return __s
; }
327 inline ios_base
& _STLP_CALL
oct(ios_base
& __s
)
328 { __s
.setf(ios_base::oct
, ios_base::basefield
); return __s
; }
331 // floatfield manipulators, section 27.4.5.3
332 inline ios_base
& _STLP_CALL
fixed(ios_base
& __s
)
333 { __s
.setf(ios_base::fixed
, ios_base::floatfield
); return __s
; }
335 inline ios_base
& _STLP_CALL
scientific(ios_base
& __s
)
336 { __s
.setf(ios_base::scientific
, ios_base::floatfield
); return __s
; }
340 #endif /* _STLP_IOS_BASE */