2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 #ifndef _STLP_IOS_BASE_H
21 #define _STLP_IOS_BASE_H
23 #ifndef _STLP_INTERNAL_STDEXCEPT_BASE
24 # include <stl/_stdexcept_base.h>
31 #ifndef _STLP_INTERNAL_LOCALE_H
32 # include <stl/_locale.h>
35 #ifndef _STLP_INTERNAL_STRING_H
36 # include <stl/_string.h>
41 // ----------------------------------------------------------------------
43 // Class ios_base. This is the base class of the ios hierarchy, which
44 // includes basic_istream and basic_ostream. Classes in the ios
45 // hierarchy are actually quite simple: they are just glorified
46 // wrapper classes. They delegate buffering and physical character
47 // manipulation to the streambuf classes, and they delegate most
48 // formatting tasks to a locale.
50 class _STLP_CLASS_DECLSPEC ios_base {
53 class _STLP_CLASS_DECLSPEC failure : public __Named_exception {
55 _STLP_DECLSPEC explicit failure(const string&);
56 _STLP_DECLSPEC virtual ~failure() _STLP_NOTHROW_INHERENTLY;
64 # ifndef _STLP_NO_ANACHRONISMS
65 typedef fmtflags fmt_flags;
69 #if defined (_STLP_STATIC_CONST_INIT_BUG)
72 // boris : type for all those constants is int
90 adjustfield = left | right | internal,
91 basefield = dec | hex | oct,
92 floatfield = scientific | fixed,
101 __default_mode = 0x0, /* implementation detail */
114 # ifdef _STLP_STATIC_CONST_INIT_BUG
119 public: // Flag-manipulation functions.
120 fmtflags flags() const { return _M_fmtflags; }
121 fmtflags flags(fmtflags __flags) {
122 fmtflags __tmp = _M_fmtflags;
123 _M_fmtflags = __flags;
127 fmtflags setf(fmtflags __flag) {
128 fmtflags __tmp = _M_fmtflags;
129 _M_fmtflags |= __flag;
132 fmtflags setf(fmtflags __flag, fmtflags __mask) {
133 fmtflags __tmp = _M_fmtflags;
134 _M_fmtflags &= ~__mask;
135 _M_fmtflags |= __flag & __mask;
138 void unsetf(fmtflags __mask) { _M_fmtflags &= ~__mask; }
140 streamsize precision() const { return _M_precision; }
141 streamsize precision(streamsize __newprecision) {
142 streamsize __tmp = _M_precision;
143 _M_precision = __newprecision;
147 streamsize width() const { return _M_width; }
148 streamsize width(streamsize __newwidth) {
149 streamsize __tmp = _M_width;
150 _M_width = __newwidth;
155 _STLP_DECLSPEC locale imbue(const locale&);
156 locale getloc() const { return _M_locale; }
158 public: // Auxiliary storage.
159 _STLP_DECLSPEC static int _STLP_CALL xalloc();
160 _STLP_DECLSPEC long& iword(int __index);
161 _STLP_DECLSPEC void*& pword(int __index);
163 public: // Destructor.
164 _STLP_DECLSPEC virtual ~ios_base();
166 public: // Callbacks.
167 enum event { erase_event, imbue_event, copyfmt_event };
168 typedef void (*event_callback)(event, ios_base&, int __index);
169 _STLP_DECLSPEC void register_callback(event_callback __fn, int __index);
171 public: // This member function affects only
172 // the eight predefined ios objects:
174 _STLP_DECLSPEC static bool _STLP_CALL sync_with_stdio(bool __sync = true);
176 public: // The C++ standard requires only that these
177 // member functions be defined in basic_ios.
178 // We define them in the non-template
179 // base class to avoid code duplication.
180 operator void*() const { return !fail() ? (void*) __CONST_CAST(ios_base*,this) : (void*) 0; }
181 bool operator!() const { return fail(); }
183 iostate rdstate() const { return _M_iostate; }
185 bool good() const { return _M_iostate == 0; }
186 bool eof() const { return (_M_iostate & eofbit) != 0; }
187 bool fail() const { return (_M_iostate & (failbit | badbit)) != 0; }
188 bool bad() const { return (_M_iostate & badbit) != 0; }
190 protected: // The functional protected interface.
192 // Copies the state of __x to *this. This member function makes it
193 // possible to implement basic_ios::copyfmt without having to expose
194 // ios_base's private data members. Does not copy _M_exception_mask
196 _STLP_DECLSPEC void _M_copy_state(const ios_base& __x);
198 void _M_setstate_nothrow(iostate __state) { _M_iostate |= __state; }
199 void _M_clear_nothrow(iostate __state) { _M_iostate = __state; }
200 iostate _M_get_exception_mask() const { return _M_exception_mask; }
201 void _M_set_exception_mask(iostate __mask) { _M_exception_mask = __mask; }
202 void _M_check_exception_mask() {
203 if (_M_iostate & _M_exception_mask)
207 _STLP_DECLSPEC void _M_invoke_callbacks(event);
208 _STLP_DECLSPEC void _STLP_FUNCTION_THROWS _M_throw_failure();
210 _STLP_DECLSPEC ios_base(); // Default constructor.
212 protected: // Initialization of the I/O system
213 static void _STLP_CALL _S_initialize();
214 static void _STLP_CALL _S_uninitialize();
215 # if defined(__SYMBIAN32__WSD__)
217 static void ios_base_S_was_synced_init()
219 get_ios_base_S_was_synced() = true;
222 static inline bool& get_ios_base_S_was_synced();
224 static bool _S_was_synced;
225 # endif //__SYMBIAN32__WSD__
228 private: // Invalidate the copy constructor and
229 // assignment operator.
230 ios_base(const ios_base&);
231 void operator=(const ios_base&);
233 private: // Data members.
235 fmtflags _M_fmtflags; // Flags
237 openmode _M_openmode;
239 iostate _M_exception_mask;
241 streamsize _M_precision;
246 pair<event_callback, int>* _M_callbacks;
247 size_t _M_num_callbacks; // Size of the callback array.
248 size_t _M_callback_index; // Index of the next available callback;
251 long* _M_iwords; // Auxiliary storage. The count is zero
252 size_t _M_num_iwords; // if and only if the pointer is null.
255 size_t _M_num_pwords;
258 // Cached copies of the curent locale's facets. Set by init() and imbue().
259 locale::facet* _M_cached_ctype;
260 locale::facet* _M_cached_numpunct;
261 string _M_cached_grouping;
263 // Equivalent to &use_facet< Facet >(getloc()), but faster.
264 const locale::facet* _M_ctype_facet() const { return _M_cached_ctype; }
265 const locale::facet* _M_numpunct_facet() const { return _M_cached_numpunct; }
266 const string& _M_grouping() const { return _M_cached_grouping; }
269 // ----------------------------------------------------------------------
270 // Nested initializer class. This is an implementation detail, but it's
271 // prescribed by the standard. The static initializer object (on
272 // implementations where such a thing is required) is declared in
275 class _STLP_CLASS_DECLSPEC Init
278 _STLP_DECLSPEC Init();
279 _STLP_DECLSPEC ~Init();
280 # if defined(__SYMBIAN32__WSD__)
281 static inline void ios_base_Init_S_count_init()
283 get_ios_base_Init_S_count() = 0;
286 static inline long& get_ios_base_Init_S_count();
289 static long _S_count;
290 # endif //__SYMBIAN32__WSD__
291 friend class ios_base;
297 # ifndef _STLP_NO_ANACHRONISMS
298 // 31.6 Old iostreams members [depr.ios.members]
299 typedef iostate io_state;
300 typedef openmode open_mode;
301 typedef seekdir seek_dir;
302 typedef _STLP_STD::streamoff streamoff;
303 typedef _STLP_STD::streampos streampos;
307 // ----------------------------------------------------------------------
308 // ios_base manipulator functions, from section 27.4.5 of the C++ standard.
309 // All of them are trivial one-line wrapper functions.
311 // fmtflag manipulators, section 27.4.5.1
312 inline ios_base& _STLP_CALL boolalpha(ios_base& __s)
313 { __s.setf(ios_base::boolalpha); return __s;}
315 inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
316 { __s.unsetf(ios_base::boolalpha); return __s;}
318 inline ios_base& _STLP_CALL showbase(ios_base& __s)
319 { __s.setf(ios_base::showbase); return __s;}
321 inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
322 { __s.unsetf(ios_base::showbase); return __s;}
324 inline ios_base& _STLP_CALL showpoint(ios_base& __s)
325 { __s.setf(ios_base::showpoint); return __s;}
327 inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
328 { __s.unsetf(ios_base::showpoint); return __s;}
330 inline ios_base& _STLP_CALL showpos(ios_base& __s)
331 { __s.setf(ios_base::showpos); return __s;}
333 inline ios_base& _STLP_CALL noshowpos(ios_base& __s)
334 { __s.unsetf(ios_base::showpos); return __s;}
336 inline ios_base& _STLP_CALL skipws(ios_base& __s)
337 { __s.setf(ios_base::skipws); return __s;}
339 inline ios_base& _STLP_CALL noskipws(ios_base& __s)
340 { __s.unsetf(ios_base::skipws); return __s;}
342 inline ios_base& _STLP_CALL uppercase(ios_base& __s)
343 { __s.setf(ios_base::uppercase); return __s;}
345 inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
346 { __s.unsetf(ios_base::uppercase); return __s;}
348 inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
349 { __s.setf(ios_base::unitbuf); return __s;}
351 inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
352 { __s.unsetf(ios_base::unitbuf); return __s;}
355 // adjustfield manipulators, section 27.4.5.2
356 inline ios_base& _STLP_CALL internal(ios_base& __s)
357 { __s.setf(ios_base::internal, ios_base::adjustfield); return __s; }
359 inline ios_base& _STLP_CALL left(ios_base& __s)
360 { __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
362 inline ios_base& _STLP_CALL right(ios_base& __s)
363 { __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
365 // basefield manipulators, section 27.4.5.3
366 inline ios_base& _STLP_CALL dec(ios_base& __s)
367 { __s.setf(ios_base::dec, ios_base::basefield); return __s; }
369 inline ios_base& _STLP_CALL hex(ios_base& __s)
370 { __s.setf(ios_base::hex, ios_base::basefield); return __s; }
372 inline ios_base& _STLP_CALL oct(ios_base& __s)
373 { __s.setf(ios_base::oct, ios_base::basefield); return __s; }
376 // floatfield manipulators, section 27.4.5.3
377 inline ios_base& _STLP_CALL fixed(ios_base& __s)
378 { __s.setf(ios_base::fixed, ios_base::floatfield); return __s; }
380 inline ios_base& _STLP_CALL scientific(ios_base& __s)
381 { __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
385 #endif /* _STLP_IOS_BASE */