Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- istream ----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ISTREAM |
| 11 | #define _LIBCPP_ISTREAM |
| 12 | |
| 13 | /* |
| 14 | istream synopsis |
| 15 | |
| 16 | template <class charT, class traits = char_traits<charT> > |
| 17 | class basic_istream |
| 18 | : virtual public basic_ios<charT,traits> |
| 19 | { |
| 20 | public: |
| 21 | // types (inherited from basic_ios (27.5.4)): |
| 22 | typedef charT char_type; |
| 23 | typedef traits traits_type; |
| 24 | typedef typename traits_type::int_type int_type; |
| 25 | typedef typename traits_type::pos_type pos_type; |
| 26 | typedef typename traits_type::off_type off_type; |
| 27 | |
| 28 | // 27.7.1.1.1 Constructor/destructor: |
| 29 | explicit basic_istream(basic_streambuf<char_type, traits_type>* sb); |
| 30 | basic_istream(basic_istream&& rhs); |
| 31 | virtual ~basic_istream(); |
| 32 | |
| 33 | // 27.7.1.1.2 Assign/swap: |
| 34 | basic_istream& operator=(basic_istream&& rhs); |
| 35 | void swap(basic_istream& rhs); |
| 36 | |
| 37 | // 27.7.1.1.3 Prefix/suffix: |
| 38 | class sentry; |
| 39 | |
| 40 | // 27.7.1.2 Formatted input: |
| 41 | basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); |
| 42 | basic_istream& operator>>(basic_ios<char_type, traits_type>& |
| 43 | (*pf)(basic_ios<char_type, traits_type>&)); |
| 44 | basic_istream& operator>>(ios_base& (*pf)(ios_base&)); |
| 45 | basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb); |
| 46 | basic_istream& operator>>(bool& n); |
| 47 | basic_istream& operator>>(short& n); |
| 48 | basic_istream& operator>>(unsigned short& n); |
| 49 | basic_istream& operator>>(int& n); |
| 50 | basic_istream& operator>>(unsigned int& n); |
| 51 | basic_istream& operator>>(long& n); |
| 52 | basic_istream& operator>>(unsigned long& n); |
| 53 | basic_istream& operator>>(long long& n); |
| 54 | basic_istream& operator>>(unsigned long long& n); |
| 55 | basic_istream& operator>>(float& f); |
| 56 | basic_istream& operator>>(double& f); |
| 57 | basic_istream& operator>>(long double& f); |
| 58 | basic_istream& operator>>(void*& p); |
| 59 | |
| 60 | // 27.7.1.3 Unformatted input: |
| 61 | streamsize gcount() const; |
| 62 | int_type get(); |
| 63 | basic_istream& get(char_type& c); |
| 64 | basic_istream& get(char_type* s, streamsize n); |
| 65 | basic_istream& get(char_type* s, streamsize n, char_type delim); |
| 66 | basic_istream& get(basic_streambuf<char_type,traits_type>& sb); |
| 67 | basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim); |
| 68 | |
| 69 | basic_istream& getline(char_type* s, streamsize n); |
| 70 | basic_istream& getline(char_type* s, streamsize n, char_type delim); |
| 71 | |
| 72 | basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof()); |
| 73 | int_type peek(); |
| 74 | basic_istream& read (char_type* s, streamsize n); |
| 75 | streamsize readsome(char_type* s, streamsize n); |
| 76 | |
| 77 | basic_istream& putback(char_type c); |
| 78 | basic_istream& unget(); |
| 79 | int sync(); |
| 80 | |
| 81 | pos_type tellg(); |
| 82 | basic_istream& seekg(pos_type); |
| 83 | basic_istream& seekg(off_type, ios_base::seekdir); |
Marshall Clow | 27d2987 | 2014-09-16 15:27:01 +0000 | [diff] [blame] | 84 | protected: |
| 85 | basic_istream(const basic_istream& rhs) = delete; |
| 86 | basic_istream(basic_istream&& rhs); |
| 87 | // 27.7.2.1.2 Assign/swap: |
| 88 | basic_istream& operator=(const basic_istream& rhs) = delete; |
| 89 | basic_istream& operator=(basic_istream&& rhs); |
| 90 | void swap(basic_istream& rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | // 27.7.1.2.3 character extraction templates: |
| 94 | template<class charT, class traits> |
| 95 | basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&); |
| 96 | |
| 97 | template<class traits> |
| 98 | basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&); |
| 99 | |
| 100 | template<class traits> |
| 101 | basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&); |
| 102 | |
| 103 | template<class charT, class traits> |
| 104 | basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*); |
| 105 | |
| 106 | template<class traits> |
| 107 | basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*); |
| 108 | |
| 109 | template<class traits> |
| 110 | basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*); |
| 111 | |
| 112 | template <class charT, class traits> |
| 113 | void |
| 114 | swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y); |
| 115 | |
| 116 | typedef basic_istream<char> istream; |
| 117 | typedef basic_istream<wchar_t> wistream; |
| 118 | |
| 119 | template <class charT, class traits = char_traits<charT> > |
| 120 | class basic_iostream : |
| 121 | public basic_istream<charT,traits>, |
| 122 | public basic_ostream<charT,traits> |
| 123 | { |
| 124 | public: |
| 125 | // types: |
| 126 | typedef charT char_type; |
| 127 | typedef traits traits_type; |
| 128 | typedef typename traits_type::int_type int_type; |
| 129 | typedef typename traits_type::pos_type pos_type; |
| 130 | typedef typename traits_type::off_type off_type; |
| 131 | |
| 132 | // constructor/destructor |
| 133 | explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb); |
| 134 | basic_iostream(basic_iostream&& rhs); |
| 135 | virtual ~basic_iostream(); |
| 136 | |
| 137 | // assign/swap |
| 138 | basic_iostream& operator=(basic_iostream&& rhs); |
| 139 | void swap(basic_iostream& rhs); |
| 140 | }; |
| 141 | |
| 142 | template <class charT, class traits> |
| 143 | void |
| 144 | swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y); |
| 145 | |
| 146 | typedef basic_iostream<char> iostream; |
| 147 | typedef basic_iostream<wchar_t> wiostream; |
| 148 | |
| 149 | template <class charT, class traits> |
| 150 | basic_istream<charT,traits>& |
| 151 | ws(basic_istream<charT,traits>& is); |
| 152 | |
| 153 | template <class charT, class traits, class T> |
| 154 | basic_istream<charT, traits>& |
| 155 | operator>>(basic_istream<charT, traits>&& is, T& x); |
| 156 | |
| 157 | } // std |
| 158 | |
| 159 | */ |
| 160 | |
| 161 | #include <__config> |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 162 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 163 | #include <ostream> |
| 164 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 165 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 167 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 168 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 169 | _LIBCPP_PUSH_MACROS |
| 170 | #include <__undef_macros> |
| 171 | |
| 172 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 173 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 174 | |
| 175 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 176 | class _LIBCPP_TEMPLATE_VIS basic_istream |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | : virtual public basic_ios<_CharT, _Traits> |
| 178 | { |
| 179 | streamsize __gc_; |
| 180 | public: |
| 181 | // types (inherited from basic_ios (27.5.4)): |
| 182 | typedef _CharT char_type; |
| 183 | typedef _Traits traits_type; |
| 184 | typedef typename traits_type::int_type int_type; |
| 185 | typedef typename traits_type::pos_type pos_type; |
| 186 | typedef typename traits_type::off_type off_type; |
| 187 | |
| 188 | // 27.7.1.1.1 Constructor/destructor: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 189 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 190 | explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0) |
| 191 | { this->init(__sb); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 192 | virtual ~basic_istream(); |
| 193 | protected: |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 194 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 195 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 196 | basic_istream(basic_istream&& __rhs); |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 197 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | // 27.7.1.1.2 Assign/swap: |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 199 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 200 | basic_istream& operator=(basic_istream&& __rhs); |
| 201 | #endif |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 202 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 203 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 204 | void swap(basic_istream& __rhs) { |
| 205 | _VSTD::swap(__gc_, __rhs.__gc_); |
| 206 | basic_ios<char_type, traits_type>::swap(__rhs); |
| 207 | } |
Marshall Clow | 27d2987 | 2014-09-16 15:27:01 +0000 | [diff] [blame] | 208 | |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 209 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | 242d9c1 | 2014-09-16 15:33:53 +0000 | [diff] [blame] | 210 | basic_istream (const basic_istream& __rhs) = delete; |
| 211 | basic_istream& operator=(const basic_istream& __rhs) = delete; |
Marshall Clow | 27d2987 | 2014-09-16 15:27:01 +0000 | [diff] [blame] | 212 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 213 | public: |
| 214 | |
| 215 | // 27.7.1.1.3 Prefix/suffix: |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 216 | class _LIBCPP_TEMPLATE_VIS sentry; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 217 | |
| 218 | // 27.7.1.2 Formatted input: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 219 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 220 | basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) |
| 221 | { return __pf(*this); } |
| 222 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 223 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | basic_istream& operator>>(basic_ios<char_type, traits_type>& |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 225 | (*__pf)(basic_ios<char_type, traits_type>&)) |
| 226 | { __pf(*this); return *this; } |
| 227 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 228 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 229 | basic_istream& operator>>(ios_base& (*__pf)(ios_base&)) |
| 230 | { __pf(*this); return *this; } |
| 231 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 232 | basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb); |
| 233 | basic_istream& operator>>(bool& __n); |
| 234 | basic_istream& operator>>(short& __n); |
| 235 | basic_istream& operator>>(unsigned short& __n); |
| 236 | basic_istream& operator>>(int& __n); |
| 237 | basic_istream& operator>>(unsigned int& __n); |
| 238 | basic_istream& operator>>(long& __n); |
| 239 | basic_istream& operator>>(unsigned long& __n); |
| 240 | basic_istream& operator>>(long long& __n); |
| 241 | basic_istream& operator>>(unsigned long long& __n); |
| 242 | basic_istream& operator>>(float& __f); |
| 243 | basic_istream& operator>>(double& __f); |
| 244 | basic_istream& operator>>(long double& __f); |
| 245 | basic_istream& operator>>(void*& __p); |
| 246 | |
| 247 | // 27.7.1.3 Unformatted input: |
Howard Hinnant | 64da260 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 249 | streamsize gcount() const {return __gc_;} |
| 250 | int_type get(); |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 251 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 252 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 253 | basic_istream& get(char_type& __c) { |
| 254 | int_type __ch = get(); |
| 255 | if (__ch != traits_type::eof()) |
| 256 | __c = traits_type::to_char_type(__ch); |
| 257 | return *this; |
| 258 | } |
| 259 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 260 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 261 | basic_istream& get(char_type* __s, streamsize __n) |
| 262 | { return get(__s, __n, this->widen('\n')); } |
| 263 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | basic_istream& get(char_type* __s, streamsize __n, char_type __dlm); |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 265 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 266 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 267 | basic_istream& get(basic_streambuf<char_type, traits_type>& __sb) |
| 268 | { return get(__sb, this->widen('\n')); } |
| 269 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm); |
| 271 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 272 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 273 | basic_istream& getline(char_type* __s, streamsize __n) |
| 274 | { return getline(__s, __n, this->widen('\n')); } |
| 275 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 276 | basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm); |
| 277 | |
| 278 | basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof()); |
| 279 | int_type peek(); |
| 280 | basic_istream& read (char_type* __s, streamsize __n); |
| 281 | streamsize readsome(char_type* __s, streamsize __n); |
| 282 | |
| 283 | basic_istream& putback(char_type __c); |
| 284 | basic_istream& unget(); |
| 285 | int sync(); |
| 286 | |
| 287 | pos_type tellg(); |
| 288 | basic_istream& seekg(pos_type __pos); |
| 289 | basic_istream& seekg(off_type __off, ios_base::seekdir __dir); |
| 290 | }; |
| 291 | |
| 292 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 293 | class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | { |
| 295 | bool __ok_; |
| 296 | |
| 297 | sentry(const sentry&); // = delete; |
| 298 | sentry& operator=(const sentry&); // = delete; |
| 299 | |
| 300 | public: |
| 301 | explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); |
| 302 | // ~sentry() = default; |
| 303 | |
Howard Hinnant | 64da260 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 86a291f | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 305 | _LIBCPP_EXPLICIT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 306 | operator bool() const {return __ok_;} |
| 307 | }; |
| 308 | |
| 309 | template <class _CharT, class _Traits> |
| 310 | basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is, |
| 311 | bool __noskipws) |
| 312 | : __ok_(false) |
| 313 | { |
| 314 | if (__is.good()) |
| 315 | { |
| 316 | if (__is.tie()) |
| 317 | __is.tie()->flush(); |
| 318 | if (!__noskipws && (__is.flags() & ios_base::skipws)) |
| 319 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 320 | typedef istreambuf_iterator<_CharT, _Traits> _Ip; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 321 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 322 | _Ip __i(__is); |
| 323 | _Ip __eof; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 324 | for (; __i != __eof; ++__i) |
| 325 | if (!__ct.is(__ct.space, *__i)) |
| 326 | break; |
| 327 | if (__i == __eof) |
| 328 | __is.setstate(ios_base::failbit | ios_base::eofbit); |
| 329 | } |
| 330 | __ok_ = __is.good(); |
| 331 | } |
| 332 | else |
| 333 | __is.setstate(ios_base::failbit); |
| 334 | } |
| 335 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 336 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 | |
| 338 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 339 | basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs) |
| 340 | : __gc_(__rhs.__gc_) |
| 341 | { |
| 342 | __rhs.__gc_ = 0; |
| 343 | this->move(__rhs); |
| 344 | } |
| 345 | |
| 346 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | basic_istream<_CharT, _Traits>& |
| 348 | basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs) |
| 349 | { |
| 350 | swap(__rhs); |
| 351 | return *this; |
| 352 | } |
| 353 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 354 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | |
| 356 | template <class _CharT, class _Traits> |
| 357 | basic_istream<_CharT, _Traits>::~basic_istream() |
| 358 | { |
| 359 | } |
| 360 | |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 361 | template <class _Tp, class _CharT, class _Traits> |
| 362 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 363 | basic_istream<_CharT, _Traits>& |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 364 | __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 366 | try |
| 367 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 368 | #endif // _LIBCPP_NO_EXCEPTIONS |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 369 | typename basic_istream<_CharT, _Traits>::sentry __s(__is); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | if (__s) |
| 371 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 372 | typedef istreambuf_iterator<_CharT, _Traits> _Ip; |
| 373 | typedef num_get<_CharT, _Ip> _Fp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | ios_base::iostate __err = ios_base::goodbit; |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 375 | use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __n); |
| 376 | __is.setstate(__err); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | } |
| 378 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 379 | } |
| 380 | catch (...) |
| 381 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 382 | __is.__set_badbit_and_consider_rethrow(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 383 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 384 | #endif // _LIBCPP_NO_EXCEPTIONS |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 385 | return __is; |
| 386 | } |
| 387 | |
| 388 | template <class _CharT, class _Traits> |
| 389 | basic_istream<_CharT, _Traits>& |
| 390 | basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) |
| 391 | { |
| 392 | return _VSTD::__input_arithmetic<unsigned short>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | template <class _CharT, class _Traits> |
| 396 | basic_istream<_CharT, _Traits>& |
| 397 | basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) |
| 398 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 399 | return _VSTD::__input_arithmetic<unsigned int>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | template <class _CharT, class _Traits> |
| 403 | basic_istream<_CharT, _Traits>& |
| 404 | basic_istream<_CharT, _Traits>::operator>>(long& __n) |
| 405 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 406 | return _VSTD::__input_arithmetic<long>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | template <class _CharT, class _Traits> |
| 410 | basic_istream<_CharT, _Traits>& |
| 411 | basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) |
| 412 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 413 | return _VSTD::__input_arithmetic<unsigned long>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | template <class _CharT, class _Traits> |
| 417 | basic_istream<_CharT, _Traits>& |
| 418 | basic_istream<_CharT, _Traits>::operator>>(long long& __n) |
| 419 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 420 | return _VSTD::__input_arithmetic<long long>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | template <class _CharT, class _Traits> |
| 424 | basic_istream<_CharT, _Traits>& |
| 425 | basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) |
| 426 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 427 | return _VSTD::__input_arithmetic<unsigned long long>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | template <class _CharT, class _Traits> |
| 431 | basic_istream<_CharT, _Traits>& |
| 432 | basic_istream<_CharT, _Traits>::operator>>(float& __n) |
| 433 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 434 | return _VSTD::__input_arithmetic<float>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | template <class _CharT, class _Traits> |
| 438 | basic_istream<_CharT, _Traits>& |
| 439 | basic_istream<_CharT, _Traits>::operator>>(double& __n) |
| 440 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 441 | return _VSTD::__input_arithmetic<double>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | template <class _CharT, class _Traits> |
| 445 | basic_istream<_CharT, _Traits>& |
| 446 | basic_istream<_CharT, _Traits>::operator>>(long double& __n) |
| 447 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 448 | return _VSTD::__input_arithmetic<long double>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | template <class _CharT, class _Traits> |
| 452 | basic_istream<_CharT, _Traits>& |
| 453 | basic_istream<_CharT, _Traits>::operator>>(bool& __n) |
| 454 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 455 | return _VSTD::__input_arithmetic<bool>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | template <class _CharT, class _Traits> |
| 459 | basic_istream<_CharT, _Traits>& |
| 460 | basic_istream<_CharT, _Traits>::operator>>(void*& __n) |
| 461 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 462 | return _VSTD::__input_arithmetic<void*>(*this, __n); |
| 463 | } |
| 464 | |
| 465 | template <class _Tp, class _CharT, class _Traits> |
| 466 | _LIBCPP_INLINE_VISIBILITY |
| 467 | basic_istream<_CharT, _Traits>& |
| 468 | __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 470 | try |
| 471 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 472 | #endif // _LIBCPP_NO_EXCEPTIONS |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 473 | typename basic_istream<_CharT, _Traits>::sentry __s(__is); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 474 | if (__s) |
| 475 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 476 | typedef istreambuf_iterator<_CharT, _Traits> _Ip; |
| 477 | typedef num_get<_CharT, _Ip> _Fp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | ios_base::iostate __err = ios_base::goodbit; |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 479 | long __temp; |
| 480 | use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __temp); |
| 481 | if (__temp < numeric_limits<_Tp>::min()) |
| 482 | { |
| 483 | __err |= ios_base::failbit; |
| 484 | __n = numeric_limits<_Tp>::min(); |
| 485 | } |
| 486 | else if (__temp > numeric_limits<_Tp>::max()) |
| 487 | { |
| 488 | __err |= ios_base::failbit; |
| 489 | __n = numeric_limits<_Tp>::max(); |
| 490 | } |
| 491 | else |
| 492 | __n = static_cast<_Tp>(__temp); |
| 493 | __is.setstate(__err); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | } |
| 495 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 496 | } |
| 497 | catch (...) |
| 498 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 499 | __is.__set_badbit_and_consider_rethrow(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 501 | #endif // _LIBCPP_NO_EXCEPTIONS |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 502 | return __is; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | template <class _CharT, class _Traits> |
| 506 | basic_istream<_CharT, _Traits>& |
| 507 | basic_istream<_CharT, _Traits>::operator>>(short& __n) |
| 508 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 509 | return _VSTD::__input_arithmetic_with_numeric_limits<short>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | template <class _CharT, class _Traits> |
| 513 | basic_istream<_CharT, _Traits>& |
| 514 | basic_istream<_CharT, _Traits>::operator>>(int& __n) |
| 515 | { |
Louis Dionne | 8ea6608 | 2018-07-25 19:40:01 +0000 | [diff] [blame] | 516 | return _VSTD::__input_arithmetic_with_numeric_limits<int>(*this, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 519 | template<class _CharT, class _Traits> |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 520 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 521 | basic_istream<_CharT, _Traits>& |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 522 | __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | { |
| 524 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 525 | try |
| 526 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 527 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 529 | if (__sen) |
| 530 | { |
Louis Dionne | 54f5075 | 2019-04-02 19:20:47 +0000 | [diff] [blame^] | 531 | _CharT* __s = __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 533 | ios_base::iostate __err = ios_base::goodbit; |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 534 | while (__s != __p + (__n-1)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 535 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 536 | typename _Traits::int_type __i = __is.rdbuf()->sgetc(); |
| 537 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 538 | { |
| 539 | __err |= ios_base::eofbit; |
| 540 | break; |
| 541 | } |
| 542 | _CharT __ch = _Traits::to_char_type(__i); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 543 | if (__ct.is(__ct.space, __ch)) |
| 544 | break; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 545 | *__s++ = __ch; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 546 | __is.rdbuf()->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | } |
| 548 | *__s = _CharT(); |
| 549 | __is.width(0); |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 550 | if (__s == __p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 551 | __err |= ios_base::failbit; |
| 552 | __is.setstate(__err); |
| 553 | } |
| 554 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 555 | } |
| 556 | catch (...) |
| 557 | { |
| 558 | __is.__set_badbit_and_consider_rethrow(); |
| 559 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 560 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | return __is; |
| 562 | } |
| 563 | |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 564 | #if _LIBCPP_STD_VER > 17 |
| 565 | |
| 566 | template<class _CharT, class _Traits, size_t _Np> |
| 567 | inline _LIBCPP_INLINE_VISIBILITY |
| 568 | basic_istream<_CharT, _Traits>& |
| 569 | operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np]) |
| 570 | { |
Louis Dionne | 54f5075 | 2019-04-02 19:20:47 +0000 | [diff] [blame^] | 571 | size_t __n = _Np; |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 572 | if (__is.width() > 0) |
| 573 | __n = _VSTD::min(size_t(__is.width()), _Np); |
| 574 | return _VSTD::__input_c_string(__is, __buf, __n); |
| 575 | } |
| 576 | |
| 577 | template<class _Traits, size_t _Np> |
| 578 | inline _LIBCPP_INLINE_VISIBILITY |
| 579 | basic_istream<char, _Traits>& |
| 580 | operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np]) |
| 581 | { |
| 582 | return __is >> (char(&)[_Np])__buf; |
| 583 | } |
| 584 | |
| 585 | template<class _Traits, size_t _Np> |
| 586 | inline _LIBCPP_INLINE_VISIBILITY |
| 587 | basic_istream<char, _Traits>& |
| 588 | operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np]) |
| 589 | { |
| 590 | return __is >> (char(&)[_Np])__buf; |
| 591 | } |
| 592 | |
| 593 | #else |
| 594 | |
| 595 | template<class _CharT, class _Traits> |
| 596 | inline _LIBCPP_INLINE_VISIBILITY |
| 597 | basic_istream<_CharT, _Traits>& |
| 598 | operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s) |
| 599 | { |
| 600 | streamsize __n = __is.width(); |
| 601 | if (__n <= 0) |
| 602 | __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1; |
| 603 | return _VSTD::__input_c_string(__is, __s, size_t(__n)); |
| 604 | } |
| 605 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | template<class _Traits> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 607 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 608 | basic_istream<char, _Traits>& |
| 609 | operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s) |
| 610 | { |
| 611 | return __is >> (char*)__s; |
| 612 | } |
| 613 | |
| 614 | template<class _Traits> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 615 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | basic_istream<char, _Traits>& |
| 617 | operator>>(basic_istream<char, _Traits>& __is, signed char* __s) |
| 618 | { |
| 619 | return __is >> (char*)__s; |
| 620 | } |
| 621 | |
Zhihao Yuan | 404bcaa | 2018-11-21 03:30:10 +0000 | [diff] [blame] | 622 | #endif // _LIBCPP_STD_VER > 17 |
| 623 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 624 | template<class _CharT, class _Traits> |
| 625 | basic_istream<_CharT, _Traits>& |
| 626 | operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) |
| 627 | { |
| 628 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 629 | try |
| 630 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 631 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 633 | if (__sen) |
| 634 | { |
Howard Hinnant | b2e8a42 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 635 | typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); |
| 636 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 637 | __is.setstate(ios_base::eofbit | ios_base::failbit); |
| 638 | else |
| 639 | __c = _Traits::to_char_type(__i); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 640 | } |
| 641 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 642 | } |
| 643 | catch (...) |
| 644 | { |
| 645 | __is.__set_badbit_and_consider_rethrow(); |
| 646 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 647 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | return __is; |
| 649 | } |
| 650 | |
| 651 | template<class _Traits> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 652 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | basic_istream<char, _Traits>& |
| 654 | operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c) |
| 655 | { |
| 656 | return __is >> (char&)__c; |
| 657 | } |
| 658 | |
| 659 | template<class _Traits> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 660 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | basic_istream<char, _Traits>& |
| 662 | operator>>(basic_istream<char, _Traits>& __is, signed char& __c) |
| 663 | { |
| 664 | return __is >> (char&)__c; |
| 665 | } |
| 666 | |
| 667 | template<class _CharT, class _Traits> |
| 668 | basic_istream<_CharT, _Traits>& |
| 669 | basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) |
| 670 | { |
| 671 | __gc_ = 0; |
| 672 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 673 | try |
| 674 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 675 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | sentry __s(*this, true); |
| 677 | if (__s) |
| 678 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 679 | if (__sb) |
| 680 | { |
| 681 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 682 | try |
| 683 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 684 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 685 | ios_base::iostate __err = ios_base::goodbit; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 686 | while (true) |
| 687 | { |
| 688 | typename traits_type::int_type __i = this->rdbuf()->sgetc(); |
| 689 | if (traits_type::eq_int_type(__i, _Traits::eof())) |
| 690 | { |
| 691 | __err |= ios_base::eofbit; |
| 692 | break; |
| 693 | } |
| 694 | if (traits_type::eq_int_type( |
| 695 | __sb->sputc(traits_type::to_char_type(__i)), |
| 696 | traits_type::eof())) |
| 697 | break; |
| 698 | ++__gc_; |
| 699 | this->rdbuf()->sbumpc(); |
| 700 | } |
| 701 | if (__gc_ == 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 702 | __err |= ios_base::failbit; |
| 703 | this->setstate(__err); |
| 704 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 705 | } |
| 706 | catch (...) |
| 707 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 708 | if (__gc_ == 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | this->__set_failbit_and_consider_rethrow(); |
| 710 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 711 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 712 | } |
| 713 | else |
| 714 | this->setstate(ios_base::failbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | } |
| 716 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 717 | } |
| 718 | catch (...) |
| 719 | { |
| 720 | this->__set_badbit_and_consider_rethrow(); |
| 721 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 722 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | return *this; |
| 724 | } |
| 725 | |
| 726 | template<class _CharT, class _Traits> |
| 727 | typename basic_istream<_CharT, _Traits>::int_type |
| 728 | basic_istream<_CharT, _Traits>::get() |
| 729 | { |
| 730 | __gc_ = 0; |
| 731 | int_type __r = traits_type::eof(); |
| 732 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 733 | try |
| 734 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 735 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 736 | sentry __s(*this, true); |
| 737 | if (__s) |
| 738 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 739 | __r = this->rdbuf()->sbumpc(); |
| 740 | if (traits_type::eq_int_type(__r, traits_type::eof())) |
| 741 | this->setstate(ios_base::failbit | ios_base::eofbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 742 | else |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 743 | __gc_ = 1; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 744 | } |
| 745 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 746 | } |
| 747 | catch (...) |
| 748 | { |
| 749 | this->__set_badbit_and_consider_rethrow(); |
| 750 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 751 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 752 | return __r; |
| 753 | } |
| 754 | |
| 755 | template<class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | basic_istream<_CharT, _Traits>& |
| 757 | basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) |
| 758 | { |
| 759 | __gc_ = 0; |
| 760 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 761 | try |
| 762 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 763 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 764 | sentry __sen(*this, true); |
| 765 | if (__sen) |
| 766 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 767 | if (__n > 0) |
| 768 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 769 | ios_base::iostate __err = ios_base::goodbit; |
| 770 | while (__gc_ < __n-1) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 771 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 772 | int_type __i = this->rdbuf()->sgetc(); |
| 773 | if (traits_type::eq_int_type(__i, traits_type::eof())) |
| 774 | { |
| 775 | __err |= ios_base::eofbit; |
| 776 | break; |
| 777 | } |
| 778 | char_type __ch = traits_type::to_char_type(__i); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 779 | if (traits_type::eq(__ch, __dlm)) |
| 780 | break; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 781 | *__s++ = __ch; |
| 782 | ++__gc_; |
| 783 | this->rdbuf()->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 784 | } |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 785 | if (__gc_ == 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 786 | __err |= ios_base::failbit; |
| 787 | this->setstate(__err); |
| 788 | } |
| 789 | else |
| 790 | this->setstate(ios_base::failbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | } |
Volodymyr Sapsai | 99be85e | 2018-01-11 23:23:49 +0000 | [diff] [blame] | 792 | if (__n > 0) |
| 793 | *__s = char_type(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 795 | } |
| 796 | catch (...) |
| 797 | { |
Volodymyr Sapsai | 99be85e | 2018-01-11 23:23:49 +0000 | [diff] [blame] | 798 | if (__n > 0) |
| 799 | *__s = char_type(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 800 | this->__set_badbit_and_consider_rethrow(); |
| 801 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 802 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | return *this; |
| 804 | } |
| 805 | |
| 806 | template<class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 807 | basic_istream<_CharT, _Traits>& |
| 808 | basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, |
| 809 | char_type __dlm) |
| 810 | { |
| 811 | __gc_ = 0; |
| 812 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 813 | try |
| 814 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 815 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 816 | sentry __sen(*this, true); |
| 817 | if (__sen) |
| 818 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | ios_base::iostate __err = ios_base::goodbit; |
| 820 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 821 | try |
| 822 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 823 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 824 | while (true) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 825 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 826 | typename traits_type::int_type __i = this->rdbuf()->sgetc(); |
| 827 | if (traits_type::eq_int_type(__i, traits_type::eof())) |
| 828 | { |
| 829 | __err |= ios_base::eofbit; |
| 830 | break; |
| 831 | } |
| 832 | char_type __ch = traits_type::to_char_type(__i); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 833 | if (traits_type::eq(__ch, __dlm)) |
| 834 | break; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 835 | if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | break; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 837 | ++__gc_; |
| 838 | this->rdbuf()->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 839 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 840 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 841 | } |
| 842 | catch (...) |
| 843 | { |
| 844 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 845 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 846 | if (__gc_ == 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | __err |= ios_base::failbit; |
| 848 | this->setstate(__err); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 849 | } |
| 850 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 851 | } |
| 852 | catch (...) |
| 853 | { |
| 854 | this->__set_badbit_and_consider_rethrow(); |
| 855 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 856 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 857 | return *this; |
| 858 | } |
| 859 | |
| 860 | template<class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | basic_istream<_CharT, _Traits>& |
| 862 | basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) |
| 863 | { |
| 864 | __gc_ = 0; |
| 865 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 866 | try |
| 867 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 868 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 869 | sentry __sen(*this, true); |
| 870 | if (__sen) |
| 871 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 872 | ios_base::iostate __err = ios_base::goodbit; |
| 873 | while (true) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 875 | typename traits_type::int_type __i = this->rdbuf()->sgetc(); |
| 876 | if (traits_type::eq_int_type(__i, traits_type::eof())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 878 | __err |= ios_base::eofbit; |
| 879 | break; |
| 880 | } |
| 881 | char_type __ch = traits_type::to_char_type(__i); |
| 882 | if (traits_type::eq(__ch, __dlm)) |
| 883 | { |
| 884 | this->rdbuf()->sbumpc(); |
| 885 | ++__gc_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 886 | break; |
| 887 | } |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 888 | if (__gc_ >= __n-1) |
| 889 | { |
| 890 | __err |= ios_base::failbit; |
| 891 | break; |
| 892 | } |
| 893 | *__s++ = __ch; |
| 894 | this->rdbuf()->sbumpc(); |
| 895 | ++__gc_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 896 | } |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 897 | if (__gc_ == 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 898 | __err |= ios_base::failbit; |
| 899 | this->setstate(__err); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 900 | } |
Volodymyr Sapsai | b801d70 | 2017-11-22 18:52:36 +0000 | [diff] [blame] | 901 | if (__n > 0) |
| 902 | *__s = char_type(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 904 | } |
| 905 | catch (...) |
| 906 | { |
Volodymyr Sapsai | b801d70 | 2017-11-22 18:52:36 +0000 | [diff] [blame] | 907 | if (__n > 0) |
| 908 | *__s = char_type(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 909 | this->__set_badbit_and_consider_rethrow(); |
| 910 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 911 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 912 | return *this; |
| 913 | } |
| 914 | |
| 915 | template<class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 916 | basic_istream<_CharT, _Traits>& |
| 917 | basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) |
| 918 | { |
| 919 | __gc_ = 0; |
| 920 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 921 | try |
| 922 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 923 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 924 | sentry __sen(*this, true); |
| 925 | if (__sen) |
| 926 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 927 | ios_base::iostate __err = ios_base::goodbit; |
| 928 | if (__n == numeric_limits<streamsize>::max()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 929 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 930 | while (true) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 931 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 932 | typename traits_type::int_type __i = this->rdbuf()->sbumpc(); |
| 933 | if (traits_type::eq_int_type(__i, traits_type::eof())) |
| 934 | { |
| 935 | __err |= ios_base::eofbit; |
| 936 | break; |
| 937 | } |
| 938 | ++__gc_; |
Howard Hinnant | 4df1e3f | 2013-07-01 00:37:50 +0000 | [diff] [blame] | 939 | if (traits_type::eq_int_type(__i, __dlm)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 940 | break; |
| 941 | } |
| 942 | } |
| 943 | else |
| 944 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 945 | while (__gc_ < __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 946 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 947 | typename traits_type::int_type __i = this->rdbuf()->sbumpc(); |
| 948 | if (traits_type::eq_int_type(__i, traits_type::eof())) |
| 949 | { |
| 950 | __err |= ios_base::eofbit; |
| 951 | break; |
| 952 | } |
| 953 | ++__gc_; |
Howard Hinnant | 4df1e3f | 2013-07-01 00:37:50 +0000 | [diff] [blame] | 954 | if (traits_type::eq_int_type(__i, __dlm)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 955 | break; |
| 956 | } |
| 957 | } |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 958 | this->setstate(__err); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | } |
| 960 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 961 | } |
| 962 | catch (...) |
| 963 | { |
| 964 | this->__set_badbit_and_consider_rethrow(); |
| 965 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 966 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 967 | return *this; |
| 968 | } |
| 969 | |
| 970 | template<class _CharT, class _Traits> |
| 971 | typename basic_istream<_CharT, _Traits>::int_type |
| 972 | basic_istream<_CharT, _Traits>::peek() |
| 973 | { |
| 974 | __gc_ = 0; |
| 975 | int_type __r = traits_type::eof(); |
| 976 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 977 | try |
| 978 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 979 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | sentry __sen(*this, true); |
| 981 | if (__sen) |
Howard Hinnant | a442737 | 2012-11-01 17:32:07 +0000 | [diff] [blame] | 982 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 983 | __r = this->rdbuf()->sgetc(); |
Howard Hinnant | a442737 | 2012-11-01 17:32:07 +0000 | [diff] [blame] | 984 | if (traits_type::eq_int_type(__r, traits_type::eof())) |
| 985 | this->setstate(ios_base::eofbit); |
| 986 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 988 | } |
| 989 | catch (...) |
| 990 | { |
| 991 | this->__set_badbit_and_consider_rethrow(); |
| 992 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 993 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | return __r; |
| 995 | } |
| 996 | |
| 997 | template<class _CharT, class _Traits> |
| 998 | basic_istream<_CharT, _Traits>& |
| 999 | basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) |
| 1000 | { |
| 1001 | __gc_ = 0; |
| 1002 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1003 | try |
| 1004 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1005 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | sentry __sen(*this, true); |
| 1007 | if (__sen) |
| 1008 | { |
Howard Hinnant | 232466c | 2013-03-06 19:27:56 +0000 | [diff] [blame] | 1009 | __gc_ = this->rdbuf()->sgetn(__s, __n); |
| 1010 | if (__gc_ != __n) |
| 1011 | this->setstate(ios_base::failbit | ios_base::eofbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1012 | } |
| 1013 | else |
| 1014 | this->setstate(ios_base::failbit); |
| 1015 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1016 | } |
| 1017 | catch (...) |
| 1018 | { |
| 1019 | this->__set_badbit_and_consider_rethrow(); |
| 1020 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1021 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1022 | return *this; |
| 1023 | } |
| 1024 | |
| 1025 | template<class _CharT, class _Traits> |
| 1026 | streamsize |
| 1027 | basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) |
| 1028 | { |
Howard Hinnant | af8555c | 2012-12-20 15:40:28 +0000 | [diff] [blame] | 1029 | __gc_ = 0; |
Marshall Clow | 1c6e386 | 2016-07-13 16:58:48 +0000 | [diff] [blame] | 1030 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1031 | try |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | { |
Marshall Clow | 1c6e386 | 2016-07-13 16:58:48 +0000 | [diff] [blame] | 1033 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 1034 | sentry __sen(*this, true); |
| 1035 | if (__sen) |
| 1036 | { |
| 1037 | streamsize __c = this->rdbuf()->in_avail(); |
| 1038 | switch (__c) |
| 1039 | { |
| 1040 | case -1: |
| 1041 | this->setstate(ios_base::eofbit); |
| 1042 | break; |
| 1043 | case 0: |
| 1044 | break; |
| 1045 | default: |
| 1046 | read(__s, _VSTD::min(__c, __n)); |
| 1047 | break; |
| 1048 | } |
| 1049 | } |
| 1050 | else |
| 1051 | this->setstate(ios_base::failbit); |
| 1052 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1053 | } |
Marshall Clow | 1c6e386 | 2016-07-13 16:58:48 +0000 | [diff] [blame] | 1054 | catch (...) |
| 1055 | { |
| 1056 | this->__set_badbit_and_consider_rethrow(); |
| 1057 | } |
| 1058 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1059 | return __gc_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | template<class _CharT, class _Traits> |
| 1063 | basic_istream<_CharT, _Traits>& |
| 1064 | basic_istream<_CharT, _Traits>::putback(char_type __c) |
| 1065 | { |
| 1066 | __gc_ = 0; |
| 1067 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1068 | try |
| 1069 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1070 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0c8d6a4 | 2012-08-24 22:03:03 +0000 | [diff] [blame] | 1071 | this->clear(this->rdstate() & ~ios_base::eofbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | sentry __sen(*this, true); |
| 1073 | if (__sen) |
| 1074 | { |
| 1075 | if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) |
| 1076 | this->setstate(ios_base::badbit); |
| 1077 | } |
| 1078 | else |
| 1079 | this->setstate(ios_base::failbit); |
| 1080 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1081 | } |
| 1082 | catch (...) |
| 1083 | { |
| 1084 | this->__set_badbit_and_consider_rethrow(); |
| 1085 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1086 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1087 | return *this; |
| 1088 | } |
| 1089 | |
| 1090 | template<class _CharT, class _Traits> |
| 1091 | basic_istream<_CharT, _Traits>& |
| 1092 | basic_istream<_CharT, _Traits>::unget() |
| 1093 | { |
| 1094 | __gc_ = 0; |
| 1095 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1096 | try |
| 1097 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1098 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0c8d6a4 | 2012-08-24 22:03:03 +0000 | [diff] [blame] | 1099 | this->clear(this->rdstate() & ~ios_base::eofbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1100 | sentry __sen(*this, true); |
| 1101 | if (__sen) |
| 1102 | { |
| 1103 | if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof()) |
| 1104 | this->setstate(ios_base::badbit); |
| 1105 | } |
| 1106 | else |
| 1107 | this->setstate(ios_base::failbit); |
| 1108 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1109 | } |
| 1110 | catch (...) |
| 1111 | { |
| 1112 | this->__set_badbit_and_consider_rethrow(); |
| 1113 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1114 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1115 | return *this; |
| 1116 | } |
| 1117 | |
| 1118 | template<class _CharT, class _Traits> |
| 1119 | int |
| 1120 | basic_istream<_CharT, _Traits>::sync() |
| 1121 | { |
| 1122 | int __r = 0; |
| 1123 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1124 | try |
| 1125 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1126 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | sentry __sen(*this, true); |
| 1128 | if (__sen) |
| 1129 | { |
| 1130 | if (this->rdbuf() == 0) |
| 1131 | return -1; |
| 1132 | if (this->rdbuf()->pubsync() == -1) |
| 1133 | { |
| 1134 | this->setstate(ios_base::badbit); |
| 1135 | return -1; |
| 1136 | } |
| 1137 | } |
| 1138 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1139 | } |
| 1140 | catch (...) |
| 1141 | { |
| 1142 | this->__set_badbit_and_consider_rethrow(); |
| 1143 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1144 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1145 | return __r; |
| 1146 | } |
| 1147 | |
| 1148 | template<class _CharT, class _Traits> |
| 1149 | typename basic_istream<_CharT, _Traits>::pos_type |
| 1150 | basic_istream<_CharT, _Traits>::tellg() |
| 1151 | { |
| 1152 | pos_type __r(-1); |
| 1153 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1154 | try |
| 1155 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1156 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1157 | sentry __sen(*this, true); |
| 1158 | if (__sen) |
| 1159 | __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); |
| 1160 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1161 | } |
| 1162 | catch (...) |
| 1163 | { |
| 1164 | this->__set_badbit_and_consider_rethrow(); |
| 1165 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1166 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | return __r; |
| 1168 | } |
| 1169 | |
| 1170 | template<class _CharT, class _Traits> |
| 1171 | basic_istream<_CharT, _Traits>& |
| 1172 | basic_istream<_CharT, _Traits>::seekg(pos_type __pos) |
| 1173 | { |
| 1174 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1175 | try |
| 1176 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1177 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0c8d6a4 | 2012-08-24 22:03:03 +0000 | [diff] [blame] | 1178 | this->clear(this->rdstate() & ~ios_base::eofbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1179 | sentry __sen(*this, true); |
| 1180 | if (__sen) |
Marshall Clow | 29c4daa | 2013-10-31 22:20:45 +0000 | [diff] [blame] | 1181 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1182 | if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) |
| 1183 | this->setstate(ios_base::failbit); |
Marshall Clow | 29c4daa | 2013-10-31 22:20:45 +0000 | [diff] [blame] | 1184 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1185 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1186 | } |
| 1187 | catch (...) |
| 1188 | { |
| 1189 | this->__set_badbit_and_consider_rethrow(); |
| 1190 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1191 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | return *this; |
| 1193 | } |
| 1194 | |
| 1195 | template<class _CharT, class _Traits> |
| 1196 | basic_istream<_CharT, _Traits>& |
| 1197 | basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) |
| 1198 | { |
| 1199 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1200 | try |
| 1201 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1202 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 41d9e3a | 2015-10-25 18:31:51 +0000 | [diff] [blame] | 1203 | this->clear(this->rdstate() & ~ios_base::eofbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1204 | sentry __sen(*this, true); |
| 1205 | if (__sen) |
Marshall Clow | 29c4daa | 2013-10-31 22:20:45 +0000 | [diff] [blame] | 1206 | { |
| 1207 | if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1)) |
| 1208 | this->setstate(ios_base::failbit); |
| 1209 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1211 | } |
| 1212 | catch (...) |
| 1213 | { |
| 1214 | this->__set_badbit_and_consider_rethrow(); |
| 1215 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1216 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | return *this; |
| 1218 | } |
| 1219 | |
| 1220 | template <class _CharT, class _Traits> |
| 1221 | basic_istream<_CharT, _Traits>& |
| 1222 | ws(basic_istream<_CharT, _Traits>& __is) |
| 1223 | { |
| 1224 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1225 | try |
| 1226 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1227 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); |
| 1229 | if (__sen) |
| 1230 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1231 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1232 | while (true) |
| 1233 | { |
| 1234 | typename _Traits::int_type __i = __is.rdbuf()->sgetc(); |
| 1235 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 1236 | { |
| 1237 | __is.setstate(ios_base::eofbit); |
| 1238 | break; |
| 1239 | } |
| 1240 | if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1241 | break; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1242 | __is.rdbuf()->sbumpc(); |
| 1243 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | } |
| 1245 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1246 | } |
| 1247 | catch (...) |
| 1248 | { |
| 1249 | __is.__set_badbit_and_consider_rethrow(); |
| 1250 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1251 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1252 | return __is; |
| 1253 | } |
| 1254 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1255 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1256 | |
| 1257 | template <class _CharT, class _Traits, class _Tp> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 1258 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1259 | basic_istream<_CharT, _Traits>& |
Eric Fiselier | 7955ef6 | 2016-07-24 04:07:22 +0000 | [diff] [blame] | 1260 | operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1261 | { |
Eric Fiselier | 7955ef6 | 2016-07-24 04:07:22 +0000 | [diff] [blame] | 1262 | __is >> _VSTD::forward<_Tp>(__x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1263 | return __is; |
| 1264 | } |
| 1265 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1266 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1267 | |
| 1268 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1269 | class _LIBCPP_TEMPLATE_VIS basic_iostream |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | : public basic_istream<_CharT, _Traits>, |
| 1271 | public basic_ostream<_CharT, _Traits> |
| 1272 | { |
| 1273 | public: |
| 1274 | // types: |
| 1275 | typedef _CharT char_type; |
| 1276 | typedef _Traits traits_type; |
| 1277 | typedef typename traits_type::int_type int_type; |
| 1278 | typedef typename traits_type::pos_type pos_type; |
| 1279 | typedef typename traits_type::off_type off_type; |
| 1280 | |
| 1281 | // constructor/destructor |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 1282 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1283 | explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb) |
| 1284 | : basic_istream<_CharT, _Traits>(__sb) |
| 1285 | {} |
| 1286 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | virtual ~basic_iostream(); |
| 1288 | protected: |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1289 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1290 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1291 | basic_iostream(basic_iostream&& __rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1292 | |
| 1293 | // assign/swap |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1294 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1295 | basic_iostream& operator=(basic_iostream&& __rhs); |
| 1296 | #endif |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 1297 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1298 | void swap(basic_iostream& __rhs) |
| 1299 | { basic_istream<char_type, traits_type>::swap(__rhs); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1300 | }; |
| 1301 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1302 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | |
| 1304 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1305 | basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1306 | : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1307 | { |
| 1308 | } |
| 1309 | |
| 1310 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | basic_iostream<_CharT, _Traits>& |
| 1312 | basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) |
| 1313 | { |
| 1314 | swap(__rhs); |
| 1315 | return *this; |
| 1316 | } |
| 1317 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1318 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1319 | |
| 1320 | template <class _CharT, class _Traits> |
| 1321 | basic_iostream<_CharT, _Traits>::~basic_iostream() |
| 1322 | { |
| 1323 | } |
| 1324 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | template<class _CharT, class _Traits, class _Allocator> |
| 1326 | basic_istream<_CharT, _Traits>& |
| 1327 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 1328 | basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1329 | { |
| 1330 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1331 | try |
| 1332 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1333 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 1335 | if (__sen) |
| 1336 | { |
| 1337 | __str.clear(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | streamsize __n = __is.width(); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1339 | if (__n <= 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1340 | __n = __str.max_size(); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1341 | if (__n <= 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1342 | __n = numeric_limits<streamsize>::max(); |
| 1343 | streamsize __c = 0; |
| 1344 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1345 | ios_base::iostate __err = ios_base::goodbit; |
| 1346 | while (__c < __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1348 | typename _Traits::int_type __i = __is.rdbuf()->sgetc(); |
| 1349 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 1350 | { |
| 1351 | __err |= ios_base::eofbit; |
| 1352 | break; |
| 1353 | } |
| 1354 | _CharT __ch = _Traits::to_char_type(__i); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 | if (__ct.is(__ct.space, __ch)) |
| 1356 | break; |
| 1357 | __str.push_back(__ch); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1358 | ++__c; |
| 1359 | __is.rdbuf()->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1360 | } |
| 1361 | __is.width(0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1362 | if (__c == 0) |
| 1363 | __err |= ios_base::failbit; |
| 1364 | __is.setstate(__err); |
| 1365 | } |
| 1366 | else |
| 1367 | __is.setstate(ios_base::failbit); |
| 1368 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1369 | } |
| 1370 | catch (...) |
| 1371 | { |
| 1372 | __is.__set_badbit_and_consider_rethrow(); |
| 1373 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1374 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1375 | return __is; |
| 1376 | } |
| 1377 | |
| 1378 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1379 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | getline(basic_istream<_CharT, _Traits>& __is, |
| 1381 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) |
| 1382 | { |
| 1383 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1384 | try |
| 1385 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1386 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1387 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); |
| 1388 | if (__sen) |
| 1389 | { |
| 1390 | __str.clear(); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1391 | ios_base::iostate __err = ios_base::goodbit; |
Howard Hinnant | e992f76 | 2011-10-09 15:20:46 +0000 | [diff] [blame] | 1392 | streamsize __extr = 0; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1393 | while (true) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1395 | typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); |
| 1396 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 1397 | { |
| 1398 | __err |= ios_base::eofbit; |
| 1399 | break; |
| 1400 | } |
Howard Hinnant | e992f76 | 2011-10-09 15:20:46 +0000 | [diff] [blame] | 1401 | ++__extr; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1402 | _CharT __ch = _Traits::to_char_type(__i); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1403 | if (_Traits::eq(__ch, __dlm)) |
| 1404 | break; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1405 | __str.push_back(__ch); |
| 1406 | if (__str.size() == __str.max_size()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1407 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1408 | __err |= ios_base::failbit; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1409 | break; |
| 1410 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1411 | } |
Howard Hinnant | e992f76 | 2011-10-09 15:20:46 +0000 | [diff] [blame] | 1412 | if (__extr == 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | __err |= ios_base::failbit; |
| 1414 | __is.setstate(__err); |
| 1415 | } |
| 1416 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1417 | } |
| 1418 | catch (...) |
| 1419 | { |
| 1420 | __is.__set_badbit_and_consider_rethrow(); |
| 1421 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1422 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | return __is; |
| 1424 | } |
| 1425 | |
| 1426 | template<class _CharT, class _Traits, class _Allocator> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 1427 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1428 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | getline(basic_istream<_CharT, _Traits>& __is, |
| 1430 | basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1431 | { |
| 1432 | return getline(__is, __str, __is.widen('\n')); |
| 1433 | } |
| 1434 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1435 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | |
| 1437 | template<class _CharT, class _Traits, class _Allocator> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 1438 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1439 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 1441 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) |
| 1442 | { |
| 1443 | return getline(__is, __str, __dlm); |
| 1444 | } |
| 1445 | |
| 1446 | template<class _CharT, class _Traits, class _Allocator> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 1447 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1448 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1449 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 1450 | basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1451 | { |
| 1452 | return getline(__is, __str, __is.widen('\n')); |
| 1453 | } |
| 1454 | |
Eric Fiselier | 78ccf77 | 2017-04-18 23:38:41 +0000 | [diff] [blame] | 1455 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | |
| 1457 | template <class _CharT, class _Traits, size_t _Size> |
| 1458 | basic_istream<_CharT, _Traits>& |
| 1459 | operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) |
| 1460 | { |
| 1461 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1462 | try |
| 1463 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1464 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1465 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 1466 | if (__sen) |
| 1467 | { |
| 1468 | basic_string<_CharT, _Traits> __str; |
| 1469 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 1470 | size_t __c = 0; |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1471 | ios_base::iostate __err = ios_base::goodbit; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1472 | _CharT __zero = __ct.widen('0'); |
| 1473 | _CharT __one = __ct.widen('1'); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1474 | while (__c < _Size) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | { |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1476 | typename _Traits::int_type __i = __is.rdbuf()->sgetc(); |
| 1477 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 1478 | { |
| 1479 | __err |= ios_base::eofbit; |
| 1480 | break; |
| 1481 | } |
| 1482 | _CharT __ch = _Traits::to_char_type(__i); |
| 1483 | if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1484 | break; |
| 1485 | __str.push_back(__ch); |
Howard Hinnant | e51e4e9 | 2011-09-01 21:02:45 +0000 | [diff] [blame] | 1486 | ++__c; |
| 1487 | __is.rdbuf()->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1488 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1489 | __x = bitset<_Size>(__str); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | if (__c == 0) |
| 1491 | __err |= ios_base::failbit; |
| 1492 | __is.setstate(__err); |
| 1493 | } |
| 1494 | else |
| 1495 | __is.setstate(ios_base::failbit); |
| 1496 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1497 | } |
| 1498 | catch (...) |
| 1499 | { |
| 1500 | __is.__set_badbit_and_consider_rethrow(); |
| 1501 | } |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1502 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1503 | return __is; |
| 1504 | } |
| 1505 | |
Louis Dionne | 207a910 | 2018-12-06 00:24:58 +0000 | [diff] [blame] | 1506 | #ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB |
Eric Fiselier | 1b57fa8 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 1507 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>) |
| 1508 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>) |
| 1509 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>) |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 1510 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1511 | |
| 1512 | _LIBCPP_END_NAMESPACE_STD |
| 1513 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 1514 | _LIBCPP_POP_MACROS |
| 1515 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1516 | #endif // _LIBCPP_ISTREAM |