Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
ostream.cc
Go to the documentation of this file.
1
31
32
33template<class _CharT, class _Traits>
34basic_ostream<_CharT, _Traits>&
35basic_ostream<_CharT, _Traits>::flush ()
36{
37 if (this->rdbuf ()) {
38
39 // see LWG issue 581
40
41 const sentry __opfx (*this);
42
43 if (__opfx) {
44
45 int __res = 0;
46
47 _TRY {
48 __res = this->rdbuf ()->pubsync ();
49 }
50 _CATCH (...) {
51 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
52 }
53
54 if (-1 == __res)
55 this->setstate (ios_base::badbit);
56 }
57 }
58
59 return *this;
60}
61
62
63template<class _CharT, class _Traits>
64basic_ostream<_CharT, _Traits>&
65basic_ostream<_CharT, _Traits>::seekp (pos_type __pos)
66{
67 _RWSTD_ASSERT (0 != this->rdbuf ());
68
69 if (!this->fail ()) {
70 _RWSTD_MT_GUARD (this->_C_bufmutex ());
71
72 pos_type __res = 0;
73
74 _TRY {
75 __res = this->rdbuf ()->pubseekpos (__pos, ios_base::out);
76 }
77 _CATCH (...) {
78 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
79 }
80 if (-1 == __res)
81 this->setstate (ios_base::failbit); // lwg issue 129
82 }
83
84 return *this;
85}
86
87
88template<class _CharT, class _Traits>
89basic_ostream<_CharT, _Traits>&
90basic_ostream<_CharT, _Traits>::seekp (off_type __off, ios_base::seekdir __dir)
91{
92 _RWSTD_ASSERT (0 != this->rdbuf ());
93
94 if (!this->fail ()) {
95 _RWSTD_MT_GUARD (this->_C_bufmutex ());
96
97 off_type __res = 0;
98
99 _TRY {
100 __res = this->rdbuf()->pubseekoff (__off, __dir, ios_base::out);
101 }
102 _CATCH (...) {
103 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
104 }
105
106 if (-1 == __res)
107 this->setstate (ios_base::failbit); // lwg issue 129
108 }
109
110 return *this;
111}
112
113
114template<class _CharT, class _Traits>
115typename basic_ostream<_CharT, _Traits>::pos_type
116basic_ostream<_CharT, _Traits>::tellp ()
117{
118 _RWSTD_ASSERT (0 != this->rdbuf ());
119
120 if (!this->fail ()) {
121 _RWSTD_MT_GUARD (this->_C_bufmutex ());
122
123 _TRY {
124 return this->rdbuf()->pubseekoff (0, ios_base::cur, ios_base::out);
125 }
126 _CATCH (...) {
127 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
128 }
129 }
130
131 return pos_type (off_type (-1));
132}
133
134
135template<class _CharT, class _Traits>
136basic_ostream<_CharT, _Traits>&
137basic_ostream<_CharT, _Traits>::
138operator<< (basic_streambuf<char_type, traits_type> *__sb)
139{
140 if (!__sb) {
141 this->setstate (ios_base::badbit);
142 return *this;
143 }
144
145 ios_base::iostate __err = ios_base::goodbit;
146
147 streamsize __nget = 0; // number of extracted characters
148
149 if (__sb->_C_mode () & ios_base::in) {
150
151 const sentry __opfx (*this);
152
153 _TRY {
154
155 if (__opfx) {
156
157 basic_streambuf<char_type, traits_type>* const __rdbuf =
158 this->rdbuf ();
159
160 for (const int_type __eof = traits_type::eof (); ; ++__nget) {
161
162 // determine the amount of available space in our buffer
163 // into which it is safe (i.e., w/o calling overridden
164 // virtuals on the buffer object or risking exceptions)
165 // to copy the contents of the source stream buffer
166 const streamsize __navail =
167 streamsize (__rdbuf->epptr () - __rdbuf->pptr ());
168
169 if (__navail > 1) {
170 // copy 2 or more characters directly into buffer
171 const streamsize __n =
172 __sb->sgetn (__rdbuf->pptr (), __navail);
173
174 if (__n < 0) {
175 __err = ios_base::failbit;
176 break;
177 }
178
179 if (!__n)
180 break;
181
182 __rdbuf->pbump (__n);
183
184 __nget += __n;
185 }
186 else {
187 // if space for less than 2 characters is available
188 // try to retrieve and insert a single character
189 int_type __c = __sb->sgetc ();
190
191 // 27.6.2.5.3, p7, bullet 1
192 if (traits_type::eq_int_type (__eof, __c))
193 break;
194
195 __c = __rdbuf->sputc (traits_type::to_char_type(__c));
196
197 if (traits_type::eq_int_type (__eof, __c)) {
198 __err = ios_base::failbit;
199 break;
200 }
201
202 // 27.6.2.5.3, p7, bullet 2: extract character
203 // only if it has been successfully inserted
204 __sb->snextc ();
205 }
206 }
207 }
208 }
209 _CATCH (...) {
210 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
211 }
212 }
213 // 27.6.2.5.3.8
214 if (!__nget)
215 __err |= ios_base::failbit;
216
217 if (__err)
218 this->setstate (__err);
219
220 return *this;
221}
222
223
224#ifdef _RWSTD_NO_UNDEFINED_TEMPLATES
225
226template <class _CharT, class _Traits>
227basic_ostream<_CharT, _Traits>::sentry::
228sentry (const sentry &__rhs)
229 : _RW::__rw_guard (0),
230 _C_strm (__rhs._C_strm)
231{
232 _RWSTD_ASSERT (!"not callable");
233}
234
235template <class _CharT, class _Traits>
236void
237basic_ostream<_CharT, _Traits>::sentry::
238operator= (const sentry&)
239{
240 _RWSTD_ASSERT (!"not callable");
241}
242
243#endif // _RWSTD_NO_UNDEFINED_TEMPLATES
244
245} // namespace std
int fail
#define _TRY
Definition _defs.h:850
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_MT_GUARD(ignore)
Definition _defs.h:695
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
#define _CATCH(ex)
Definition _defs.h:851
Definition json.h:5363