1 // Helpers for ostream inserters -*- C++ -*-
3 // Copyright (C) 2007 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file ostream_insert.h
31 * This is an internal header file, included by other library headers.
32 * You should not attempt to use it directly.
35 #ifndef _OSTREAM_INSERT_H
36 #define _OSTREAM_INSERT_H 1
38 #pragma GCC system_header
41 #include <cxxabi-internal.h>
43 _GLIBCXX_BEGIN_NAMESPACE(std
)
45 template<typename _CharT
, typename _Traits
>
47 __ostream_write(basic_ostream
<_CharT
, _Traits
>& __out
,
48 const _CharT
* __s
, streamsize __n
)
50 typedef basic_ostream
<_CharT
, _Traits
> __ostream_type
;
51 typedef typename
__ostream_type::ios_base __ios_base
;
53 const streamsize __put
= __out
.rdbuf()->sputn(__s
, __n
);
55 __out
.setstate(__ios_base::badbit
);
58 template<typename _CharT
, typename _Traits
>
60 __ostream_fill(basic_ostream
<_CharT
, _Traits
>& __out
, streamsize __n
)
62 typedef basic_ostream
<_CharT
, _Traits
> __ostream_type
;
63 typedef typename
__ostream_type::ios_base __ios_base
;
65 const _CharT __c
= __out
.fill();
66 for (; __n
> 0; --__n
)
68 const typename
_Traits::int_type __put
= __out
.rdbuf()->sputc(__c
);
69 if (_Traits::eq_int_type(__put
, _Traits::eof()))
71 __out
.setstate(__ios_base::badbit
);
77 template<typename _CharT
, typename _Traits
>
78 basic_ostream
<_CharT
, _Traits
>&
79 __ostream_insert(basic_ostream
<_CharT
, _Traits
>& __out
,
80 const _CharT
* __s
, streamsize __n
)
82 typedef basic_ostream
<_CharT
, _Traits
> __ostream_type
;
83 typedef typename
__ostream_type::ios_base __ios_base
;
85 typename
__ostream_type::sentry
__cerb(__out
);
90 const streamsize __w
= __out
.width();
93 const bool __left
= ((__out
.flags()
94 & __ios_base::adjustfield
)
97 __ostream_fill(__out
, __w
- __n
);
99 __ostream_write(__out
, __s
, __n
);
100 if (__left
&& __out
.good())
101 __ostream_fill(__out
, __w
- __n
);
104 __ostream_write(__out
, __s
, __n
);
107 catch(__cxxabiv1::__forced_unwind
&)
109 __out
._M_setstate(__ios_base::badbit
);
110 __throw_exception_again
;
113 { __out
._M_setstate(__ios_base::badbit
); }
118 // Inhibit implicit instantiations for required instantiations,
119 // which are defined via explicit instantiations elsewhere.
120 // NB: This syntax is a GNU extension.
121 #if _GLIBCXX_EXTERN_TEMPLATE
122 extern template ostream
& __ostream_insert(ostream
&, const char*, streamsize
);
124 #ifdef _GLIBCXX_USE_WCHAR_T
125 extern template wostream
& __ostream_insert(wostream
&, const wchar_t*,
130 _GLIBCXX_END_NAMESPACE
132 #endif /* _OSTREAM_INSERT_H */