Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

176 rindas
4.8KB

  1. // Stream buffer classes -*- C++ -*-
  2. // Copyright (C) 1997-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file bits/streambuf.tcc
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{streambuf}
  23. */
  24. //
  25. // ISO C++ 14882: 27.5 Stream buffers
  26. //
  27. #ifndef _STREAMBUF_TCC
  28. #define _STREAMBUF_TCC 1
  29. #pragma GCC system_header
  30. namespace std _GLIBCXX_VISIBILITY(default)
  31. {
  32. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  33. template<typename _CharT, typename _Traits>
  34. streamsize
  35. basic_streambuf<_CharT, _Traits>::
  36. xsgetn(char_type* __s, streamsize __n)
  37. {
  38. streamsize __ret = 0;
  39. while (__ret < __n)
  40. {
  41. const streamsize __buf_len = this->egptr() - this->gptr();
  42. if (__buf_len)
  43. {
  44. const streamsize __remaining = __n - __ret;
  45. const streamsize __len = std::min(__buf_len, __remaining);
  46. traits_type::copy(__s, this->gptr(), __len);
  47. __ret += __len;
  48. __s += __len;
  49. this->__safe_gbump(__len);
  50. }
  51. if (__ret < __n)
  52. {
  53. const int_type __c = this->uflow();
  54. if (!traits_type::eq_int_type(__c, traits_type::eof()))
  55. {
  56. traits_type::assign(*__s++, traits_type::to_char_type(__c));
  57. ++__ret;
  58. }
  59. else
  60. break;
  61. }
  62. }
  63. return __ret;
  64. }
  65. template<typename _CharT, typename _Traits>
  66. streamsize
  67. basic_streambuf<_CharT, _Traits>::
  68. xsputn(const char_type* __s, streamsize __n)
  69. {
  70. streamsize __ret = 0;
  71. while (__ret < __n)
  72. {
  73. const streamsize __buf_len = this->epptr() - this->pptr();
  74. if (__buf_len)
  75. {
  76. const streamsize __remaining = __n - __ret;
  77. const streamsize __len = std::min(__buf_len, __remaining);
  78. traits_type::copy(this->pptr(), __s, __len);
  79. __ret += __len;
  80. __s += __len;
  81. this->__safe_pbump(__len);
  82. }
  83. if (__ret < __n)
  84. {
  85. int_type __c = this->overflow(traits_type::to_int_type(*__s));
  86. if (!traits_type::eq_int_type(__c, traits_type::eof()))
  87. {
  88. ++__ret;
  89. ++__s;
  90. }
  91. else
  92. break;
  93. }
  94. }
  95. return __ret;
  96. }
  97. // Conceivably, this could be used to implement buffer-to-buffer
  98. // copies, if this was ever desired in an un-ambiguous way by the
  99. // standard.
  100. template<typename _CharT, typename _Traits>
  101. streamsize
  102. __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
  103. basic_streambuf<_CharT, _Traits>* __sbout,
  104. bool& __ineof)
  105. {
  106. streamsize __ret = 0;
  107. __ineof = true;
  108. typename _Traits::int_type __c = __sbin->sgetc();
  109. while (!_Traits::eq_int_type(__c, _Traits::eof()))
  110. {
  111. __c = __sbout->sputc(_Traits::to_char_type(__c));
  112. if (_Traits::eq_int_type(__c, _Traits::eof()))
  113. {
  114. __ineof = false;
  115. break;
  116. }
  117. ++__ret;
  118. __c = __sbin->snextc();
  119. }
  120. return __ret;
  121. }
  122. template<typename _CharT, typename _Traits>
  123. inline streamsize
  124. __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
  125. basic_streambuf<_CharT, _Traits>* __sbout)
  126. {
  127. bool __ineof;
  128. return __copy_streambufs_eof(__sbin, __sbout, __ineof);
  129. }
  130. // Inhibit implicit instantiations for required instantiations,
  131. // which are defined via explicit instantiations elsewhere.
  132. #if _GLIBCXX_EXTERN_TEMPLATE
  133. extern template class basic_streambuf<char>;
  134. extern template
  135. streamsize
  136. __copy_streambufs(basic_streambuf<char>*,
  137. basic_streambuf<char>*);
  138. extern template
  139. streamsize
  140. __copy_streambufs_eof(basic_streambuf<char>*,
  141. basic_streambuf<char>*, bool&);
  142. #ifdef _GLIBCXX_USE_WCHAR_T
  143. extern template class basic_streambuf<wchar_t>;
  144. extern template
  145. streamsize
  146. __copy_streambufs(basic_streambuf<wchar_t>*,
  147. basic_streambuf<wchar_t>*);
  148. extern template
  149. streamsize
  150. __copy_streambufs_eof(basic_streambuf<wchar_t>*,
  151. basic_streambuf<wchar_t>*, bool&);
  152. #endif
  153. #endif
  154. _GLIBCXX_END_NAMESPACE_VERSION
  155. } // namespace std
  156. #endif