1 : // ostream standard header
2 : #pragma once
3 : #ifndef _OSTREAM_
4 : #define _OSTREAM_
5 : #ifndef RC_INVOKED
6 : #include <ios>
7 :
8 : #ifdef _MSC_VER
9 : #pragma pack(push,_CRT_PACKING)
10 : #pragma warning(push,3)
11 : #pragma warning(disable: 4390)
12 : #endif /* _MSC_VER */
13 :
14 : _STD_BEGIN
15 :
16 : // I/O EXCEPTION MACROS
17 :
18 : #if _HAS_EXCEPTIONS
19 : #define _TRY_IO_BEGIN _TRY_BEGIN /* begin try block */
20 :
21 : #define _CATCH_IO_END _CATCH_ALL /* catch block for _Myios */ \
22 : _Myios::setstate(ios_base::badbit, true); /* set badbit and rethrow */ \
23 : _CATCH_END
24 :
25 : #define _CATCH_IO_(x) _CATCH_ALL /* catch block for basic_ios x */ \
26 : (x).setstate(ios_base::badbit, true); /* set badbit and rethrow */ \
27 : _CATCH_END
28 :
29 : #else /* _HAS_EXCEPTIONS */
30 : #define _TRY_IO_BEGIN { /* begin try block */
31 :
32 : #define _CATCH_IO_END } /* catch block for _Myios */
33 :
34 : #define _CATCH_IO_(x) } /* catch block for basic_ios x */
35 : #endif /* _HAS_EXCEPTIONS */
36 :
37 : // TEMPLATE CLASS basic_ostream
38 : template<class _Elem,
39 : class _Traits>
40 : class basic_ostream
41 : : virtual public basic_ios<_Elem, _Traits>
42 : { // control insertions into a stream buffer
43 : public:
44 : typedef basic_ostream<_Elem, _Traits> _Myt;
45 : typedef basic_ios<_Elem, _Traits> _Myios;
46 : typedef basic_streambuf<_Elem, _Traits> _Mysb;
47 : typedef ostreambuf_iterator<_Elem, _Traits> _Iter;
48 : typedef num_put<_Elem, _Iter> _Nput;
49 :
50 : explicit __CLR_OR_THIS_CALL basic_ostream(basic_streambuf<_Elem, _Traits> *_Strbuf,
51 : bool _Isstd = false)
52 : { // construct from a stream buffer pointer
53 : _Myios::init(_Strbuf, _Isstd);
54 : }
55 :
56 10 : __CLR_OR_THIS_CALL basic_ostream(_Uninitialized, bool _Addit = true)
57 : { // construct uninitialized
58 10 : if (_Addit)
59 0 : ios_base::_Addstd(this); // suppress for basic_iostream
60 10 : }
61 :
62 : virtual __CLR_OR_THIS_CALL ~basic_ostream()
63 10 : { // destroy the object
64 10 : }
65 :
66 : typedef typename _Traits::int_type int_type;
67 : typedef typename _Traits::pos_type pos_type;
68 : typedef typename _Traits::off_type off_type;
69 :
70 : class _Sentry_base
71 : { // stores thread lock and reference to output stream
72 : public:
73 : __CLR_OR_THIS_CALL _Sentry_base(_Myt& _Ostr)
74 : : _Myostr(_Ostr)
75 10 : { // lock the stream buffer, if there
76 10 : if (_Myostr.rdbuf() != 0)
77 10 : _Myostr.rdbuf()->_Lock();
78 10 : }
79 :
80 : __CLR_OR_THIS_CALL ~_Sentry_base()
81 10 : { // destroy after unlocking
82 10 : if (_Myostr.rdbuf() != 0)
83 10 : _Myostr.rdbuf()->_Unlock();
84 10 : }
85 :
86 : _Myt& _Myostr; // the output stream, for _Unlock call at destruction
87 : };
88 :
89 : class sentry
90 : : public _Sentry_base
91 : { // stores thread lock and state of stream
92 : public:
93 : explicit __CLR_OR_THIS_CALL sentry(_Myt& _Ostr)
94 : : _Sentry_base(_Ostr)
95 10 : { // construct locking and testing stream
96 10 : if (_Ostr.good() && _Ostr.tie() != 0)
97 0 : _Ostr.tie()->flush();
98 10 : _Ok = _Ostr.good(); // store test only after flushing tie
99 10 : }
100 :
101 : __CLR_OR_THIS_CALL ~sentry()
102 10 : { // destroy the object
103 :
104 : #if _HAS_EXCEPTIONS
105 10 : if (!_XSTD uncaught_exception())
106 10 : this->_Myostr._Osfx();
107 10 : }
108 :
109 : #else /* _HAS_EXCEPTIONS */
110 : this->_Myostr._Osfx();
111 : }
112 : #endif /* _HAS_EXCEPTIONS */
113 :
114 : __CLR_OR_THIS_CALL operator bool() const
115 10 : { // test if stream state okay
116 10 : return (_Ok);
117 10 : }
118 :
119 : private:
120 : __CLR_OR_THIS_CALL sentry(const sentry&); // not defined
121 : sentry& __CLR_OR_THIS_CALL operator=(const sentry&); // not defined
122 :
123 : bool _Ok; // true if stream state okay at construction
124 : };
125 :
126 : bool __CLR_OR_THIS_CALL opfx()
127 : { // test stream state and flush tie stream as needed (retained)
128 : if (ios_base::good() && _Myios::tie() != 0)
129 : _Myios::tie()->flush();
130 : return (ios_base::good());
131 : }
132 :
133 : void __CLR_OR_THIS_CALL osfx()
134 : { // perform any wrapup (retained)
135 : _Osfx();
136 : }
137 :
138 : void __CLR_OR_THIS_CALL _Osfx()
139 10 : { // perform any wrapup
140 10 : _TRY_BEGIN
141 10 : if (ios_base::flags() & ios_base::unitbuf)
142 10 : flush(); // flush stream as needed
143 : _CATCH_ALL
144 0 : _CATCH_END
145 10 : }
146 :
147 : #ifdef _M_CEE_PURE
148 : _Myt& __CLR_OR_THIS_CALL operator<<(_Myt& (__clrcall *_Pfn)(_Myt&))
149 : { // call basic_ostream manipulator
150 : _DEBUG_POINTER(_Pfn);
151 : return ((*_Pfn)(*this));
152 : }
153 :
154 : _Myt& __CLR_OR_THIS_CALL operator<<(_Myios& (__clrcall *_Pfn)(_Myios&))
155 : { // call basic_ios manipulator
156 : _DEBUG_POINTER(_Pfn);
157 : (*_Pfn)(*(_Myios *)this);
158 : return (*this);
159 : }
160 :
161 : _Myt& __CLR_OR_THIS_CALL operator<<(ios_base& (__clrcall *_Pfn)(ios_base&))
162 : { // call ios_base manipulator
163 : _DEBUG_POINTER(_Pfn);
164 : (*_Pfn)(*(ios_base *)this);
165 : return (*this);
166 : }
167 :
168 : #endif
169 :
170 : _Myt& __CLR_OR_THIS_CALL operator<<(_Myt& (__cdecl *_Pfn)(_Myt&))
171 0 : { // call basic_ostream manipulator
172 0 : _DEBUG_POINTER(_Pfn);
173 0 : return ((*_Pfn)(*this));
174 0 : }
175 :
176 : _Myt& __CLR_OR_THIS_CALL operator<<(_Myios& (__cdecl *_Pfn)(_Myios&))
177 : { // call basic_ios manipulator
178 : _DEBUG_POINTER(_Pfn);
179 : (*_Pfn)(*(_Myios *)this);
180 : return (*this);
181 : }
182 :
183 : _Myt& __CLR_OR_THIS_CALL operator<<(ios_base& (__cdecl *_Pfn)(ios_base&))
184 0 : { // call ios_base manipulator
185 0 : _DEBUG_POINTER(_Pfn);
186 0 : (*_Pfn)(*(ios_base *)this);
187 0 : return (*this);
188 0 : }
189 :
190 : _Myt& __CLR_OR_THIS_CALL operator<<(_Bool _Val)
191 : { // insert a boolean
192 : ios_base::iostate _State = ios_base::goodbit;
193 : const sentry _Ok(*this);
194 :
195 : if (_Ok)
196 : { // state okay, use facet to insert
197 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
198 :
199 : _TRY_IO_BEGIN
200 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
201 : _Myios::fill(), _Val).failed())
202 : _State |= ios_base::badbit;
203 : _CATCH_IO_END
204 : }
205 :
206 : _Myios::setstate(_State);
207 : return (*this);
208 : }
209 :
210 : _Myt& __CLR_OR_THIS_CALL operator<<(short _Val)
211 : { // insert a short
212 : ios_base::iostate _State = ios_base::goodbit;
213 : const sentry _Ok(*this);
214 :
215 : if (_Ok)
216 : { // state okay, use facet to insert
217 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
218 : ios_base::fmtflags _Bfl =
219 : ios_base::flags() & ios_base::basefield;
220 : long _Tmp = (_Bfl == ios_base::oct
221 : || _Bfl == ios_base::hex)
222 : ? (long)(unsigned short)_Val : (long)_Val;
223 :
224 : _TRY_IO_BEGIN
225 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
226 : _Myios::fill(), _Tmp).failed())
227 : _State |= ios_base::badbit;
228 : _CATCH_IO_END
229 : }
230 :
231 : _Myios::setstate(_State);
232 : return (*this);
233 : }
234 :
235 : /* Note that if your stream is wchar_t, and you are not using native wchar_t
236 : Then this operation will be unavailable as there is an explicit
237 : specialisation further down this file that is designed to treat an
238 : unsigned short as a character.
239 :
240 : If you wish to read or write unsigned shorts to wchar_t streams, you should
241 : consider making wchar_t a native type by turning on /Zc:wchar_t
242 : */
243 : _Myt& __CLR_OR_THIS_CALL operator<<(unsigned short _Val)
244 0 : { // insert an unsigned short
245 0 : ios_base::iostate _State = ios_base::goodbit;
246 0 : const sentry _Ok(*this);
247 :
248 0 : if (_Ok)
249 : { // state okay, use facet to insert
250 0 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
251 :
252 0 : _TRY_IO_BEGIN
253 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
254 0 : _Myios::fill(), (unsigned long)_Val).failed())
255 0 : _State |= ios_base::badbit;
256 0 : _CATCH_IO_END
257 : }
258 :
259 0 : _Myios::setstate(_State);
260 0 : return (*this);
261 0 : }
262 :
263 : _Myt& __CLR_OR_THIS_CALL operator<<(int __w64 _Val)
264 9 : { // insert an int
265 9 : ios_base::iostate _State = ios_base::goodbit;
266 9 : const sentry _Ok(*this);
267 :
268 9 : if (_Ok)
269 : { // state okay, use facet to insert
270 9 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
271 : ios_base::fmtflags _Bfl =
272 9 : ios_base::flags() & ios_base::basefield;
273 : long _Tmp = (_Bfl == ios_base::oct
274 : || _Bfl == ios_base::hex)
275 9 : ? (long)(unsigned int)_Val : (long)_Val;
276 :
277 9 : _TRY_IO_BEGIN
278 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
279 9 : _Myios::fill(), _Tmp).failed())
280 9 : _State |= ios_base::badbit;
281 0 : _CATCH_IO_END
282 : }
283 :
284 9 : _Myios::setstate(_State);
285 9 : return (*this);
286 9 : }
287 :
288 : _Myt& __CLR_OR_THIS_CALL operator<<(unsigned int __w64 _Val)
289 0 : { // insert an unsigned int
290 0 : ios_base::iostate _State = ios_base::goodbit;
291 0 : const sentry _Ok(*this);
292 :
293 0 : if (_Ok)
294 : { // state okay, use facet to insert
295 0 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
296 :
297 0 : _TRY_IO_BEGIN
298 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
299 0 : _Myios::fill(), (unsigned long)_Val).failed())
300 0 : _State |= ios_base::badbit;
301 0 : _CATCH_IO_END
302 : }
303 :
304 0 : _Myios::setstate(_State);
305 0 : return (*this);
306 0 : }
307 :
308 : _Myt& __CLR_OR_THIS_CALL operator<<(long _Val)
309 : { // insert a long
310 : ios_base::iostate _State = ios_base::goodbit;
311 : const sentry _Ok(*this);
312 :
313 : if (_Ok)
314 : { // state okay, use facet to insert
315 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
316 :
317 : _TRY_IO_BEGIN
318 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
319 : _Myios::fill(), _Val).failed())
320 : _State |= ios_base::badbit;
321 : _CATCH_IO_END
322 : }
323 :
324 : _Myios::setstate(_State);
325 : return (*this);
326 : }
327 :
328 : _Myt& __CLR_OR_THIS_CALL operator<<(unsigned long __w64 _Val)
329 0 : { // insert an unsigned long
330 0 : ios_base::iostate _State = ios_base::goodbit;
331 0 : const sentry _Ok(*this);
332 :
333 0 : if (_Ok)
334 : { // state okay, use facet to insert
335 0 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
336 :
337 0 : _TRY_IO_BEGIN
338 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
339 0 : _Myios::fill(), (unsigned long)_Val).failed())
340 0 : _State |= ios_base::badbit;
341 0 : _CATCH_IO_END
342 : }
343 :
344 0 : _Myios::setstate(_State);
345 0 : return (*this);
346 0 : }
347 :
348 : #ifdef _LONGLONG
349 : _Myt& __CLR_OR_THIS_CALL operator<<(_LONGLONG _Val)
350 9 : { // insert a long long
351 9 : ios_base::iostate _State = ios_base::goodbit;
352 9 : const sentry _Ok(*this);
353 :
354 9 : if (_Ok)
355 : { // state okay, use facet to insert
356 9 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
357 :
358 9 : _TRY_IO_BEGIN
359 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
360 9 : _Myios::fill(), _Val).failed())
361 9 : _State |= ios_base::badbit;
362 0 : _CATCH_IO_END
363 : }
364 :
365 9 : _Myios::setstate(_State);
366 9 : return (*this);
367 9 : }
368 :
369 : _Myt& __CLR_OR_THIS_CALL operator<<(_ULONGLONG _Val)
370 0 : { // insert an unsigned long long
371 0 : ios_base::iostate _State = ios_base::goodbit;
372 0 : const sentry _Ok(*this);
373 :
374 0 : if (_Ok)
375 : { // state okay, use facet to insert
376 0 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
377 :
378 0 : _TRY_IO_BEGIN
379 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
380 0 : _Myios::fill(), _Val).failed())
381 0 : _State |= ios_base::badbit;
382 0 : _CATCH_IO_END
383 : }
384 :
385 0 : _Myios::setstate(_State);
386 0 : return (*this);
387 0 : }
388 : #endif /* _LONGLONG */
389 :
390 : _Myt& __CLR_OR_THIS_CALL operator<<(float _Val)
391 0 : { // insert a float
392 0 : ios_base::iostate _State = ios_base::goodbit;
393 0 : const sentry _Ok(*this);
394 :
395 0 : if (_Ok)
396 : { // state okay, use facet to insert
397 0 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
398 :
399 0 : _TRY_IO_BEGIN
400 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
401 0 : _Myios::fill(), (double)_Val).failed())
402 0 : _State |= ios_base::badbit;
403 0 : _CATCH_IO_END
404 : }
405 :
406 0 : _Myios::setstate(_State);
407 0 : return (*this);
408 0 : }
409 :
410 : _Myt& __CLR_OR_THIS_CALL operator<<(double _Val)
411 3 : { // insert a double
412 3 : ios_base::iostate _State = ios_base::goodbit;
413 3 : const sentry _Ok(*this);
414 :
415 3 : if (_Ok)
416 : { // state okay, use facet to insert
417 3 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
418 :
419 3 : _TRY_IO_BEGIN
420 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
421 3 : _Myios::fill(), _Val).failed())
422 3 : _State |= ios_base::badbit;
423 0 : _CATCH_IO_END
424 : }
425 :
426 3 : _Myios::setstate(_State);
427 3 : return (*this);
428 3 : }
429 :
430 : _Myt& __CLR_OR_THIS_CALL operator<<(long double _Val)
431 : { // insert a long double
432 : ios_base::iostate _State = ios_base::goodbit;
433 : const sentry _Ok(*this);
434 :
435 : if (_Ok)
436 : { // state okay, use facet to insert
437 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
438 :
439 : _TRY_IO_BEGIN
440 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
441 : _Myios::fill(), _Val).failed())
442 : _State |= ios_base::badbit;
443 : _CATCH_IO_END
444 : }
445 :
446 : _Myios::setstate(_State);
447 : return (*this);
448 : }
449 :
450 : _Myt& __CLR_OR_THIS_CALL operator<<(const void *_Val)
451 0 : { // insert a void pointer
452 0 : ios_base::iostate _State = ios_base::goodbit;
453 0 : const sentry _Ok(*this);
454 :
455 0 : if (_Ok)
456 : { // state okay, use facet to insert
457 0 : const _Nput& _Nput_fac = _USE(ios_base::getloc(), _Nput);
458 :
459 0 : _TRY_IO_BEGIN
460 : if (_Nput_fac.put(_Iter(_Myios::rdbuf()), *this,
461 0 : _Myios::fill(), _Val).failed())
462 0 : _State |= ios_base::badbit;
463 0 : _CATCH_IO_END
464 : }
465 :
466 0 : _Myios::setstate(_State);
467 0 : return (*this);
468 0 : }
469 :
470 : _Myt& __CLR_OR_THIS_CALL operator<<(_Mysb *_Strbuf)
471 : { // insert until end-of-file from a stream buffer
472 : ios_base::iostate _State = ios_base::goodbit;
473 : bool _Copied = false;
474 : const sentry _Ok(*this);
475 :
476 : if (_Ok && _Strbuf != 0)
477 : for (int_type _Meta = _Traits::eof(); ; _Copied = true)
478 : { // extract another character from stream buffer
479 : _TRY_BEGIN
480 : _Meta = _Traits::eq_int_type(_Traits::eof(), _Meta)
481 : ? _Strbuf->sgetc() : _Strbuf->snextc();
482 : _CATCH_ALL
483 : _Myios::setstate(ios_base::failbit);
484 : _RERAISE;
485 : _CATCH_END
486 :
487 : if (_Traits::eq_int_type(_Traits::eof(), _Meta))
488 : break; // end of file, quit
489 :
490 : _TRY_IO_BEGIN
491 : if (_Traits::eq_int_type(_Traits::eof(),
492 : _Myios::rdbuf()->sputc(
493 : _Traits::to_char_type(_Meta))))
494 : { // insertion failed, quit
495 : _State |= ios_base::badbit;
496 : break;
497 : }
498 : _CATCH_IO_END
499 : }
500 :
501 : ios_base::width(0);
502 : _Myios::setstate(_Strbuf == 0 ? ios_base::badbit
503 : : !_Copied ? _State | ios_base::failbit : _State);
504 : return (*this);
505 : }
506 :
507 : _Myt& __CLR_OR_THIS_CALL put(_Elem _Ch)
508 0 : { // insert a character
509 0 : ios_base::iostate _State = ios_base::goodbit;
510 0 : const sentry _Ok(*this);
511 :
512 0 : if (!_Ok)
513 0 : _State |= ios_base::badbit;
514 0 : else
515 : { // state okay, insert character
516 0 : _TRY_IO_BEGIN
517 : if (_Traits::eq_int_type(_Traits::eof(),
518 0 : _Myios::rdbuf()->sputc(_Ch)))
519 0 : _State |= ios_base::badbit;
520 0 : _CATCH_IO_END
521 : }
522 :
523 0 : _Myios::setstate(_State);
524 0 : return (*this);
525 0 : }
526 :
527 : _Myt& __CLR_OR_THIS_CALL write(const _Elem *_Str,
528 : streamsize _Count)
529 0 : { // insert _Count characters from array _Str
530 0 : if (0 < _Count)
531 0 : _DEBUG_POINTER(_Str);
532 0 : ios_base::iostate _State = ios_base::goodbit;
533 0 : const sentry _Ok(*this);
534 :
535 0 : if (!_Ok)
536 0 : _State |= ios_base::badbit;
537 0 : else
538 : { // state okay, insert characters
539 0 : _TRY_IO_BEGIN
540 0 : if (_Myios::rdbuf()->sputn(_Str, _Count) != _Count)
541 0 : _State |= ios_base::badbit;
542 0 : _CATCH_IO_END
543 : }
544 :
545 0 : _Myios::setstate(_State);
546 0 : return (*this);
547 0 : }
548 :
549 : _Myt& __CLR_OR_THIS_CALL flush()
550 0 : { // flush output stream
551 0 : ios_base::iostate _State = ios_base::goodbit;
552 0 : if (!ios_base::fail() && _Myios::rdbuf()->pubsync() == -1)
553 0 : _State |= ios_base::badbit; // sync failed
554 0 : _Myios::setstate(_State);
555 0 : return (*this);
556 0 : }
557 :
558 : _Myt& __CLR_OR_THIS_CALL seekp(pos_type _Pos)
559 : { // set output stream position to _Pos
560 : if (!ios_base::fail()
561 : && (off_type)_Myios::rdbuf()->pubseekpos(_Pos,
562 : ios_base::out) == _BADOFF)
563 : _Myios::setstate(ios_base::failbit);
564 : return (*this);
565 : }
566 :
567 : _Myt& __CLR_OR_THIS_CALL seekp(off_type _Off, ios_base::seekdir _Way)
568 : { // change output stream position by _Off, according to _Way
569 : if (!ios_base::fail()
570 : && (off_type)_Myios::rdbuf()->pubseekoff(_Off, _Way,
571 : ios_base::out) == _BADOFF)
572 : _Myios::setstate(ios_base::failbit);
573 : return (*this);
574 : }
575 :
576 : pos_type __CLR_OR_THIS_CALL tellp()
577 : { // return output stream position
578 : if (!ios_base::fail())
579 : return (_Myios::rdbuf()->pubseekoff(0,
580 : ios_base::cur, ios_base::out));
581 : else
582 : return (pos_type(_BADOFF));
583 : }
584 : };
585 :
586 : #ifndef _NATIVE_WCHAR_T_DEFINED
587 : /*
588 : This explicit template specialisation writes a single unicode character to the stream.
589 :
590 : By default, the compiler treats wchar_t as if it were a typedef for unsigned short. This means
591 : that we cannot distinguish between an unsigned short and a wchar_t in the library. To be most
592 : consistent with previous practice, we add this explicit specialisation to ensure that a single
593 : unsigned short is read and written as a character.
594 :
595 : If you wish to read and write unsigned shorts as integers, we recommend you consider making
596 : wchar_t a native type by using the /Zc:wchar_t compiler switch.
597 : */
598 : template <> inline
599 : basic_ostream<unsigned short, char_traits<unsigned short> >&__CLR_OR_THIS_CALL
600 : basic_ostream<unsigned short, char_traits<unsigned short> >::operator<<(
601 : unsigned short _Ch)
602 : { // insert a character
603 : typedef basic_ostream<unsigned short, char_traits<unsigned short> > _Myos;
604 : typedef char_traits<unsigned short> _Traits;
605 : _Myos &_Ostr=*this;
606 : ios_base::iostate _State = ios_base::goodbit;
607 : const _Myos::sentry _Ok(_Ostr);
608 :
609 : if (_Ok)
610 : { // state okay, insert
611 : streamsize _Pad = _Ostr.width() <= 1 ? 0 : _Ostr.width() - 1;
612 :
613 : _TRY_IO_BEGIN
614 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
615 : for (; _State == ios_base::goodbit && 0 < _Pad;
616 : --_Pad) // pad on left
617 : if (_Traits::eq_int_type(_Traits::eof(),
618 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
619 : _State |= ios_base::badbit;
620 :
621 : if (_State == ios_base::goodbit
622 : && _Traits::eq_int_type(_Traits::eof(),
623 : _Ostr.rdbuf()->sputc(_Ch)))
624 : _State |= ios_base::badbit;
625 :
626 : for (; _State == ios_base::goodbit && 0 < _Pad;
627 : --_Pad) // pad on right
628 : if (_Traits::eq_int_type(_Traits::eof(),
629 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
630 : _State |= ios_base::badbit;
631 : _CATCH_IO_(_Ostr)
632 : }
633 :
634 : _Ostr.width(0);
635 : _Ostr.setstate(_State);
636 : return (_Ostr);
637 : }
638 : #endif
639 :
640 : #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
641 :
642 : template class _CRTIMP2_PURE basic_ostream<char, char_traits<char> >;
643 : template class _CRTIMP2_PURE basic_ostream<wchar_t, char_traits<wchar_t> >;
644 :
645 :
646 :
647 : #endif /* _DLL_CPPLIB */
648 :
649 : // INSERTERS
650 :
651 : template<class _Elem,
652 : class _Traits> inline
653 : basic_ostream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator<<(
654 : basic_ostream<_Elem, _Traits>& _Ostr, const char *_Val)
655 : { // insert NTBS
656 : ios_base::iostate _State = ios_base::goodbit;
657 : streamsize _Count = (streamsize)::strlen(_Val); // may overflow
658 : streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() <= _Count
659 : ? 0 : _Ostr.width() - _Count;
660 : const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr);
661 :
662 : if (!_Ok)
663 : _State |= ios_base::badbit;
664 : else
665 : { // state okay, insert characters
666 : _TRY_IO_BEGIN
667 : const ctype<_Elem>& _Ctype_fac = _USE(_Ostr.getloc(), ctype<_Elem>);
668 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
669 : for (; 0 < _Pad; --_Pad) // pad on left
670 : if (_Traits::eq_int_type(_Traits::eof(),
671 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
672 : { // insertion failed, quit
673 : _State |= ios_base::badbit;
674 : break;
675 : }
676 :
677 : for (; _State == ios_base::goodbit && 0 < _Count; --_Count, ++_Val)
678 : if (_Traits::eq_int_type(_Traits::eof(),
679 : _Ostr.rdbuf()->sputc(_Ctype_fac.widen(*_Val))))
680 : _State |= ios_base::badbit;
681 :
682 : if (_State == ios_base::goodbit)
683 : for (; 0 < _Pad; --_Pad) // pad on right
684 : if (_Traits::eq_int_type(_Traits::eof(),
685 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
686 : { // insertion failed, quit
687 : _State |= ios_base::badbit;
688 : break;
689 : }
690 : _Ostr.width(0);
691 : _CATCH_IO_(_Ostr)
692 : }
693 :
694 : _Ostr.setstate(_State);
695 : return (_Ostr);
696 : }
697 :
698 : template<class _Elem,
699 : class _Traits> inline
700 : basic_ostream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator<<(
701 : basic_ostream<_Elem, _Traits>& _Ostr, char _Ch)
702 : { // insert a character
703 : ios_base::iostate _State = ios_base::goodbit;
704 : const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr);
705 :
706 : if (_Ok)
707 : { // state okay, insert
708 : const ctype<_Elem>& _Ctype_fac = _USE(_Ostr.getloc(), ctype<_Elem>);
709 : streamsize _Pad = _Ostr.width() <= 1 ? 0 : _Ostr.width() - 1;
710 :
711 : _TRY_IO_BEGIN
712 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
713 : for (; _State == ios_base::goodbit && 0 < _Pad;
714 : --_Pad) // pad on left
715 : if (_Traits::eq_int_type(_Traits::eof(),
716 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
717 : _State |= ios_base::badbit;
718 :
719 : if (_State == ios_base::goodbit
720 : && _Traits::eq_int_type(_Traits::eof(),
721 : _Ostr.rdbuf()->sputc(_Ctype_fac.widen(_Ch))))
722 : _State |= ios_base::badbit;
723 :
724 : for (; _State == ios_base::goodbit && 0 < _Pad;
725 : --_Pad) // pad on right
726 : if (_Traits::eq_int_type(_Traits::eof(),
727 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
728 : _State |= ios_base::badbit;
729 : _CATCH_IO_(_Ostr)
730 : }
731 :
732 : _Ostr.width(0);
733 : _Ostr.setstate(_State);
734 : return (_Ostr);
735 : }
736 :
737 : template<class _Traits> inline
738 : basic_ostream<char, _Traits>& __CLRCALL_OR_CDECL operator<<(
739 : basic_ostream<char, _Traits>& _Ostr,
740 : const char *_Val)
741 9 : { // insert NTBS into char stream
742 : typedef char _Elem;
743 : typedef basic_ostream<_Elem, _Traits> _Myos;
744 9 : ios_base::iostate _State = ios_base::goodbit;
745 9 : streamsize _Count = (streamsize)_Traits::length(_Val); // may overflow
746 : streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() <= _Count
747 9 : ? 0 : _Ostr.width() - _Count;
748 9 : const typename _Myos::sentry _Ok(_Ostr);
749 :
750 9 : if (!_Ok)
751 0 : _State |= ios_base::badbit;
752 0 : else
753 : { // state okay, insert
754 9 : _TRY_IO_BEGIN
755 9 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
756 9 : for (; 0 < _Pad; --_Pad) // pad on left
757 : if (_Traits::eq_int_type(_Traits::eof(),
758 0 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
759 : { // insertion failed, quit
760 0 : _State |= ios_base::badbit;
761 0 : break;
762 : }
763 :
764 0 : if (_State == ios_base::goodbit
765 9 : && _Ostr.rdbuf()->sputn(_Val, _Count) != _Count)
766 0 : _State |= ios_base::badbit;
767 :
768 9 : if (_State == ios_base::goodbit)
769 9 : for (; 0 < _Pad; --_Pad) // pad on right
770 : if (_Traits::eq_int_type(_Traits::eof(),
771 0 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
772 : { // insertion failed, quit
773 0 : _State |= ios_base::badbit;
774 0 : break;
775 0 : }
776 9 : _Ostr.width(0);
777 0 : _CATCH_IO_(_Ostr)
778 : }
779 :
780 9 : _Ostr.setstate(_State);
781 9 : return (_Ostr);
782 9 : }
783 :
784 : template<class _Traits> inline
785 : basic_ostream<char, _Traits>& __CLRCALL_OR_CDECL operator<<(
786 : basic_ostream<char, _Traits>& _Ostr, char _Ch)
787 10 : { // insert a char into char stream
788 : typedef char _Elem;
789 : typedef basic_ostream<_Elem, _Traits> _Myos;
790 10 : ios_base::iostate _State = ios_base::goodbit;
791 10 : const typename _Myos::sentry _Ok(_Ostr);
792 :
793 10 : if (_Ok)
794 : { // state okay, insert
795 10 : streamsize _Pad = _Ostr.width() <= 1 ? 0 : _Ostr.width() - 1;
796 :
797 10 : _TRY_IO_BEGIN
798 10 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
799 : for (; _State == ios_base::goodbit && 0 < _Pad;
800 10 : --_Pad) // pad on left
801 : if (_Traits::eq_int_type(_Traits::eof(),
802 0 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
803 0 : _State |= ios_base::badbit;
804 :
805 0 : if (_State == ios_base::goodbit
806 : && _Traits::eq_int_type(_Traits::eof(),
807 10 : _Ostr.rdbuf()->sputc(_Ch)))
808 0 : _State |= ios_base::badbit;
809 :
810 : for (; _State == ios_base::goodbit && 0 < _Pad;
811 10 : --_Pad) // pad on right
812 : if (_Traits::eq_int_type(_Traits::eof(),
813 0 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
814 0 : _State |= ios_base::badbit;
815 10 : _CATCH_IO_(_Ostr)
816 : }
817 :
818 10 : _Ostr.width(0);
819 10 : _Ostr.setstate(_State);
820 10 : return (_Ostr);
821 10 : }
822 :
823 : template<class _Elem,
824 : class _Traits> inline
825 : basic_ostream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator<<(
826 : basic_ostream<_Elem, _Traits>& _Ostr, const _Elem *_Val)
827 : { // insert NTCS
828 : typedef basic_ostream<_Elem, _Traits> _Myos;
829 : ios_base::iostate _State = ios_base::goodbit;
830 : streamsize _Count = (streamsize)_Traits::length(_Val); // may overflow
831 : streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() <= _Count
832 : ? 0 : _Ostr.width() - _Count;
833 : const typename _Myos::sentry _Ok(_Ostr);
834 :
835 : if (!_Ok)
836 : _State |= ios_base::badbit;
837 : else
838 : { // state okay, insert
839 : _TRY_IO_BEGIN
840 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
841 : for (; 0 < _Pad; --_Pad) // pad on left
842 : if (_Traits::eq_int_type(_Traits::eof(),
843 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
844 : { // insertion failed, quit
845 : _State |= ios_base::badbit;
846 : break;
847 : }
848 :
849 : if (_State == ios_base::goodbit
850 : && _Ostr.rdbuf()->sputn(_Val, _Count) != _Count)
851 : _State |= ios_base::badbit;
852 :
853 : if (_State == ios_base::goodbit)
854 : for (; 0 < _Pad; --_Pad) // pad on right
855 : if (_Traits::eq_int_type(_Traits::eof(),
856 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
857 : { // insertion failed, quit
858 : _State |= ios_base::badbit;
859 : break;
860 : }
861 : _Ostr.width(0);
862 : _CATCH_IO_(_Ostr)
863 : }
864 :
865 : _Ostr.setstate(_State);
866 : return (_Ostr);
867 : }
868 :
869 : template<class _Elem,
870 : class _Traits> inline
871 : basic_ostream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator<<(
872 : basic_ostream<_Elem, _Traits>& _Ostr, _Elem _Ch)
873 : { // insert a character
874 : typedef basic_ostream<_Elem, _Traits> _Myos;
875 : ios_base::iostate _State = ios_base::goodbit;
876 : const typename _Myos::sentry _Ok(_Ostr);
877 :
878 : if (_Ok)
879 : { // state okay, insert
880 : streamsize _Pad = _Ostr.width() <= 1 ? 0 : _Ostr.width() - 1;
881 :
882 : _TRY_IO_BEGIN
883 : if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
884 : for (; _State == ios_base::goodbit && 0 < _Pad;
885 : --_Pad) // pad on left
886 : if (_Traits::eq_int_type(_Traits::eof(),
887 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
888 : _State |= ios_base::badbit;
889 :
890 : if (_State == ios_base::goodbit
891 : && _Traits::eq_int_type(_Traits::eof(),
892 : _Ostr.rdbuf()->sputc(_Ch)))
893 : _State |= ios_base::badbit;
894 :
895 : for (; _State == ios_base::goodbit && 0 < _Pad;
896 : --_Pad) // pad on right
897 : if (_Traits::eq_int_type(_Traits::eof(),
898 : _Ostr.rdbuf()->sputc(_Ostr.fill())))
899 : _State |= ios_base::badbit;
900 : _CATCH_IO_(_Ostr)
901 : }
902 :
903 : _Ostr.width(0);
904 : _Ostr.setstate(_State);
905 : return (_Ostr);
906 : }
907 :
908 : template<class _Traits> inline
909 : basic_ostream<char, _Traits>& __CLRCALL_OR_CDECL operator<<(
910 : basic_ostream<char, _Traits>& _Ostr, const signed char *_Val)
911 : { // insert a signed char NTBS
912 : return (_Ostr << (const char *)_Val);
913 : }
914 :
915 : template<class _Traits> inline
916 : basic_ostream<char, _Traits>& __CLRCALL_OR_CDECL operator<<(
917 : basic_ostream<char, _Traits>& _Ostr, signed char _Ch)
918 : { // insert a signed char
919 : return (_Ostr << (char)_Ch);
920 : }
921 :
922 : template<class _Traits> inline
923 : basic_ostream<char, _Traits>& __CLRCALL_OR_CDECL operator<<(
924 : basic_ostream<char, _Traits>& _Ostr, const unsigned char *_Val)
925 : { // insert an unsigned char NTBS
926 : return (_Ostr << (const char *)_Val);
927 : }
928 :
929 : template<class _Traits> inline
930 : basic_ostream<char, _Traits>& __CLRCALL_OR_CDECL operator<<(
931 : basic_ostream<char, _Traits>& _Ostr, unsigned char _Ch)
932 : { // insert an unsigned char
933 : return (_Ostr << (char)_Ch);
934 : }
935 :
936 : // MANIPULATORS
937 : template<class _Elem,
938 : class _Traits> inline
939 : basic_ostream<_Elem, _Traits>&
940 : __CLRCALL_OR_CDECL endl(basic_ostream<_Elem, _Traits>& _Ostr)
941 : { // insert newline and flush stream
942 : _Ostr.put(_Ostr.widen('\n'));
943 : _Ostr.flush();
944 : return (_Ostr);
945 : }
946 :
947 : template<class _Elem,
948 : class _Traits> inline
949 : basic_ostream<_Elem, _Traits>&
950 : __CLRCALL_OR_CDECL ends(basic_ostream<_Elem, _Traits>& _Ostr)
951 : { // insert null character
952 : _Ostr.put(_Elem());
953 : return (_Ostr);
954 : }
955 :
956 : template<class _Elem,
957 : class _Traits> inline
958 : basic_ostream<_Elem, _Traits>&
959 : __CLRCALL_OR_CDECL flush(basic_ostream<_Elem, _Traits>& _Ostr)
960 : { // flush stream
961 : _Ostr.flush();
962 : return (_Ostr);
963 : }
964 :
965 : _CRTIMP2_PURE inline basic_ostream<char, char_traits<char> >&
966 : __CLRCALL_OR_CDECL endl(basic_ostream<char, char_traits<char> >& _Ostr)
967 0 : { // insert newline and flush byte stream
968 0 : _Ostr.put('\n');
969 0 : _Ostr.flush();
970 0 : return (_Ostr);
971 0 : }
972 :
973 : _CRTIMP2_PURE inline basic_ostream<wchar_t, char_traits<wchar_t> >&
974 : __CLRCALL_OR_CDECL endl(basic_ostream<wchar_t,
975 : char_traits<wchar_t> >& _Ostr)
976 : { // insert newline and flush wide stream
977 : _Ostr.put('\n');
978 : _Ostr.flush();
979 : return (_Ostr);
980 : }
981 :
982 :
983 : _CRTIMP2_PURE inline basic_ostream<char, char_traits<char> >&
984 : __CLRCALL_OR_CDECL ends(basic_ostream<char, char_traits<char> >& _Ostr)
985 : { // insert null character into byte stream
986 : _Ostr.put('\0');
987 : return (_Ostr);
988 : }
989 :
990 : _CRTIMP2_PURE inline basic_ostream<wchar_t, char_traits<wchar_t> >&
991 : __CLRCALL_OR_CDECL ends(basic_ostream<wchar_t,
992 : char_traits<wchar_t> >& _Ostr)
993 : { // insert null character into wide stream
994 : _Ostr.put('\0');
995 : return (_Ostr);
996 : }
997 :
998 :
999 : _CRTIMP2_PURE inline basic_ostream<char, char_traits<char> >&
1000 : __CLRCALL_OR_CDECL flush(basic_ostream<char, char_traits<char> >& _Ostr)
1001 : { // flush byte stream
1002 : _Ostr.flush();
1003 : return (_Ostr);
1004 : }
1005 :
1006 : _CRTIMP2_PURE inline basic_ostream<wchar_t, char_traits<wchar_t> >&
1007 : __CLRCALL_OR_CDECL flush(basic_ostream<wchar_t,
1008 : char_traits<wchar_t> >& _Ostr)
1009 : { // flush wide stream
1010 : _Ostr.flush();
1011 : return (_Ostr);
1012 : }
1013 :
1014 :
1015 : #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
1016 :
1017 : #endif /* _DLL_CPPLIB */
1018 :
1019 : _STD_END
1020 :
1021 : #ifdef _MSC_VER
1022 : #pragma warning(default: 4390)
1023 : #pragma warning(pop)
1024 : #pragma pack(pop)
1025 : #endif /* _MSC_VER */
1026 :
1027 : #endif /* RC_INVOKED */
1028 : #endif /* _OSTREAM_ */
1029 :
1030 : /*
1031 : * Copyright (c) 1992-2006 by P.J. Plauger. ALL RIGHTS RESERVED.
1032 : * Consult your license regarding permissions and restrictions.
1033 : V5.02:0009 */
|