00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _STLP_IOS_BASE_H
00019 #define _STLP_IOS_BASE_H
00020
00021 #ifndef _STLP_STDEXCEPT
00022 #include <stdexcept>
00023 #endif
00024 #ifndef _STLP_UTILITY
00025 #include <utility>
00026 #endif
00027 #ifndef _STLP_INTERNAL_LOCALE_H
00028 #include <stl/_locale.h>
00029 #endif
00030 #ifndef _STLP_STRING_H
00031 # include <stl/_string.h>
00032 #endif
00033
00034 _STLP_BEGIN_NAMESPACE
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class _STLP_CLASS_DECLSPEC ios_base {
00046 public:
00047
00048 class _STLP_CLASS_DECLSPEC failure : public __Named_exception {
00049 public:
00050 explicit failure(const string&);
00051 virtual ~failure() _STLP_NOTHROW_INHERENTLY;
00052 };
00053
00054 typedef int fmtflags;
00055 typedef int iostate;
00056 typedef int openmode;
00057 typedef int seekdir;
00058
00059 # ifndef _STLP_NO_ANACHRONISMS
00060 typedef fmtflags fmt_flags;
00061 # endif
00062
00063
00064 # ifdef _STLP_STATIC_CONST_INIT_BUG
00065 enum {
00066 # else
00067
00068 static const int
00069 # endif
00070 left = 0x0001,
00071 right = 0x0002,
00072 internal = 0x0004,
00073 dec = 0x0008,
00074 hex = 0x0010,
00075 oct = 0x0020,
00076 fixed = 0x0040,
00077 scientific = 0x0080,
00078 boolalpha = 0x0100,
00079 showbase = 0x0200,
00080 showpoint = 0x0400,
00081 showpos = 0x0800,
00082 skipws = 0x1000,
00083 unitbuf = 0x2000,
00084 uppercase = 0x4000,
00085 adjustfield = left | right | internal,
00086 basefield = dec | hex | oct,
00087 floatfield = scientific | fixed,
00088
00089
00090 goodbit = 0x00,
00091 badbit = 0x01,
00092 eofbit = 0x02,
00093 failbit = 0x04,
00094
00095
00096 __default_mode = 0x0,
00097 app = 0x01,
00098 ate = 0x02,
00099 binary = 0x04,
00100 in = 0x08,
00101 out = 0x10,
00102 trunc = 0x20,
00103
00104
00105
00106 beg = 0x01,
00107 cur = 0x02,
00108 end = 0x04
00109 # ifdef _STLP_STATIC_CONST_INIT_BUG
00110 }
00111 # endif
00112 ;
00113
00114 public:
00115 fmtflags flags() const { return _M_fmtflags; }
00116 fmtflags flags(fmtflags __flags) {
00117 fmtflags __tmp = _M_fmtflags;
00118 _M_fmtflags = __flags;
00119 return __tmp;
00120 }
00121
00122 fmtflags setf(fmtflags __flag) {
00123 fmtflags __tmp = _M_fmtflags;
00124 _M_fmtflags |= __flag;
00125 return __tmp;
00126 }
00127 fmtflags setf(fmtflags __flag, fmtflags __mask) {
00128 fmtflags __tmp = _M_fmtflags;
00129 _M_fmtflags &= ~__mask;
00130 _M_fmtflags |= __flag & __mask;
00131 return __tmp;
00132 }
00133 void unsetf(fmtflags __mask) { _M_fmtflags &= ~__mask; }
00134
00135 streamsize precision() const { return _M_precision; }
00136 streamsize precision(streamsize __newprecision) {
00137 streamsize __tmp = _M_precision;
00138 _M_precision = __newprecision;
00139 return __tmp;
00140 }
00141
00142 streamsize width() const { return _M_width; }
00143 streamsize width(streamsize __newwidth) {
00144 streamsize __tmp = _M_width;
00145 _M_width = __newwidth;
00146 return __tmp;
00147 }
00148
00149 public:
00150 locale imbue(const locale&);
00151 locale getloc() const { return _M_locale; }
00152
00153 public:
00154 static int _STLP_CALL xalloc();
00155 long& iword(int __index);
00156 void*& pword(int __index);
00157
00158 public:
00159 virtual ~ios_base();
00160
00161 public:
00162 enum event { erase_event, imbue_event, copyfmt_event };
00163 typedef void (*event_callback)(event, ios_base&, int __index);
00164 void register_callback(event_callback __fn, int __index);
00165
00166 public:
00167
00168
00169 static bool _STLP_CALL sync_with_stdio(bool __sync = true);
00170
00171 public:
00172
00173
00174
00175 operator void*() const { return !fail() ? (void*) __CONST_CAST(ios_base*,this) : (void*) 0; }
00176 bool operator!() const { return fail(); }
00177
00178 iostate rdstate() const { return _M_iostate; }
00179
00180 bool good() const { return _M_iostate == 0; }
00181 bool eof() const { return (_M_iostate & eofbit) != 0; }
00182 bool fail() const { return (_M_iostate & (failbit | badbit)) != 0; }
00183 bool bad() const { return (_M_iostate & badbit) != 0; }
00184
00185 protected:
00186
00187
00188
00189
00190
00191 void _M_copy_state(const ios_base& __x);
00192
00193 void _M_setstate_nothrow(iostate __state) { _M_iostate |= __state; }
00194 void _M_clear_nothrow(iostate __state) { _M_iostate = __state; }
00195 iostate _M_get_exception_mask() const { return _M_exception_mask; }
00196 void _M_set_exception_mask(iostate __mask) { _M_exception_mask = __mask; }
00197 void _M_check_exception_mask()
00198 { if (_M_iostate & _M_exception_mask) _M_throw_failure(); }
00199
00200 void _M_invoke_callbacks(event);
00201 void _M_throw_failure();
00202
00203 ios_base();
00204
00205 protected:
00206 static void _STLP_CALL _S_initialize();
00207 static void _STLP_CALL _S_uninitialize();
00208 static bool _S_was_synced;
00209
00210 private:
00211
00212 ios_base(const ios_base&);
00213 void operator=(const ios_base&);
00214
00215 private:
00216
00217 fmtflags _M_fmtflags;
00218 iostate _M_iostate;
00219 openmode _M_openmode;
00220 seekdir _M_seekdir;
00221 iostate _M_exception_mask;
00222
00223 streamsize _M_precision;
00224 streamsize _M_width;
00225
00226 locale _M_locale;
00227
00228 pair<event_callback, int>* _M_callbacks;
00229 size_t _M_num_callbacks;
00230 size_t _M_callback_index;
00231
00232
00233 long* _M_iwords;
00234 size_t _M_num_iwords;
00235
00236 void** _M_pwords;
00237 size_t _M_num_pwords;
00238
00239 static int _S_index;
00240
00241 protected:
00242
00243 locale::facet* _M_cached_ctype;
00244 locale::facet* _M_cached_numpunct;
00245 string _M_cached_grouping;
00246 public:
00247
00248 const locale::facet* _M_ctype_facet() const { return _M_cached_ctype; }
00249 const locale::facet* _M_numpunct_facet() const { return _M_cached_numpunct; }
00250 const string& _M_grouping() const { return _M_cached_grouping; }
00251 public:
00252
00253
00254
00255
00256
00257
00258
00259 class _STLP_CLASS_DECLSPEC Init {
00260 public:
00261 Init();
00262 ~Init();
00263 private:
00264 static long _S_count;
00265 friend class ios_base;
00266 };
00267
00268
00269 class _STLP_CLASS_DECLSPEC _Loc_init {
00270 public:
00271 _Loc_init();
00272 ~_Loc_init();
00273 private:
00274 static long _S_count;
00275 friend class ios_base;
00276 };
00277
00278 friend class Init;
00279
00280 public:
00281 # ifndef _STLP_NO_ANACHRONISMS
00282
00283 typedef iostate io_state;
00284 typedef openmode open_mode;
00285 typedef seekdir seek_dir;
00286 typedef _STLP_STD::streamoff streamoff;
00287 typedef _STLP_STD::streampos streampos;
00288 # endif
00289 };
00290
00291 template <class Facet>
00292 locale::facet* _M_get_facet(ios_base& __i, Facet*)
00293 {
00294
00295 }
00296
00297
00298
00299
00300
00301
00302 inline ios_base& _STLP_CALL boolalpha(ios_base& __s)
00303 { __s.setf(ios_base::boolalpha); return __s;}
00304
00305 inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
00306 { __s.unsetf(ios_base::boolalpha); return __s;}
00307
00308 inline ios_base& _STLP_CALL showbase(ios_base& __s)
00309 { __s.setf(ios_base::showbase); return __s;}
00310
00311 inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
00312 { __s.unsetf(ios_base::showbase); return __s;}
00313
00314 inline ios_base& _STLP_CALL showpoint(ios_base& __s)
00315 { __s.setf(ios_base::showpoint); return __s;}
00316
00317 inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
00318 { __s.unsetf(ios_base::showpoint); return __s;}
00319
00320 inline ios_base& _STLP_CALL showpos(ios_base& __s)
00321 { __s.setf(ios_base::showpos); return __s;}
00322
00323 inline ios_base& _STLP_CALL noshowpos(ios_base& __s)
00324 { __s.unsetf(ios_base::showpos); return __s;}
00325
00326 inline ios_base& _STLP_CALL skipws(ios_base& __s)
00327 { __s.setf(ios_base::skipws); return __s;}
00328
00329 inline ios_base& _STLP_CALL noskipws(ios_base& __s)
00330 { __s.unsetf(ios_base::skipws); return __s;}
00331
00332 inline ios_base& _STLP_CALL uppercase(ios_base& __s)
00333 { __s.setf(ios_base::uppercase); return __s;}
00334
00335 inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
00336 { __s.unsetf(ios_base::uppercase); return __s;}
00337
00338 inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
00339 { __s.setf(ios_base::unitbuf); return __s;}
00340
00341 inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
00342 { __s.unsetf(ios_base::unitbuf); return __s;}
00343
00344
00345
00346 inline ios_base& _STLP_CALL internal(ios_base& __s)
00347 { __s.setf(ios_base::internal, ios_base::adjustfield); return __s; }
00348
00349 inline ios_base& _STLP_CALL left(ios_base& __s)
00350 { __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
00351
00352 inline ios_base& _STLP_CALL right(ios_base& __s)
00353 { __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
00354
00355
00356 inline ios_base& _STLP_CALL dec(ios_base& __s)
00357 { __s.setf(ios_base::dec, ios_base::basefield); return __s; }
00358
00359 inline ios_base& _STLP_CALL hex(ios_base& __s)
00360 { __s.setf(ios_base::hex, ios_base::basefield); return __s; }
00361
00362 inline ios_base& _STLP_CALL oct(ios_base& __s)
00363 { __s.setf(ios_base::oct, ios_base::basefield); return __s; }
00364
00365
00366
00367 inline ios_base& _STLP_CALL fixed(ios_base& __s)
00368 { __s.setf(ios_base::fixed, ios_base::floatfield); return __s; }
00369
00370 inline ios_base& _STLP_CALL scientific(ios_base& __s)
00371 { __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
00372
00373 #if defined(__BORLANDC__) && defined(_RTLDLL)
00374
00375 long ios_base::_Loc_init::_S_count = 0;
00376
00377 void _STLP_CALL _Stl_loc_init_num_put();
00378 void _STLP_CALL _Stl_loc_init_num_get();
00379 void _STLP_CALL _Stl_loc_init_monetary();
00380 void _STLP_CALL _Stl_loc_init_time_facets();
00381
00382 inline ios_base::_Loc_init::_Loc_init() {
00383 if (_S_count++ == 0) {
00384 _Stl_loc_init_num_put();
00385 _Stl_loc_init_num_get();
00386 _Stl_loc_init_monetary();
00387 _Stl_loc_init_time_facets();
00388 locale::_S_initialize();
00389 }
00390 }
00391
00392 inline ios_base::_Loc_init::~_Loc_init() {
00393 if (--_S_count == 0)
00394 locale::_S_uninitialize();
00395 }
00396
00397 #endif
00398
00399 _STLP_END_NAMESPACE
00400
00401 #endif
00402
00403
00404
00405
00406