epoc32/include/stdapis/stlportv5/stl/_ios_base.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
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) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3  *
     4  * Copyright (c) 1999
     5  * Silicon Graphics Computer Systems, Inc.
     6  *
     7  * Copyright (c) 1999
     8  * Boris Fomitchev
     9  *
    10  * This material is provided "as is", with absolutely no warranty expressed
    11  * or implied. Any use is at your own risk.
    12  *
    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.
    18  *
    19  */
    20 #ifndef _STLP_IOS_BASE_H
    21 #define _STLP_IOS_BASE_H
    22 
    23 #ifndef _STLP_INTERNAL_STDEXCEPT_BASE
    24 #  include <stl/_stdexcept_base.h>
    25 #endif
    26 
    27 #ifndef _STLP_UTILITY
    28 #  include <utility>
    29 #endif
    30 
    31 #ifndef _STLP_INTERNAL_LOCALE_H
    32 #  include <stl/_locale.h>
    33 #endif
    34 
    35 #ifndef _STLP_INTERNAL_STRING_H
    36 #  include <stl/_string.h>
    37 #endif
    38 
    39 _STLP_BEGIN_NAMESPACE
    40 
    41 // ----------------------------------------------------------------------
    42 
    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.
    49 
    50 class _STLP_CLASS_DECLSPEC ios_base {
    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 #if defined (_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   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 _STLP_FUNCTION_THROWS _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(__SYMBIAN32__WSD__)
   216 public:
   217   static void ios_base_S_was_synced_init()
   218   {
   219      get_ios_base_S_was_synced() = true;	
   220   }
   221 protected:
   222   static inline bool& get_ios_base_S_was_synced();
   223 #else
   224   static bool _S_was_synced;
   225 # endif //__SYMBIAN32__WSD__
   226 
   227   
   228 private:                        // Invalidate the copy constructor and
   229                                 // assignment operator.
   230   ios_base(const ios_base&);
   231   void operator=(const ios_base&);
   232 
   233 private:                        // Data members.
   234 
   235   fmtflags _M_fmtflags;         // Flags
   236   iostate _M_iostate;
   237   openmode _M_openmode;
   238   seekdir _M_seekdir;
   239   iostate _M_exception_mask;
   240 
   241   streamsize _M_precision;
   242   streamsize _M_width;
   243 
   244   locale _M_locale;
   245 
   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;
   249                                 // initially zero.
   250 
   251   long* _M_iwords;              // Auxiliary storage.  The count is zero
   252   size_t _M_num_iwords;         // if and only if the pointer is null.
   253 
   254   void** _M_pwords;
   255   size_t _M_num_pwords;
   256 
   257 protected:
   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;
   262 public:
   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; }
   267 public:
   268 
   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
   273   // <iostream>
   274 
   275   class _STLP_CLASS_DECLSPEC Init
   276   {
   277     public:
   278       _STLP_DECLSPEC Init();
   279       _STLP_DECLSPEC ~Init();
   280 # if defined(__SYMBIAN32__WSD__)
   281       static inline void ios_base_Init_S_count_init() 
   282       {
   283       	get_ios_base_Init_S_count() = 0;
   284       }
   285     private:
   286       static inline long& get_ios_base_Init_S_count();      
   287 #else	
   288     private:  
   289       static long _S_count;
   290 # endif //__SYMBIAN32__WSD__     
   291       friend class ios_base;
   292   };
   293 
   294   friend class Init;
   295 
   296 public:
   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;
   304 # endif
   305 };
   306 
   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.
   310 
   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;}
   314 
   315 inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
   316   { __s.unsetf(ios_base::boolalpha); return __s;}
   317 
   318 inline ios_base& _STLP_CALL showbase(ios_base& __s)
   319   { __s.setf(ios_base::showbase); return __s;}
   320 
   321 inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
   322   { __s.unsetf(ios_base::showbase); return __s;}
   323 
   324 inline ios_base& _STLP_CALL showpoint(ios_base& __s)
   325   { __s.setf(ios_base::showpoint); return __s;}
   326 
   327 inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
   328   { __s.unsetf(ios_base::showpoint); return __s;}
   329 
   330 inline ios_base& _STLP_CALL showpos(ios_base& __s)
   331   { __s.setf(ios_base::showpos); return __s;}
   332 
   333 inline ios_base& _STLP_CALL noshowpos(ios_base& __s)
   334   { __s.unsetf(ios_base::showpos); return __s;}
   335 
   336 inline ios_base& _STLP_CALL skipws(ios_base& __s)
   337   { __s.setf(ios_base::skipws); return __s;}
   338 
   339 inline ios_base& _STLP_CALL noskipws(ios_base& __s)
   340   { __s.unsetf(ios_base::skipws); return __s;}
   341 
   342 inline ios_base& _STLP_CALL uppercase(ios_base& __s)
   343   { __s.setf(ios_base::uppercase); return __s;}
   344 
   345 inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
   346   { __s.unsetf(ios_base::uppercase); return __s;}
   347 
   348 inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
   349   { __s.setf(ios_base::unitbuf); return __s;}
   350 
   351 inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
   352   { __s.unsetf(ios_base::unitbuf); return __s;}
   353 
   354 
   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; }
   358 
   359 inline ios_base& _STLP_CALL left(ios_base& __s)
   360   { __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
   361 
   362 inline ios_base& _STLP_CALL right(ios_base& __s)
   363   { __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
   364 
   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; }
   368 
   369 inline ios_base& _STLP_CALL hex(ios_base& __s)
   370   { __s.setf(ios_base::hex, ios_base::basefield); return __s; }
   371 
   372 inline ios_base& _STLP_CALL oct(ios_base& __s)
   373   { __s.setf(ios_base::oct, ios_base::basefield); return __s; }
   374 
   375 
   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; }
   379 
   380 inline ios_base& _STLP_CALL scientific(ios_base& __s)
   381   { __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
   382 
   383 _STLP_END_NAMESPACE
   384 
   385 #endif /* _STLP_IOS_BASE */
   386 
   387 // Local Variables:
   388 // mode:C++
   389 // End:
   390