/home/ntakagi/work/STLport-5.1.5/stlport/stl/_ios.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 #ifndef _STLP_IOS_C
00019 #define _STLP_IOS_C
00020 
00021 #ifndef _STLP_INTERNAL_IOS_H
00022 # include <stl/_ios.h>
00023 #endif
00024 
00025 #ifndef _STLP_INTERNAL_STREAMBUF
00026 # include <stl/_streambuf.h>
00027 #endif
00028 
00029 #ifndef _STLP_INTERNAL_NUMPUNCT_H
00030 # include <stl/_numpunct.h>
00031 #endif
00032 
00033 _STLP_BEGIN_NAMESPACE
00034 
00035 // basic_ios<>'s non-inline member functions
00036 
00037 // Public constructor, taking a streambuf.
00038 template <class _CharT, class _Traits>
00039 basic_ios<_CharT, _Traits>
00040   ::basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf)
00041     : ios_base(),
00042       _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0) {
00043   basic_ios<_CharT, _Traits>::init(__streambuf);
00044 }
00045 
00046 template <class _CharT, class _Traits>
00047 basic_streambuf<_CharT, _Traits>*
00048 basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __buf) {
00049   basic_streambuf<_CharT, _Traits>* __tmp = _M_streambuf;
00050   _M_streambuf = __buf;
00051   this->clear();
00052   return __tmp;
00053 }
00054 
00055 template <class _CharT, class _Traits>
00056 basic_ios<_CharT, _Traits>&
00057 basic_ios<_CharT, _Traits>::copyfmt(const basic_ios<_CharT, _Traits>& __x) {
00058   _M_invoke_callbacks(erase_event);
00059   _M_copy_state(__x);           // Inherited from ios_base.
00060   _M_fill = __x._M_fill;
00061   _M_tied_ostream = __x._M_tied_ostream;
00062   _M_invoke_callbacks(copyfmt_event);
00063   this->_M_set_exception_mask(__x.exceptions());
00064   return *this;
00065 }
00066 
00067 template <class _CharT, class _Traits>
00068 locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) {
00069   locale __tmp = ios_base::imbue(__loc);
00070   _STLP_TRY {
00071     if (_M_streambuf)
00072       _M_streambuf->pubimbue(__loc);
00073 
00074     // no throwing here
00075     this->_M_cached_ctype = __loc._M_get_facet(ctype<char_type>::id);
00076     this->_M_cached_numpunct = __loc._M_get_facet(numpunct<char_type>::id);
00077     this->_M_cached_grouping = ((numpunct<char_type>*)_M_cached_numpunct)->grouping();
00078   }
00079   _STLP_CATCH_ALL {
00080     __tmp = ios_base::imbue(__tmp);
00081     _M_handle_exception(ios_base::failbit);
00082   }
00083   return __tmp;
00084 }
00085 
00086 // Protected constructor and initialization functions. The default
00087 // constructor creates an uninitialized basic_ios, and init() initializes
00088 // all of the members to the values in Table 89 of the C++ standard.
00089 
00090 template <class _CharT, class _Traits>
00091 basic_ios<_CharT, _Traits>::basic_ios()
00092   : ios_base(),
00093     _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
00094 {}
00095 
00096 template <class _CharT, class _Traits>
00097 void
00098 basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
00099 {
00100   this->rdbuf(__sb);
00101   this->imbue(locale());
00102   this->tie(0);
00103   this->_M_set_exception_mask(ios_base::goodbit);
00104   this->_M_clear_nothrow(__sb != 0 ? ios_base::goodbit : ios_base::badbit);
00105   ios_base::flags(ios_base::skipws | ios_base::dec);
00106   ios_base::width(0);
00107   ios_base::precision(6);
00108   this->fill(widen(' '));
00109   // We don't need to worry about any of the three arrays: they are
00110   // initialized correctly in ios_base's constructor.
00111 }
00112 
00113 // This is never called except from within a catch clause.
00114 template <class _CharT, class _Traits>
00115 void basic_ios<_CharT, _Traits>::_M_handle_exception(ios_base::iostate __flag)
00116 {
00117   this->_M_setstate_nothrow(__flag);
00118   if (this->_M_get_exception_mask() & __flag)
00119     _STLP_RETHROW;
00120 }
00121 
00122 _STLP_END_NAMESPACE
00123 
00124 #endif /* _STLP_IOS_C */
00125 
00126 // Local Variables:
00127 // mode:C++
00128 // End:



Generated on Mon Mar 10 15:32:25 2008 by  doxygen 1.5.1