]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // Stream buffer classes -*- C++ -*- |
2 | ||
1bc8b0ad | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
6f48900c | 4 | // Free Software Foundation, Inc. |
725dc051 BK |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
19 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
20 | // USA. | |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
31 | // | |
32 | // ISO C++ 14882: 27.5 Stream buffers | |
33 | // | |
34 | ||
3d7c150e BK |
35 | #ifndef _STREAMBUF_TCC |
36 | #define _STREAMBUF_TCC 1 | |
725dc051 | 37 | |
3b794528 BK |
38 | #pragma GCC system_header |
39 | ||
6f48900c BK |
40 | namespace std |
41 | { | |
725dc051 BK |
42 | template<typename _CharT, typename _Traits> |
43 | streamsize | |
44 | basic_streambuf<_CharT, _Traits>:: | |
45 | xsgetn(char_type* __s, streamsize __n) | |
46 | { | |
725dc051 | 47 | streamsize __ret = 0; |
13187a45 | 48 | while (__ret < __n) |
725dc051 | 49 | { |
71b46021 | 50 | const size_t __buf_len = this->egptr() - this->gptr(); |
002bd606 | 51 | if (__buf_len) |
725dc051 | 52 | { |
397751ae PC |
53 | const size_t __remaining = __n - __ret; |
54 | const size_t __len = std::min(__buf_len, __remaining); | |
71b46021 | 55 | traits_type::copy(__s, this->gptr(), __len); |
13187a45 BK |
56 | __ret += __len; |
57 | __s += __len; | |
71b46021 | 58 | this->gbump(__len); |
13187a45 BK |
59 | } |
60 | ||
61 | if (__ret < __n) | |
62 | { | |
397751ae | 63 | const int_type __c = this->uflow(); |
49433044 | 64 | if (!traits_type::eq_int_type(__c, traits_type::eof())) |
5fa9abc3 BK |
65 | { |
66 | traits_type::assign(*__s++, traits_type::to_char_type(__c)); | |
67 | ++__ret; | |
68 | } | |
69 | else | |
13187a45 | 70 | break; |
725dc051 BK |
71 | } |
72 | } | |
73 | return __ret; | |
74 | } | |
75 | ||
725dc051 BK |
76 | template<typename _CharT, typename _Traits> |
77 | streamsize | |
78 | basic_streambuf<_CharT, _Traits>:: | |
79 | xsputn(const char_type* __s, streamsize __n) | |
80 | { | |
81 | streamsize __ret = 0; | |
13187a45 | 82 | while (__ret < __n) |
725dc051 | 83 | { |
71b46021 | 84 | const size_t __buf_len = this->epptr() - this->pptr(); |
002bd606 | 85 | if (__buf_len) |
725dc051 | 86 | { |
397751ae PC |
87 | const size_t __remaining = __n - __ret; |
88 | const size_t __len = std::min(__buf_len, __remaining); | |
71b46021 | 89 | traits_type::copy(this->pptr(), __s, __len); |
13187a45 BK |
90 | __ret += __len; |
91 | __s += __len; | |
71b46021 | 92 | this->pbump(__len); |
13187a45 BK |
93 | } |
94 | ||
95 | if (__ret < __n) | |
96 | { | |
002bd606 | 97 | int_type __c = this->overflow(traits_type::to_int_type(*__s)); |
49433044 | 98 | if (!traits_type::eq_int_type(__c, traits_type::eof())) |
5fa9abc3 BK |
99 | { |
100 | ++__ret; | |
101 | ++__s; | |
102 | } | |
103 | else | |
13187a45 | 104 | break; |
725dc051 BK |
105 | } |
106 | } | |
107 | return __ret; | |
108 | } | |
109 | ||
725dc051 BK |
110 | // Conceivably, this could be used to implement buffer-to-buffer |
111 | // copies, if this was ever desired in an un-ambiguous way by the | |
112 | // standard. If so, then checks for __ios being zero would be | |
113 | // necessary. | |
114 | template<typename _CharT, typename _Traits> | |
115 | streamsize | |
fb8d4638 | 116 | __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin, |
72ed2836 | 117 | basic_streambuf<_CharT, _Traits>* __sbout) |
0992fb51 | 118 | { |
725dc051 | 119 | streamsize __ret = 0; |
fb8d4638 PC |
120 | typename _Traits::int_type __c = __sbin->sgetc(); |
121 | while (!_Traits::eq_int_type(__c, _Traits::eof())) | |
6cf5465d | 122 | { |
fb8d4638 PC |
123 | const size_t __n = __sbin->egptr() - __sbin->gptr(); |
124 | if (__n > 1) | |
0992fb51 | 125 | { |
fb8d4638 PC |
126 | const size_t __wrote = __sbout->sputn(__sbin->gptr(), __n); |
127 | __sbin->gbump(__wrote); | |
128 | __ret += __wrote; | |
129 | if (__wrote < __n) | |
130 | break; | |
131 | __c = __sbin->underflow(); | |
132 | } | |
133 | else | |
134 | { | |
135 | __c = __sbout->sputc(_Traits::to_char_type(__c)); | |
136 | if (_Traits::eq_int_type(__c, _Traits::eof())) | |
137 | break; | |
138 | ++__ret; | |
139 | __c = __sbin->snextc(); | |
0992fb51 | 140 | } |
6cf5465d | 141 | } |
725dc051 BK |
142 | return __ret; |
143 | } | |
a32e3c09 BK |
144 | |
145 | // Inhibit implicit instantiations for required instantiations, | |
146 | // which are defined via explicit instantiations elsewhere. | |
147 | // NB: This syntax is a GNU extension. | |
3d7c150e | 148 | #if _GLIBCXX_EXTERN_TEMPLATE |
a32e3c09 BK |
149 | extern template class basic_streambuf<char>; |
150 | extern template | |
151 | streamsize | |
42134429 | 152 | __copy_streambufs(basic_streambuf<char>*, basic_streambuf<char>*); |
a32e3c09 | 153 | |
3d7c150e | 154 | #ifdef _GLIBCXX_USE_WCHAR_T |
a32e3c09 BK |
155 | extern template class basic_streambuf<wchar_t>; |
156 | extern template | |
157 | streamsize | |
42134429 | 158 | __copy_streambufs(basic_streambuf<wchar_t>*, basic_streambuf<wchar_t>*); |
5112ae3a | 159 | #endif |
1bc8b0ad | 160 | #endif |
725dc051 BK |
161 | } // namespace std |
162 | ||
6f48900c | 163 | #endif |