]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_ios.c
minor doc updates
[polintos/scott/priv.git] / include / c++ / stl / stl / _ios.c
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  *
17  */
18 #ifndef _STLP_IOS_C
19 #define _STLP_IOS_C
20
21 #ifndef _STLP_INTERNAL_IOS_H
22 # include <stl/_ios.h>
23 #endif
24
25 #ifndef _STLP_INTERNAL_STREAMBUF
26 # include <stl/_streambuf.h>
27 #endif
28
29 #ifndef _STLP_INTERNAL_NUMPUNCT_H
30 # include <stl/_numpunct.h>
31 #endif
32
33 _STLP_BEGIN_NAMESPACE
34
35 // basic_ios<>'s non-inline member functions
36
37 // Public constructor, taking a streambuf.
38 template <class _CharT, class _Traits>
39 basic_ios<_CharT, _Traits>
40   ::basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf)
41     : ios_base(),
42       _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0) {
43   basic_ios<_CharT, _Traits>::init(__streambuf);
44 }
45
46 template <class _CharT, class _Traits>
47 basic_streambuf<_CharT, _Traits>*
48 basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __buf) {
49   basic_streambuf<_CharT, _Traits>* __tmp = _M_streambuf;
50   _M_streambuf = __buf;
51   this->clear();
52   return __tmp;
53 }
54
55 template <class _CharT, class _Traits>
56 basic_ios<_CharT, _Traits>&
57 basic_ios<_CharT, _Traits>::copyfmt(const basic_ios<_CharT, _Traits>& __x) {
58   _M_invoke_callbacks(erase_event);
59   _M_copy_state(__x);           // Inherited from ios_base.
60   _M_fill = __x._M_fill;
61   _M_tied_ostream = __x._M_tied_ostream;
62   _M_invoke_callbacks(copyfmt_event);
63   this->_M_set_exception_mask(__x.exceptions());
64   return *this;
65 }
66
67 template <class _CharT, class _Traits>
68 locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) {
69   locale __tmp = ios_base::imbue(__loc);
70   _STLP_TRY {
71     if (_M_streambuf)
72       _M_streambuf->pubimbue(__loc);
73
74     // no throwing here
75     this->_M_cached_ctype = __loc._M_get_facet(ctype<char_type>::id);
76     this->_M_cached_numpunct = __loc._M_get_facet(numpunct<char_type>::id);
77     this->_M_cached_grouping = ((numpunct<char_type>*)_M_cached_numpunct)->grouping();
78   }
79   _STLP_CATCH_ALL {
80     __tmp = ios_base::imbue(__tmp);
81     _M_handle_exception(ios_base::failbit);
82   }
83   return __tmp;
84 }
85
86 // Protected constructor and initialization functions. The default
87 // constructor creates an uninitialized basic_ios, and init() initializes
88 // all of the members to the values in Table 89 of the C++ standard.
89
90 template <class _CharT, class _Traits>
91 basic_ios<_CharT, _Traits>::basic_ios()
92   : ios_base(),
93     _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
94 {}
95
96 template <class _CharT, class _Traits>
97 void
98 basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
99 {
100   this->rdbuf(__sb);
101   this->imbue(locale());
102   this->tie(0);
103   this->_M_set_exception_mask(ios_base::goodbit);
104   this->_M_clear_nothrow(__sb != 0 ? ios_base::goodbit : ios_base::badbit);
105   ios_base::flags(ios_base::skipws | ios_base::dec);
106   ios_base::width(0);
107   ios_base::precision(6);
108   this->fill(widen(' '));
109   // We don't need to worry about any of the three arrays: they are
110   // initialized correctly in ios_base's constructor.
111 }
112
113 // This is never called except from within a catch clause.
114 template <class _CharT, class _Traits>
115 void basic_ios<_CharT, _Traits>::_M_handle_exception(ios_base::iostate __flag)
116 {
117   this->_M_setstate_nothrow(__flag);
118   if (this->_M_get_exception_mask() & __flag)
119     _STLP_RETHROW;
120 }
121
122 _STLP_END_NAMESPACE
123
124 #endif /* _STLP_IOS_C */
125
126 // Local Variables:
127 // mode:C++
128 // End: