epoc32/include/stdapis/stlportv5/stl/_ios.c
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_C
    21 #define _STLP_IOS_C
    22 
    23 #ifndef _STLP_INTERNAL_IOS_H
    24 # include <stl/_ios.h>
    25 #endif
    26 
    27 #ifndef _STLP_INTERNAL_STREAMBUF
    28 # include <stl/_streambuf.h>
    29 #endif
    30 
    31 #ifndef _STLP_INTERNAL_NUMPUNCT_H
    32 # include <stl/_numpunct.h>
    33 #endif
    34 
    35 _STLP_BEGIN_NAMESPACE
    36 
    37 // basic_ios<>'s non-inline member functions
    38 
    39 // Public constructor, taking a streambuf.
    40 template <class _CharT, class _Traits>
    41 basic_ios<_CharT, _Traits>
    42   ::basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf)
    43     : ios_base(),
    44       _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0) {
    45   basic_ios<_CharT, _Traits>::init(__streambuf);
    46 }
    47 
    48 template <class _CharT, class _Traits>
    49 basic_streambuf<_CharT, _Traits>*
    50 basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __buf) {
    51   basic_streambuf<_CharT, _Traits>* __tmp = _M_streambuf;
    52   _M_streambuf = __buf;
    53   this->clear();
    54   return __tmp;
    55 }
    56 
    57 template <class _CharT, class _Traits>
    58 basic_ios<_CharT, _Traits>&
    59 basic_ios<_CharT, _Traits>::copyfmt(const basic_ios<_CharT, _Traits>& __x) {
    60   _M_invoke_callbacks(erase_event);
    61   _M_copy_state(__x);           // Inherited from ios_base.
    62   _M_fill = __x._M_fill;
    63   _M_tied_ostream = __x._M_tied_ostream;
    64   _M_invoke_callbacks(copyfmt_event);
    65   this->_M_set_exception_mask(__x.exceptions());
    66   return *this;
    67 }
    68 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__) 
    69 #define id GetFacetLocaleId()
    70 #endif    
    71 
    72 template <class _CharT, class _Traits>
    73 locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) {
    74   locale __tmp = ios_base::imbue(__loc);
    75   _STLP_TRY {
    76     if (_M_streambuf)
    77       _M_streambuf->pubimbue(__loc);
    78 
    79     // no throwing here
    80     this->_M_cached_ctype = __loc._M_get_facet(ctype<char_type>::id);
    81     this->_M_cached_numpunct = __loc._M_get_facet(numpunct<char_type>::id);
    82     this->_M_cached_grouping = ((numpunct<char_type>*)_M_cached_numpunct)->grouping();
    83   }
    84   _STLP_CATCH_ALL {
    85     __tmp = ios_base::imbue(__tmp);
    86     _M_handle_exception(ios_base::failbit);
    87   }
    88   return __tmp;
    89 }
    90 #if defined(__SYMBIAN32__WSD__) || defined (__SYMBIAN32__NO_STATIC_IMPORTS__) 
    91 #undef id 
    92 #endif    
    93 
    94 
    95 // Protected constructor and initialization functions. The default
    96 // constructor creates an uninitialized basic_ios, and init() initializes
    97 // all of the members to the values in Table 89 of the C++ standard.
    98 
    99 template <class _CharT, class _Traits>
   100 basic_ios<_CharT, _Traits>::basic_ios()
   101   : ios_base(),
   102     _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
   103 {}
   104 
   105 template <class _CharT, class _Traits>
   106 void
   107 basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
   108 {
   109   this->rdbuf(__sb);
   110   this->imbue(locale());
   111   this->tie(0);
   112   this->_M_set_exception_mask(ios_base::goodbit);
   113   /*
   114     this->_M_clear_nothrow(__sb != 0 ? ios_base::goodbit : ios_base::badbit);
   115 	
   116   The ternary expression above, throws an undefined reference link error (for goodbit and badbit)
   117   when compiled with GCCE 4.3.2. Replacing ternary statement with an if-else block fixes this.
   118   */
   119   if(__sb != 0) {
   120 	this->_M_clear_nothrow(ios_base::goodbit);
   121   } else {
   122 	this->_M_clear_nothrow(ios_base::badbit);
   123   }
   124   ios_base::flags(ios_base::skipws | ios_base::dec);
   125   ios_base::width(0);
   126   ios_base::precision(6);
   127   this->fill(widen(' '));
   128   // We don't need to worry about any of the three arrays: they are
   129   // initialized correctly in ios_base's constructor.
   130 }
   131 
   132 // This is never called except from within a catch clause.
   133 template <class _CharT, class _Traits>
   134 void basic_ios<_CharT, _Traits>::_M_handle_exception(ios_base::iostate __flag)
   135 {
   136   this->_M_setstate_nothrow(__flag);
   137   if (this->_M_get_exception_mask() & __flag)
   138     _STLP_RETHROW;
   139 }
   140 
   141 _STLP_END_NAMESPACE
   142 
   143 #endif /* _STLP_IOS_C */
   144 
   145 // Local Variables:
   146 // mode:C++
   147 // End: