2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
4 * Silicon Graphics Computer Systems, Inc.
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
19 #ifndef _STLP_IOS_BASE_H
20 #define _STLP_IOS_BASE_H
22 #ifndef _STLP_STDEXCEPT
28 #ifndef _STLP_INTERNAL_LOCALE_H
29 #include <stl/_locale.h>
31 #ifndef _STLP_STRING_H
32 # include <stl/_string.h>
37 // ----------------------------------------------------------------------
39 // Class ios_base. This is the base class of the ios hierarchy, which
40 // includes basic_istream and basic_ostream. Classes in the ios
41 // hierarchy are actually quite simple: they are just glorified
42 // wrapper classes. They delegate buffering and physical character
43 // manipulation to the streambuf classes, and they delegate most
44 // formatting tasks to a locale.
49 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 # ifdef _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 _STLP_DECLSPEC 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 _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(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
216 static bool _S_was_synced;
217 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
218 friend void CallIosInit();
219 private: // Invalidate the copy constructor and
220 // assignment operator.
221 ios_base(const ios_base&);
222 void operator=(const ios_base&);
224 private: // Data members.
226 fmtflags _M_fmtflags; // Flags
228 openmode _M_openmode;
230 iostate _M_exception_mask;
232 streamsize _M_precision;
237 pair<event_callback, int>* _M_callbacks;
238 size_t _M_num_callbacks; // Size of the callback array.
239 size_t _M_callback_index; // Index of the next available callback;
242 long* _M_iwords; // Auxiliary storage. The count is zero
243 size_t _M_num_iwords; // if and only if the pointer is null.
246 size_t _M_num_pwords;
248 # if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
250 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
254 // Cached copies of the curent locale's facets. Set by init() and imbue().
255 locale::facet* _M_cached_ctype;
256 locale::facet* _M_cached_numpunct;
257 string _M_cached_grouping;
259 // Equivalent to &use_facet< Facet >(getloc()), but faster.
260 const locale::facet* _M_ctype_facet() const { return _M_cached_ctype; }
261 const locale::facet* _M_numpunct_facet() const { return _M_cached_numpunct; }
262 const string& _M_grouping() const { return _M_cached_grouping; }
265 // ----------------------------------------------------------------------
266 // Nested initializer class. This is an implementation detail, but it's
267 // prescribed by the standard. The static initializer object (on
268 // implementations where such a thing is required) is declared in
271 class _STLP_CLASS_DECLSPEC Init {
273 _STLP_DECLSPEC Init();
274 _STLP_DECLSPEC ~Init();
276 # if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
277 static long _S_count;
278 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
279 friend class ios_base;
282 // this class is needed to ensure locale initialization w/o <iostream> inclusion
283 class _STLP_CLASS_DECLSPEC _Loc_init {
285 _STLP_DECLSPEC _Loc_init();
286 _STLP_DECLSPEC ~_Loc_init();
288 # if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
289 static long _S_count;
290 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
292 friend class ios_base;
298 # ifndef _STLP_NO_ANACHRONISMS
299 // 31.6 Old iostreams members [depr.ios.members]
300 typedef iostate io_state;
301 typedef openmode open_mode;
302 typedef seekdir seek_dir;
303 typedef _STLP_STD::streamoff streamoff;
304 typedef _STLP_STD::streampos streampos;
308 inline _STLP_EXP_DECLSPEC locale ios_base::getloc() const
313 // ----------------------------------------------------------------------
314 // ios_base manipulator functions, from section 27.4.5 of the C++ standard.
315 // All of them are trivial one-line wrapper functions.
317 // fmtflag manipulators, section 27.4.5.1
318 inline ios_base& _STLP_CALL boolalpha(ios_base& __s)
319 { __s.setf(ios_base::boolalpha); return __s;}
321 inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
322 { __s.unsetf(ios_base::boolalpha); return __s;}
324 inline ios_base& _STLP_CALL showbase(ios_base& __s)
325 { __s.setf(ios_base::showbase); return __s;}
327 inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
328 { __s.unsetf(ios_base::showbase); return __s;}
330 inline ios_base& _STLP_CALL showpoint(ios_base& __s)
331 { __s.setf(ios_base::showpoint); return __s;}
333 inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
334 { __s.unsetf(ios_base::showpoint); return __s;}
336 inline ios_base& _STLP_CALL showpos(ios_base& __s)
337 { __s.setf(ios_base::showpos); return __s;}
339 inline ios_base& _STLP_CALL noshowpos(ios_base& __s)
340 { __s.unsetf(ios_base::showpos); return __s;}
342 inline ios_base& _STLP_CALL skipws(ios_base& __s)
343 { __s.setf(ios_base::skipws); return __s;}
345 inline ios_base& _STLP_CALL noskipws(ios_base& __s)
346 { __s.unsetf(ios_base::skipws); return __s;}
348 inline ios_base& _STLP_CALL uppercase(ios_base& __s)
349 { __s.setf(ios_base::uppercase); return __s;}
351 inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
352 { __s.unsetf(ios_base::uppercase); return __s;}
354 inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
355 { __s.setf(ios_base::unitbuf); return __s;}
357 inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
358 { __s.unsetf(ios_base::unitbuf); return __s;}
361 // adjustfield manipulators, section 27.4.5.2
362 inline ios_base& _STLP_CALL internal(ios_base& __s)
363 { __s.setf(ios_base::internal, ios_base::adjustfield); return __s; }
365 inline ios_base& _STLP_CALL left(ios_base& __s)
366 { __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
368 inline ios_base& _STLP_CALL right(ios_base& __s)
369 { __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
371 // basefield manipulators, section 27.4.5.3
372 inline ios_base& _STLP_CALL dec(ios_base& __s)
373 { __s.setf(ios_base::dec, ios_base::basefield); return __s; }
375 inline ios_base& _STLP_CALL hex(ios_base& __s)
376 { __s.setf(ios_base::hex, ios_base::basefield); return __s; }
378 inline ios_base& _STLP_CALL oct(ios_base& __s)
379 { __s.setf(ios_base::oct, ios_base::basefield); return __s; }
382 // floatfield manipulators, section 27.4.5.3
383 inline ios_base& _STLP_CALL fixed(ios_base& __s)
384 { __s.setf(ios_base::fixed, ios_base::floatfield); return __s; }
386 inline ios_base& _STLP_CALL scientific(ios_base& __s)
387 { __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
389 #if defined(__BORLANDC__) && defined(_RTLDLL)
391 long ios_base::_Loc_init::_S_count = 0;
393 void _STLP_CALL _Stl_loc_init_num_put();
394 void _STLP_CALL _Stl_loc_init_num_get();
395 void _STLP_CALL _Stl_loc_init_monetary();
396 void _STLP_CALL _Stl_loc_init_time_facets();
398 inline ios_base::_Loc_init::_Loc_init() {
399 if (_S_count++ == 0) {
400 _Stl_loc_init_num_put();
401 _Stl_loc_init_num_get();
402 _Stl_loc_init_monetary();
403 _Stl_loc_init_time_facets();
404 locale::_S_initialize();
408 inline ios_base::_Loc_init::~_Loc_init() {
410 locale::_S_uninitialize();
413 #endif /* __BORLANDC__ */
417 #pragma message("Symbian I/O stream support on progress.")
418 inline ios_base::_Loc_init::_Loc_init() {
421 inline ios_base::_Loc_init::~_Loc_init() {
425 inline ios_base::Init::Init() {
428 inline ios_base::Init::~Init() {
434 #endif /* _STLP_IOS_BASE */