epoc32/include/stdapis/stlport/stl/_ios_base.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     3  * Copyright (c) 1999
     4  * Silicon Graphics Computer Systems, Inc.
     5  *
     6  * Copyright (c) 1999 
     7  * Boris Fomitchev
     8  *
     9  * This material is provided "as is", with absolutely no warranty expressed
    10  * or implied. Any use is at your own risk.
    11  *
    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.
    17  *
    18  */ 
    19 #ifndef _STLP_IOS_BASE_H
    20 #define _STLP_IOS_BASE_H
    21 
    22 #ifndef _STLP_STDEXCEPT
    23 #include <stdexcept>
    24 #endif
    25 #ifndef _STLP_UTILITY
    26 #include <utility>
    27 #endif
    28 #ifndef _STLP_INTERNAL_LOCALE_H
    29 #include <stl/_locale.h>
    30 #endif
    31 #ifndef _STLP_STRING_H
    32 # include <stl/_string.h>
    33 #endif
    34 
    35 _STLP_BEGIN_NAMESPACE
    36 
    37 // ----------------------------------------------------------------------
    38 
    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.
    45 
    46 #ifdef __SYMBIAN32__
    47 class ios_base {
    48 #else
    49 class _STLP_CLASS_DECLSPEC ios_base {
    50 #endif
    51 public:
    52   
    53   class _STLP_CLASS_DECLSPEC failure : public __Named_exception {
    54   public:
    55     _STLP_DECLSPEC explicit failure(const string&);
    56     _STLP_DECLSPEC virtual ~failure() _STLP_NOTHROW_INHERENTLY;
    57   };
    58 
    59   typedef int fmtflags;
    60   typedef int iostate;
    61   typedef int openmode;
    62   typedef int seekdir;
    63 
    64 # ifndef _STLP_NO_ANACHRONISMS
    65   typedef fmtflags fmt_flags;
    66 # endif
    67 
    68   // Formatting flags.
    69 # ifdef _STLP_STATIC_CONST_INIT_BUG
    70   enum  {
    71 # else
    72   // boris : type for all those constants is int   
    73   static const int
    74 # endif
    75     left       = 0x0001,
    76     right      = 0x0002,
    77     internal   = 0x0004,
    78     dec        = 0x0008,
    79     hex        = 0x0010,
    80     oct        = 0x0020,
    81     fixed      = 0x0040,
    82     scientific = 0x0080,
    83     boolalpha  = 0x0100,
    84     showbase   = 0x0200,
    85     showpoint  = 0x0400,
    86     showpos    = 0x0800,
    87     skipws     = 0x1000,
    88     unitbuf    = 0x2000,
    89     uppercase  = 0x4000,
    90     adjustfield = left | right | internal,
    91     basefield   = dec | hex | oct,
    92     floatfield  = scientific | fixed,
    93     
    94     // State flags.
    95     goodbit = 0x00,
    96     badbit  = 0x01,
    97     eofbit  = 0x02,
    98     failbit = 0x04,
    99     
   100     // Openmode flags.
   101     __default_mode = 0x0, /* implementation detail */
   102     app    = 0x01,
   103     ate    = 0x02,
   104     binary = 0x04,
   105     in     = 0x08,
   106     out    = 0x10,
   107     trunc  = 0x20,
   108     
   109     // Seekdir flags
   110     
   111     beg = 0x01,
   112     cur = 0x02,
   113     end = 0x04
   114 # ifdef _STLP_STATIC_CONST_INIT_BUG
   115   }
   116 # endif
   117   ;
   118 
   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;
   124     return __tmp;
   125   }
   126 
   127   fmtflags setf(fmtflags __flag) {
   128     fmtflags __tmp = _M_fmtflags;
   129     _M_fmtflags |= __flag;
   130     return __tmp;
   131   }
   132   fmtflags setf(fmtflags __flag, fmtflags __mask) {
   133     fmtflags __tmp = _M_fmtflags;
   134     _M_fmtflags &= ~__mask;
   135     _M_fmtflags |= __flag & __mask;
   136     return __tmp;
   137   }
   138   void unsetf(fmtflags __mask) { _M_fmtflags &= ~__mask; }
   139 
   140   streamsize precision() const { return _M_precision; }
   141   streamsize precision(streamsize __newprecision) {
   142     streamsize __tmp = _M_precision;
   143     _M_precision = __newprecision;
   144     return __tmp;
   145   }
   146 
   147   streamsize width() const { return _M_width; }
   148   streamsize width(streamsize __newwidth) {
   149     streamsize __tmp = _M_width;
   150     _M_width = __newwidth;
   151     return __tmp;
   152   }
   153 
   154 public:                         // Locales
   155   _STLP_DECLSPEC locale imbue(const locale&);
   156   _STLP_DECLSPEC locale getloc() const;// { return _M_locale; }
   157 
   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);
   162 
   163 public:                         // Destructor.
   164   _STLP_DECLSPEC virtual ~ios_base();
   165 
   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);
   170 
   171 public:                         // This member function affects only
   172                                 // the eight predefined ios objects:
   173                                 // cin, cout, etc.
   174   _STLP_DECLSPEC static bool _STLP_CALL sync_with_stdio(bool __sync = true);
   175 
   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(); }
   182 
   183   iostate rdstate() const { return _M_iostate; }
   184 
   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; }
   189 
   190 protected:                      // The functional protected interface.
   191 
   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
   195   // or _M_iostate.
   196   _STLP_DECLSPEC void _M_copy_state(const ios_base& __x);
   197 
   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)
   204       _M_throw_failure(); 
   205   }
   206 
   207   _STLP_DECLSPEC void _M_invoke_callbacks(event);
   208   _STLP_DECLSPEC void _M_throw_failure();
   209 
   210   _STLP_DECLSPEC ios_base();                   // Default constructor.
   211 
   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&);
   223 
   224 private:                        // Data members.
   225 
   226   fmtflags _M_fmtflags;         // Flags
   227   iostate _M_iostate;
   228   openmode _M_openmode;
   229   seekdir _M_seekdir;
   230   iostate _M_exception_mask;
   231 
   232   streamsize _M_precision;
   233   streamsize _M_width;
   234 
   235   locale _M_locale;
   236 
   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;
   240                                 // initially zero.
   241 
   242   long* _M_iwords;              // Auxiliary storage.  The count is zero
   243   size_t _M_num_iwords;         // if and only if the pointer is null.
   244 
   245   void** _M_pwords;
   246   size_t _M_num_pwords;
   247 
   248 # if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
   249 	static int _S_index;
   250 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
   251 
   252 
   253 protected:
   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;
   258 public:
   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; }
   263 public:
   264 
   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
   269   // <iostream>
   270   
   271   class _STLP_CLASS_DECLSPEC Init {
   272   public:
   273     _STLP_DECLSPEC Init();
   274     _STLP_DECLSPEC ~Init();
   275   private:
   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;
   280   };
   281 
   282   // this class is needed to ensure locale initialization w/o <iostream> inclusion
   283   class _STLP_CLASS_DECLSPEC _Loc_init {
   284   public:
   285     _STLP_DECLSPEC _Loc_init();
   286     _STLP_DECLSPEC ~_Loc_init();
   287   private:
   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__
   291     friend class locale;
   292     friend class ios_base;
   293   };
   294 
   295   friend class Init;
   296 
   297 public:
   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;
   305 # endif  
   306 };
   307 
   308 inline _STLP_EXP_DECLSPEC locale ios_base::getloc() const 
   309     { 
   310     return _M_locale; 
   311     }
   312 
   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.
   316 
   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;}
   320 
   321 inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
   322   { __s.unsetf(ios_base::boolalpha); return __s;}
   323 
   324 inline ios_base& _STLP_CALL showbase(ios_base& __s)
   325   { __s.setf(ios_base::showbase); return __s;}
   326 
   327 inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
   328   { __s.unsetf(ios_base::showbase); return __s;}
   329 
   330 inline ios_base& _STLP_CALL showpoint(ios_base& __s)
   331   { __s.setf(ios_base::showpoint); return __s;}
   332 
   333 inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
   334   { __s.unsetf(ios_base::showpoint); return __s;}
   335 
   336 inline ios_base& _STLP_CALL showpos(ios_base& __s)
   337   { __s.setf(ios_base::showpos); return __s;}
   338 
   339 inline ios_base& _STLP_CALL noshowpos(ios_base& __s) 
   340   { __s.unsetf(ios_base::showpos); return __s;}
   341 
   342 inline ios_base& _STLP_CALL skipws(ios_base& __s)
   343   { __s.setf(ios_base::skipws); return __s;}
   344 
   345 inline ios_base& _STLP_CALL noskipws(ios_base& __s)
   346   { __s.unsetf(ios_base::skipws); return __s;}
   347 
   348 inline ios_base& _STLP_CALL uppercase(ios_base& __s)
   349   { __s.setf(ios_base::uppercase); return __s;}
   350 
   351 inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
   352   { __s.unsetf(ios_base::uppercase); return __s;}
   353 
   354 inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
   355   { __s.setf(ios_base::unitbuf); return __s;}
   356 
   357 inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
   358   { __s.unsetf(ios_base::unitbuf); return __s;}
   359 
   360 
   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; }
   364 
   365 inline ios_base& _STLP_CALL left(ios_base& __s)
   366   { __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
   367 
   368 inline ios_base& _STLP_CALL right(ios_base& __s)
   369   { __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
   370 
   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; }
   374 
   375 inline ios_base& _STLP_CALL hex(ios_base& __s) 
   376   { __s.setf(ios_base::hex, ios_base::basefield); return __s; }
   377 
   378 inline ios_base& _STLP_CALL oct(ios_base& __s)
   379   { __s.setf(ios_base::oct, ios_base::basefield); return __s; }
   380 
   381 
   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; }
   385 
   386 inline ios_base& _STLP_CALL scientific(ios_base& __s)
   387   { __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
   388 
   389 #if defined(__BORLANDC__) && defined(_RTLDLL)
   390 
   391 long ios_base::_Loc_init::_S_count = 0;
   392 
   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();
   397 
   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();
   405   }
   406 }
   407 
   408 inline ios_base::_Loc_init::~_Loc_init() {
   409     if (--_S_count == 0)
   410       locale::_S_uninitialize();
   411 }
   412 
   413 #endif /* __BORLANDC__ */
   414 
   415 #if 0
   416 #ifdef __SYMBIAN32__
   417 #pragma message("Symbian I/O stream support on progress.")
   418 inline ios_base::_Loc_init::_Loc_init() {
   419 }
   420 
   421 inline ios_base::_Loc_init::~_Loc_init() {
   422 }
   423 #endif
   424 
   425 inline ios_base::Init::Init() {
   426 }
   427 
   428 inline ios_base::Init::~Init() {
   429 }
   430 #endif
   431 
   432 _STLP_END_NAMESPACE
   433 
   434 #endif /* _STLP_IOS_BASE */
   435 
   436 // Local Variables:
   437 // mode:C++
   438 // End:
   439