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