1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_ios_base.h Wed Mar 31 12:27:01 2010 +0100
1.3 @@ -0,0 +1,439 @@
1.4 +/*
1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 + * Copyright (c) 1999
1.7 + * Silicon Graphics Computer Systems, Inc.
1.8 + *
1.9 + * Copyright (c) 1999
1.10 + * Boris Fomitchev
1.11 + *
1.12 + * This material is provided "as is", with absolutely no warranty expressed
1.13 + * or implied. Any use is at your own risk.
1.14 + *
1.15 + * Permission to use or copy this software for any purpose is hereby granted
1.16 + * without fee, provided the above notices are retained on all copies.
1.17 + * Permission to modify the code and to distribute modified code is granted,
1.18 + * provided the above notices are retained, and a notice that the code was
1.19 + * modified is included with the above copyright notice.
1.20 + *
1.21 + */
1.22 +#ifndef _STLP_IOS_BASE_H
1.23 +#define _STLP_IOS_BASE_H
1.24 +
1.25 +#ifndef _STLP_STDEXCEPT
1.26 +#include <stdexcept>
1.27 +#endif
1.28 +#ifndef _STLP_UTILITY
1.29 +#include <utility>
1.30 +#endif
1.31 +#ifndef _STLP_INTERNAL_LOCALE_H
1.32 +#include <stl/_locale.h>
1.33 +#endif
1.34 +#ifndef _STLP_STRING_H
1.35 +# include <stl/_string.h>
1.36 +#endif
1.37 +
1.38 +_STLP_BEGIN_NAMESPACE
1.39 +
1.40 +// ----------------------------------------------------------------------
1.41 +
1.42 +// Class ios_base. This is the base class of the ios hierarchy, which
1.43 +// includes basic_istream and basic_ostream. Classes in the ios
1.44 +// hierarchy are actually quite simple: they are just glorified
1.45 +// wrapper classes. They delegate buffering and physical character
1.46 +// manipulation to the streambuf classes, and they delegate most
1.47 +// formatting tasks to a locale.
1.48 +
1.49 +#ifdef __SYMBIAN32__
1.50 +class ios_base {
1.51 +#else
1.52 +class _STLP_CLASS_DECLSPEC ios_base {
1.53 +#endif
1.54 +public:
1.55 +
1.56 + class _STLP_CLASS_DECLSPEC failure : public __Named_exception {
1.57 + public:
1.58 + _STLP_DECLSPEC explicit failure(const string&);
1.59 + _STLP_DECLSPEC virtual ~failure() _STLP_NOTHROW_INHERENTLY;
1.60 + };
1.61 +
1.62 + typedef int fmtflags;
1.63 + typedef int iostate;
1.64 + typedef int openmode;
1.65 + typedef int seekdir;
1.66 +
1.67 +# ifndef _STLP_NO_ANACHRONISMS
1.68 + typedef fmtflags fmt_flags;
1.69 +# endif
1.70 +
1.71 + // Formatting flags.
1.72 +# ifdef _STLP_STATIC_CONST_INIT_BUG
1.73 + enum {
1.74 +# else
1.75 + // boris : type for all those constants is int
1.76 + static const int
1.77 +# endif
1.78 + left = 0x0001,
1.79 + right = 0x0002,
1.80 + internal = 0x0004,
1.81 + dec = 0x0008,
1.82 + hex = 0x0010,
1.83 + oct = 0x0020,
1.84 + fixed = 0x0040,
1.85 + scientific = 0x0080,
1.86 + boolalpha = 0x0100,
1.87 + showbase = 0x0200,
1.88 + showpoint = 0x0400,
1.89 + showpos = 0x0800,
1.90 + skipws = 0x1000,
1.91 + unitbuf = 0x2000,
1.92 + uppercase = 0x4000,
1.93 + adjustfield = left | right | internal,
1.94 + basefield = dec | hex | oct,
1.95 + floatfield = scientific | fixed,
1.96 +
1.97 + // State flags.
1.98 + goodbit = 0x00,
1.99 + badbit = 0x01,
1.100 + eofbit = 0x02,
1.101 + failbit = 0x04,
1.102 +
1.103 + // Openmode flags.
1.104 + __default_mode = 0x0, /* implementation detail */
1.105 + app = 0x01,
1.106 + ate = 0x02,
1.107 + binary = 0x04,
1.108 + in = 0x08,
1.109 + out = 0x10,
1.110 + trunc = 0x20,
1.111 +
1.112 + // Seekdir flags
1.113 +
1.114 + beg = 0x01,
1.115 + cur = 0x02,
1.116 + end = 0x04
1.117 +# ifdef _STLP_STATIC_CONST_INIT_BUG
1.118 + }
1.119 +# endif
1.120 + ;
1.121 +
1.122 +public: // Flag-manipulation functions.
1.123 + fmtflags flags() const { return _M_fmtflags; }
1.124 + fmtflags flags(fmtflags __flags) {
1.125 + fmtflags __tmp = _M_fmtflags;
1.126 + _M_fmtflags = __flags;
1.127 + return __tmp;
1.128 + }
1.129 +
1.130 + fmtflags setf(fmtflags __flag) {
1.131 + fmtflags __tmp = _M_fmtflags;
1.132 + _M_fmtflags |= __flag;
1.133 + return __tmp;
1.134 + }
1.135 + fmtflags setf(fmtflags __flag, fmtflags __mask) {
1.136 + fmtflags __tmp = _M_fmtflags;
1.137 + _M_fmtflags &= ~__mask;
1.138 + _M_fmtflags |= __flag & __mask;
1.139 + return __tmp;
1.140 + }
1.141 + void unsetf(fmtflags __mask) { _M_fmtflags &= ~__mask; }
1.142 +
1.143 + streamsize precision() const { return _M_precision; }
1.144 + streamsize precision(streamsize __newprecision) {
1.145 + streamsize __tmp = _M_precision;
1.146 + _M_precision = __newprecision;
1.147 + return __tmp;
1.148 + }
1.149 +
1.150 + streamsize width() const { return _M_width; }
1.151 + streamsize width(streamsize __newwidth) {
1.152 + streamsize __tmp = _M_width;
1.153 + _M_width = __newwidth;
1.154 + return __tmp;
1.155 + }
1.156 +
1.157 +public: // Locales
1.158 + _STLP_DECLSPEC locale imbue(const locale&);
1.159 + _STLP_DECLSPEC locale getloc() const;// { return _M_locale; }
1.160 +
1.161 +public: // Auxiliary storage.
1.162 + _STLP_DECLSPEC static int _STLP_CALL xalloc();
1.163 + _STLP_DECLSPEC long& iword(int __index);
1.164 + _STLP_DECLSPEC void*& pword(int __index);
1.165 +
1.166 +public: // Destructor.
1.167 + _STLP_DECLSPEC virtual ~ios_base();
1.168 +
1.169 +public: // Callbacks.
1.170 + enum event { erase_event, imbue_event, copyfmt_event };
1.171 + typedef void (*event_callback)(event, ios_base&, int __index);
1.172 + _STLP_DECLSPEC void register_callback(event_callback __fn, int __index);
1.173 +
1.174 +public: // This member function affects only
1.175 + // the eight predefined ios objects:
1.176 + // cin, cout, etc.
1.177 + _STLP_DECLSPEC static bool _STLP_CALL sync_with_stdio(bool __sync = true);
1.178 +
1.179 +public: // The C++ standard requires only that these
1.180 + // member functions be defined in basic_ios.
1.181 + // We define them in the non-template
1.182 + // base class to avoid code duplication.
1.183 + operator void*() const { return !fail() ? (void*) __CONST_CAST(ios_base*,this) : (void*) 0; }
1.184 + bool operator!() const { return fail(); }
1.185 +
1.186 + iostate rdstate() const { return _M_iostate; }
1.187 +
1.188 + bool good() const { return _M_iostate == 0; }
1.189 + bool eof() const { return (_M_iostate & eofbit) != 0; }
1.190 + bool fail() const { return (_M_iostate & (failbit | badbit)) != 0; }
1.191 + bool bad() const { return (_M_iostate & badbit) != 0; }
1.192 +
1.193 +protected: // The functional protected interface.
1.194 +
1.195 + // Copies the state of __x to *this. This member function makes it
1.196 + // possible to implement basic_ios::copyfmt without having to expose
1.197 + // ios_base's private data members. Does not copy _M_exception_mask
1.198 + // or _M_iostate.
1.199 + _STLP_DECLSPEC void _M_copy_state(const ios_base& __x);
1.200 +
1.201 + void _M_setstate_nothrow(iostate __state) { _M_iostate |= __state; }
1.202 + void _M_clear_nothrow(iostate __state) { _M_iostate = __state; }
1.203 + iostate _M_get_exception_mask() const { return _M_exception_mask; }
1.204 + void _M_set_exception_mask(iostate __mask) { _M_exception_mask = __mask; }
1.205 + void _M_check_exception_mask() {
1.206 + if (_M_iostate & _M_exception_mask)
1.207 + _M_throw_failure();
1.208 + }
1.209 +
1.210 + _STLP_DECLSPEC void _M_invoke_callbacks(event);
1.211 + _STLP_DECLSPEC void _M_throw_failure();
1.212 +
1.213 + _STLP_DECLSPEC ios_base(); // Default constructor.
1.214 +
1.215 +protected: // Initialization of the I/O system
1.216 + static void _STLP_CALL _S_initialize();
1.217 + static void _STLP_CALL _S_uninitialize();
1.218 +# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
1.219 + static bool _S_was_synced;
1.220 +# endif //__LIBSTD_CPP_SYMBIAN32_WSD__
1.221 + friend void CallIosInit();
1.222 +private: // Invalidate the copy constructor and
1.223 + // assignment operator.
1.224 + ios_base(const ios_base&);
1.225 + void operator=(const ios_base&);
1.226 +
1.227 +private: // Data members.
1.228 +
1.229 + fmtflags _M_fmtflags; // Flags
1.230 + iostate _M_iostate;
1.231 + openmode _M_openmode;
1.232 + seekdir _M_seekdir;
1.233 + iostate _M_exception_mask;
1.234 +
1.235 + streamsize _M_precision;
1.236 + streamsize _M_width;
1.237 +
1.238 + locale _M_locale;
1.239 +
1.240 + pair<event_callback, int>* _M_callbacks;
1.241 + size_t _M_num_callbacks; // Size of the callback array.
1.242 + size_t _M_callback_index; // Index of the next available callback;
1.243 + // initially zero.
1.244 +
1.245 + long* _M_iwords; // Auxiliary storage. The count is zero
1.246 + size_t _M_num_iwords; // if and only if the pointer is null.
1.247 +
1.248 + void** _M_pwords;
1.249 + size_t _M_num_pwords;
1.250 +
1.251 +# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
1.252 + static int _S_index;
1.253 +# endif //__LIBSTD_CPP_SYMBIAN32_WSD__
1.254 +
1.255 +
1.256 +protected:
1.257 + // Cached copies of the curent locale's facets. Set by init() and imbue().
1.258 + locale::facet* _M_cached_ctype;
1.259 + locale::facet* _M_cached_numpunct;
1.260 + string _M_cached_grouping;
1.261 +public:
1.262 + // Equivalent to &use_facet< Facet >(getloc()), but faster.
1.263 + const locale::facet* _M_ctype_facet() const { return _M_cached_ctype; }
1.264 + const locale::facet* _M_numpunct_facet() const { return _M_cached_numpunct; }
1.265 + const string& _M_grouping() const { return _M_cached_grouping; }
1.266 +public:
1.267 +
1.268 + // ----------------------------------------------------------------------
1.269 + // Nested initializer class. This is an implementation detail, but it's
1.270 + // prescribed by the standard. The static initializer object (on
1.271 + // implementations where such a thing is required) is declared in
1.272 + // <iostream>
1.273 +
1.274 + class _STLP_CLASS_DECLSPEC Init {
1.275 + public:
1.276 + _STLP_DECLSPEC Init();
1.277 + _STLP_DECLSPEC ~Init();
1.278 + private:
1.279 +# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
1.280 + static long _S_count;
1.281 +# endif //__LIBSTD_CPP_SYMBIAN32_WSD__
1.282 + friend class ios_base;
1.283 + };
1.284 +
1.285 + // this class is needed to ensure locale initialization w/o <iostream> inclusion
1.286 + class _STLP_CLASS_DECLSPEC _Loc_init {
1.287 + public:
1.288 + _STLP_DECLSPEC _Loc_init();
1.289 + _STLP_DECLSPEC ~_Loc_init();
1.290 + private:
1.291 +# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
1.292 + static long _S_count;
1.293 +# endif //__LIBSTD_CPP_SYMBIAN32_WSD__
1.294 + friend class locale;
1.295 + friend class ios_base;
1.296 + };
1.297 +
1.298 + friend class Init;
1.299 +
1.300 +public:
1.301 +# ifndef _STLP_NO_ANACHRONISMS
1.302 + // 31.6 Old iostreams members [depr.ios.members]
1.303 + typedef iostate io_state;
1.304 + typedef openmode open_mode;
1.305 + typedef seekdir seek_dir;
1.306 + typedef _STLP_STD::streamoff streamoff;
1.307 + typedef _STLP_STD::streampos streampos;
1.308 +# endif
1.309 +};
1.310 +
1.311 +inline _STLP_EXP_DECLSPEC locale ios_base::getloc() const
1.312 + {
1.313 + return _M_locale;
1.314 + }
1.315 +
1.316 +// ----------------------------------------------------------------------
1.317 +// ios_base manipulator functions, from section 27.4.5 of the C++ standard.
1.318 +// All of them are trivial one-line wrapper functions.
1.319 +
1.320 +// fmtflag manipulators, section 27.4.5.1
1.321 +inline ios_base& _STLP_CALL boolalpha(ios_base& __s)
1.322 + { __s.setf(ios_base::boolalpha); return __s;}
1.323 +
1.324 +inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
1.325 + { __s.unsetf(ios_base::boolalpha); return __s;}
1.326 +
1.327 +inline ios_base& _STLP_CALL showbase(ios_base& __s)
1.328 + { __s.setf(ios_base::showbase); return __s;}
1.329 +
1.330 +inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
1.331 + { __s.unsetf(ios_base::showbase); return __s;}
1.332 +
1.333 +inline ios_base& _STLP_CALL showpoint(ios_base& __s)
1.334 + { __s.setf(ios_base::showpoint); return __s;}
1.335 +
1.336 +inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
1.337 + { __s.unsetf(ios_base::showpoint); return __s;}
1.338 +
1.339 +inline ios_base& _STLP_CALL showpos(ios_base& __s)
1.340 + { __s.setf(ios_base::showpos); return __s;}
1.341 +
1.342 +inline ios_base& _STLP_CALL noshowpos(ios_base& __s)
1.343 + { __s.unsetf(ios_base::showpos); return __s;}
1.344 +
1.345 +inline ios_base& _STLP_CALL skipws(ios_base& __s)
1.346 + { __s.setf(ios_base::skipws); return __s;}
1.347 +
1.348 +inline ios_base& _STLP_CALL noskipws(ios_base& __s)
1.349 + { __s.unsetf(ios_base::skipws); return __s;}
1.350 +
1.351 +inline ios_base& _STLP_CALL uppercase(ios_base& __s)
1.352 + { __s.setf(ios_base::uppercase); return __s;}
1.353 +
1.354 +inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
1.355 + { __s.unsetf(ios_base::uppercase); return __s;}
1.356 +
1.357 +inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
1.358 + { __s.setf(ios_base::unitbuf); return __s;}
1.359 +
1.360 +inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
1.361 + { __s.unsetf(ios_base::unitbuf); return __s;}
1.362 +
1.363 +
1.364 +// adjustfield manipulators, section 27.4.5.2
1.365 +inline ios_base& _STLP_CALL internal(ios_base& __s)
1.366 + { __s.setf(ios_base::internal, ios_base::adjustfield); return __s; }
1.367 +
1.368 +inline ios_base& _STLP_CALL left(ios_base& __s)
1.369 + { __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
1.370 +
1.371 +inline ios_base& _STLP_CALL right(ios_base& __s)
1.372 + { __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
1.373 +
1.374 +// basefield manipulators, section 27.4.5.3
1.375 +inline ios_base& _STLP_CALL dec(ios_base& __s)
1.376 + { __s.setf(ios_base::dec, ios_base::basefield); return __s; }
1.377 +
1.378 +inline ios_base& _STLP_CALL hex(ios_base& __s)
1.379 + { __s.setf(ios_base::hex, ios_base::basefield); return __s; }
1.380 +
1.381 +inline ios_base& _STLP_CALL oct(ios_base& __s)
1.382 + { __s.setf(ios_base::oct, ios_base::basefield); return __s; }
1.383 +
1.384 +
1.385 +// floatfield manipulators, section 27.4.5.3
1.386 +inline ios_base& _STLP_CALL fixed(ios_base& __s)
1.387 + { __s.setf(ios_base::fixed, ios_base::floatfield); return __s; }
1.388 +
1.389 +inline ios_base& _STLP_CALL scientific(ios_base& __s)
1.390 + { __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
1.391 +
1.392 +#if defined(__BORLANDC__) && defined(_RTLDLL)
1.393 +
1.394 +long ios_base::_Loc_init::_S_count = 0;
1.395 +
1.396 +void _STLP_CALL _Stl_loc_init_num_put();
1.397 +void _STLP_CALL _Stl_loc_init_num_get();
1.398 +void _STLP_CALL _Stl_loc_init_monetary();
1.399 +void _STLP_CALL _Stl_loc_init_time_facets();
1.400 +
1.401 +inline ios_base::_Loc_init::_Loc_init() {
1.402 + if (_S_count++ == 0) {
1.403 + _Stl_loc_init_num_put();
1.404 + _Stl_loc_init_num_get();
1.405 + _Stl_loc_init_monetary();
1.406 + _Stl_loc_init_time_facets();
1.407 + locale::_S_initialize();
1.408 + }
1.409 +}
1.410 +
1.411 +inline ios_base::_Loc_init::~_Loc_init() {
1.412 + if (--_S_count == 0)
1.413 + locale::_S_uninitialize();
1.414 +}
1.415 +
1.416 +#endif /* __BORLANDC__ */
1.417 +
1.418 +#if 0
1.419 +#ifdef __SYMBIAN32__
1.420 +#pragma message("Symbian I/O stream support on progress.")
1.421 +inline ios_base::_Loc_init::_Loc_init() {
1.422 +}
1.423 +
1.424 +inline ios_base::_Loc_init::~_Loc_init() {
1.425 +}
1.426 +#endif
1.427 +
1.428 +inline ios_base::Init::Init() {
1.429 +}
1.430 +
1.431 +inline ios_base::Init::~Init() {
1.432 +}
1.433 +#endif
1.434 +
1.435 +_STLP_END_NAMESPACE
1.436 +
1.437 +#endif /* _STLP_IOS_BASE */
1.438 +
1.439 +// Local Variables:
1.440 +// mode:C++
1.441 +// End:
1.442 +