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 | { |
| 745 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 746 | streamsize __n = __is.width(); |
| 747 | if (__n == 0) |
| 748 | __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1; |
| 749 | streamsize __c = 0; |
| 750 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
| 751 | _I __i(__is); |
| 752 | _I __eof; |
| 753 | for (; __i != __eof && __c < __n-1; ++__i, ++__s, ++__c) |
| 754 | { |
| 755 | _CharT __ch = *__i; |
| 756 | if (__ct.is(__ct.space, __ch)) |
| 757 | break; |
| 758 | *__s = __ch; |
| 759 | } |
| 760 | *__s = _CharT(); |
| 761 | __is.width(0); |
| 762 | ios_base::iostate __err = ios_base::goodbit; |
| 763 | if (__i == __eof) |
| 764 | __err |= ios_base::eofbit; |
| 765 | if (__c == 0) |
| 766 | __err |= ios_base::failbit; |
| 767 | __is.setstate(__err); |
| 768 | } |
| 769 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 770 | } |
| 771 | catch (...) |
| 772 | { |
| 773 | __is.__set_badbit_and_consider_rethrow(); |
| 774 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 775 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 776 | return __is; |
| 777 | } |
| 778 | |
| 779 | template<class _Traits> |
| 780 | inline _LIBCPP_INLINE_VISIBILITY |
| 781 | basic_istream<char, _Traits>& |
| 782 | operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s) |
| 783 | { |
| 784 | return __is >> (char*)__s; |
| 785 | } |
| 786 | |
| 787 | template<class _Traits> |
| 788 | inline _LIBCPP_INLINE_VISIBILITY |
| 789 | basic_istream<char, _Traits>& |
| 790 | operator>>(basic_istream<char, _Traits>& __is, signed char* __s) |
| 791 | { |
| 792 | return __is >> (char*)__s; |
| 793 | } |
| 794 | |
| 795 | template<class _CharT, class _Traits> |
| 796 | basic_istream<_CharT, _Traits>& |
| 797 | operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) |
| 798 | { |
| 799 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 800 | try |
| 801 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 802 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 804 | if (__sen) |
| 805 | { |
Howard Hinnant | df85e57 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 806 | #if 1 |
| 807 | typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); |
| 808 | if (_Traits::eq_int_type(__i, _Traits::eof())) |
| 809 | __is.setstate(ios_base::eofbit | ios_base::failbit); |
| 810 | else |
| 811 | __c = _Traits::to_char_type(__i); |
| 812 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 813 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 814 | _I __i(__is); |
| 815 | _I __eof; |
| 816 | if (__i != __eof) |
| 817 | { |
| 818 | __c = *__i; |
| 819 | if (++__i == __eof) |
| 820 | __is.setstate(ios_base::eofbit); |
| 821 | } |
| 822 | else |
| 823 | __is.setstate(ios_base::eofbit | ios_base::failbit); |
Howard Hinnant | df85e57 | 2011-02-27 18:02:02 +0000 | [diff] [blame] | 824 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 825 | } |
| 826 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 827 | } |
| 828 | catch (...) |
| 829 | { |
| 830 | __is.__set_badbit_and_consider_rethrow(); |
| 831 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 832 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 833 | return __is; |
| 834 | } |
| 835 | |
| 836 | template<class _Traits> |
| 837 | inline _LIBCPP_INLINE_VISIBILITY |
| 838 | basic_istream<char, _Traits>& |
| 839 | operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c) |
| 840 | { |
| 841 | return __is >> (char&)__c; |
| 842 | } |
| 843 | |
| 844 | template<class _Traits> |
| 845 | inline _LIBCPP_INLINE_VISIBILITY |
| 846 | basic_istream<char, _Traits>& |
| 847 | operator>>(basic_istream<char, _Traits>& __is, signed char& __c) |
| 848 | { |
| 849 | return __is >> (char&)__c; |
| 850 | } |
| 851 | |
| 852 | template<class _CharT, class _Traits> |
| 853 | basic_istream<_CharT, _Traits>& |
| 854 | basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) |
| 855 | { |
| 856 | __gc_ = 0; |
| 857 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 858 | try |
| 859 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 860 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | sentry __s(*this, true); |
| 862 | if (__s) |
| 863 | { |
| 864 | streamsize __c = 0; |
| 865 | if (__sb) |
| 866 | { |
| 867 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 868 | try |
| 869 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 870 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 871 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 872 | typedef ostreambuf_iterator<char_type, traits_type> _O; |
| 873 | _I __i(*this); |
| 874 | _I __eof; |
| 875 | _O __o(__sb); |
| 876 | for (; __i != __eof; ++__i, ++__o, ++__c) |
| 877 | { |
| 878 | *__o = *__i; |
| 879 | if (__o.failed()) |
| 880 | break; |
| 881 | } |
| 882 | ios_base::iostate __err = ios_base::goodbit; |
| 883 | if (__i == __eof) |
| 884 | __err |= ios_base::eofbit; |
| 885 | if (__c == 0) |
| 886 | __err |= ios_base::failbit; |
| 887 | this->setstate(__err); |
| 888 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 889 | } |
| 890 | catch (...) |
| 891 | { |
| 892 | if (__c == 0) |
| 893 | this->__set_failbit_and_consider_rethrow(); |
| 894 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 895 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 896 | } |
| 897 | else |
| 898 | this->setstate(ios_base::failbit); |
| 899 | __gc_ = __c; |
| 900 | } |
| 901 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 902 | } |
| 903 | catch (...) |
| 904 | { |
| 905 | this->__set_badbit_and_consider_rethrow(); |
| 906 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 907 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 908 | return *this; |
| 909 | } |
| 910 | |
| 911 | template<class _CharT, class _Traits> |
| 912 | typename basic_istream<_CharT, _Traits>::int_type |
| 913 | basic_istream<_CharT, _Traits>::get() |
| 914 | { |
| 915 | __gc_ = 0; |
| 916 | int_type __r = traits_type::eof(); |
| 917 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 918 | try |
| 919 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 920 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | sentry __s(*this, true); |
| 922 | if (__s) |
| 923 | { |
| 924 | streamsize __c = 0; |
| 925 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 926 | _I __i(*this); |
| 927 | _I __eof; |
| 928 | ios_base::iostate __err = ios_base::goodbit; |
| 929 | if (__i != __eof) |
| 930 | { |
| 931 | __r = traits_type::to_int_type(*__i); |
| 932 | ++__c; |
| 933 | if (++__i == __eof) |
| 934 | __err |= ios_base::eofbit; |
| 935 | } |
| 936 | else |
| 937 | __err |= ios_base::failbit | ios_base::eofbit; |
| 938 | this->setstate(__err); |
| 939 | __gc_ = __c; |
| 940 | } |
| 941 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 942 | } |
| 943 | catch (...) |
| 944 | { |
| 945 | this->__set_badbit_and_consider_rethrow(); |
| 946 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 947 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 948 | return __r; |
| 949 | } |
| 950 | |
| 951 | template<class _CharT, class _Traits> |
| 952 | inline _LIBCPP_INLINE_VISIBILITY |
| 953 | basic_istream<_CharT, _Traits>& |
| 954 | basic_istream<_CharT, _Traits>::get(char_type& __c) |
| 955 | { |
| 956 | int_type __ch = get(); |
| 957 | if (__ch != traits_type::eof()) |
| 958 | __c = traits_type::to_char_type(__ch); |
| 959 | return *this; |
| 960 | } |
| 961 | |
| 962 | template<class _CharT, class _Traits> |
| 963 | basic_istream<_CharT, _Traits>& |
| 964 | basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) |
| 965 | { |
| 966 | __gc_ = 0; |
| 967 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 968 | try |
| 969 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 970 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 971 | sentry __sen(*this, true); |
| 972 | if (__sen) |
| 973 | { |
| 974 | streamsize __c = 0; |
| 975 | if (__n > 0) |
| 976 | { |
| 977 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 978 | _I __i(*this); |
| 979 | _I __eof; |
| 980 | for (; __i != __eof && __n > 1; ++__i, ++__s, ++__c) |
| 981 | { |
| 982 | char_type __ch = *__i; |
| 983 | if (traits_type::eq(__ch, __dlm)) |
| 984 | break; |
| 985 | *__s = __ch; |
| 986 | } |
| 987 | *__s = char_type(); |
| 988 | ios_base::iostate __err = ios_base::goodbit; |
| 989 | if (__i == __eof) |
| 990 | __err |= ios_base::eofbit; |
| 991 | if (__c == 0) |
| 992 | __err |= ios_base::failbit; |
| 993 | this->setstate(__err); |
| 994 | } |
| 995 | else |
| 996 | this->setstate(ios_base::failbit); |
| 997 | __gc_ = __c; |
| 998 | } |
| 999 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1000 | } |
| 1001 | catch (...) |
| 1002 | { |
| 1003 | this->__set_badbit_and_consider_rethrow(); |
| 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 | return *this; |
| 1007 | } |
| 1008 | |
| 1009 | template<class _CharT, class _Traits> |
| 1010 | inline _LIBCPP_INLINE_VISIBILITY |
| 1011 | basic_istream<_CharT, _Traits>& |
| 1012 | basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n) |
| 1013 | { |
| 1014 | return get(__s, __n, this->widen('\n')); |
| 1015 | } |
| 1016 | |
| 1017 | template<class _CharT, class _Traits> |
| 1018 | basic_istream<_CharT, _Traits>& |
| 1019 | basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, |
| 1020 | char_type __dlm) |
| 1021 | { |
| 1022 | __gc_ = 0; |
| 1023 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1024 | try |
| 1025 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1026 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1027 | sentry __sen(*this, true); |
| 1028 | if (__sen) |
| 1029 | { |
| 1030 | streamsize __c = 0; |
| 1031 | ios_base::iostate __err = ios_base::goodbit; |
| 1032 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1033 | try |
| 1034 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1035 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1036 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 1037 | typedef ostreambuf_iterator<char_type, traits_type> _O; |
| 1038 | _I __i(*this); |
| 1039 | _I __eof; |
| 1040 | _O __o(&__sb); |
| 1041 | for (; __i != __eof; ++__i, ++__o, ++__c) |
| 1042 | { |
| 1043 | char_type __ch = *__i; |
| 1044 | if (traits_type::eq(__ch, __dlm)) |
| 1045 | break; |
| 1046 | *__o = __ch; |
| 1047 | if (__o.failed()) |
| 1048 | break; |
| 1049 | } |
| 1050 | if (__i == __eof) |
| 1051 | __err |= ios_base::eofbit; |
| 1052 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1053 | } |
| 1054 | catch (...) |
| 1055 | { |
| 1056 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1057 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | if (__c == 0) |
| 1059 | __err |= ios_base::failbit; |
| 1060 | this->setstate(__err); |
| 1061 | __gc_ = __c; |
| 1062 | } |
| 1063 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1064 | } |
| 1065 | catch (...) |
| 1066 | { |
| 1067 | this->__set_badbit_and_consider_rethrow(); |
| 1068 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1069 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1070 | return *this; |
| 1071 | } |
| 1072 | |
| 1073 | template<class _CharT, class _Traits> |
| 1074 | inline _LIBCPP_INLINE_VISIBILITY |
| 1075 | basic_istream<_CharT, _Traits>& |
| 1076 | basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb) |
| 1077 | { |
| 1078 | return get(__sb, this->widen('\n')); |
| 1079 | } |
| 1080 | |
| 1081 | template<class _CharT, class _Traits> |
| 1082 | basic_istream<_CharT, _Traits>& |
| 1083 | basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) |
| 1084 | { |
| 1085 | __gc_ = 0; |
| 1086 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1087 | try |
| 1088 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1089 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | sentry __sen(*this, true); |
| 1091 | if (__sen) |
| 1092 | { |
| 1093 | streamsize __c = 0; |
| 1094 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 1095 | _I __i(*this); |
| 1096 | _I __eof; |
| 1097 | for (; __i != __eof; ++__s, --__n) |
| 1098 | { |
| 1099 | char_type __ch = *__i; |
| 1100 | ++__i; |
| 1101 | ++__c; |
| 1102 | if (traits_type::eq(__ch, __dlm)) |
| 1103 | break; |
| 1104 | if (__n < 2) |
| 1105 | { |
| 1106 | this->setstate(ios_base::failbit); |
| 1107 | break; |
| 1108 | } |
| 1109 | *__s = __ch; |
| 1110 | } |
| 1111 | if (__n) |
| 1112 | *__s = char_type(); |
| 1113 | ios_base::iostate __err = ios_base::goodbit; |
| 1114 | if (__i == __eof) |
| 1115 | __err |= ios_base::eofbit; |
| 1116 | if (__c == 0) |
| 1117 | __err |= ios_base::failbit; |
| 1118 | this->setstate(__err); |
| 1119 | __gc_ = __c; |
| 1120 | } |
| 1121 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1122 | } |
| 1123 | catch (...) |
| 1124 | { |
| 1125 | this->__set_badbit_and_consider_rethrow(); |
| 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 | return *this; |
| 1129 | } |
| 1130 | |
| 1131 | template<class _CharT, class _Traits> |
| 1132 | inline _LIBCPP_INLINE_VISIBILITY |
| 1133 | basic_istream<_CharT, _Traits>& |
| 1134 | basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n) |
| 1135 | { |
| 1136 | return getline(__s, __n, this->widen('\n')); |
| 1137 | } |
| 1138 | |
| 1139 | template<class _CharT, class _Traits> |
| 1140 | basic_istream<_CharT, _Traits>& |
| 1141 | basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) |
| 1142 | { |
| 1143 | __gc_ = 0; |
| 1144 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1145 | try |
| 1146 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1147 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1148 | sentry __sen(*this, true); |
| 1149 | if (__sen) |
| 1150 | { |
| 1151 | streamsize __c = 0; |
| 1152 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 1153 | _I __i(*this); |
| 1154 | _I __eof; |
| 1155 | if (__n != numeric_limits<streamsize>::max()) |
| 1156 | { |
| 1157 | for (; __n > 0 && __i != __eof; --__n) |
| 1158 | { |
| 1159 | char_type __ch = *__i; |
| 1160 | ++__i; |
| 1161 | ++__c; |
| 1162 | if (traits_type::eq(__ch, __dlm)) |
| 1163 | break; |
| 1164 | } |
| 1165 | } |
| 1166 | else |
| 1167 | { |
| 1168 | while (__i != __eof) |
| 1169 | { |
| 1170 | char_type __ch = *__i; |
| 1171 | ++__i; |
| 1172 | ++__c; |
| 1173 | if (traits_type::eq(__ch, __dlm)) |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | if (__i == __eof) |
| 1178 | this->setstate(ios_base::eofbit); |
| 1179 | __gc_ = __c; |
| 1180 | } |
| 1181 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1182 | } |
| 1183 | catch (...) |
| 1184 | { |
| 1185 | this->__set_badbit_and_consider_rethrow(); |
| 1186 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1187 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1188 | return *this; |
| 1189 | } |
| 1190 | |
| 1191 | template<class _CharT, class _Traits> |
| 1192 | typename basic_istream<_CharT, _Traits>::int_type |
| 1193 | basic_istream<_CharT, _Traits>::peek() |
| 1194 | { |
| 1195 | __gc_ = 0; |
| 1196 | int_type __r = traits_type::eof(); |
| 1197 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1198 | try |
| 1199 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1200 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | sentry __sen(*this, true); |
| 1202 | if (__sen) |
| 1203 | __r = this->rdbuf()->sgetc(); |
| 1204 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1205 | } |
| 1206 | catch (...) |
| 1207 | { |
| 1208 | this->__set_badbit_and_consider_rethrow(); |
| 1209 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1210 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | return __r; |
| 1212 | } |
| 1213 | |
| 1214 | template<class _CharT, class _Traits> |
| 1215 | basic_istream<_CharT, _Traits>& |
| 1216 | basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) |
| 1217 | { |
| 1218 | __gc_ = 0; |
| 1219 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1220 | try |
| 1221 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1222 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | sentry __sen(*this, true); |
| 1224 | if (__sen) |
| 1225 | { |
| 1226 | streamsize __c = 0; |
| 1227 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 1228 | _I __i(*this); |
| 1229 | _I __eof; |
| 1230 | for (; __i != __eof && __n > 0; ++__i, ++__s, ++__c, --__n) |
| 1231 | *__s = *__i; |
| 1232 | if (__i == __eof) |
| 1233 | { |
| 1234 | ios_base::iostate __err = ios_base::eofbit; |
| 1235 | if (__n > 0) |
| 1236 | __err |= ios_base::failbit; |
| 1237 | this->setstate(__err); |
| 1238 | } |
| 1239 | __gc_ = __c; |
| 1240 | } |
| 1241 | else |
| 1242 | this->setstate(ios_base::failbit); |
| 1243 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1244 | } |
| 1245 | catch (...) |
| 1246 | { |
| 1247 | this->__set_badbit_and_consider_rethrow(); |
| 1248 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1249 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1250 | return *this; |
| 1251 | } |
| 1252 | |
| 1253 | template<class _CharT, class _Traits> |
| 1254 | streamsize |
| 1255 | basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) |
| 1256 | { |
| 1257 | __gc_ = 0; |
| 1258 | streamsize __c = 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 | typedef istreambuf_iterator<char_type, traits_type> _I; |
| 1267 | _I __i(*this); |
| 1268 | _I __eof; |
| 1269 | __c = this->rdbuf()->in_avail(); |
| 1270 | switch (__c) |
| 1271 | { |
| 1272 | case -1: |
| 1273 | __i = __eof; |
| 1274 | break; |
| 1275 | case 0: |
| 1276 | break; |
| 1277 | default: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1278 | __c = _VSTD::min(__c, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1279 | for (streamsize __k = 0; __k < __c; ++__k, ++__s, ++__i) |
| 1280 | *__s = *__i; |
| 1281 | } |
| 1282 | if (__i == __eof) |
| 1283 | this->setstate(ios_base::eofbit); |
| 1284 | __gc_ = __c; |
| 1285 | } |
| 1286 | else |
| 1287 | this->setstate(ios_base::failbit); |
| 1288 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1289 | } |
| 1290 | catch (...) |
| 1291 | { |
| 1292 | this->__set_badbit_and_consider_rethrow(); |
| 1293 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1294 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1295 | return __c; |
| 1296 | } |
| 1297 | |
| 1298 | template<class _CharT, class _Traits> |
| 1299 | basic_istream<_CharT, _Traits>& |
| 1300 | basic_istream<_CharT, _Traits>::putback(char_type __c) |
| 1301 | { |
| 1302 | __gc_ = 0; |
| 1303 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1304 | try |
| 1305 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1306 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1307 | sentry __sen(*this, true); |
| 1308 | if (__sen) |
| 1309 | { |
| 1310 | if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) |
| 1311 | this->setstate(ios_base::badbit); |
| 1312 | } |
| 1313 | else |
| 1314 | this->setstate(ios_base::failbit); |
| 1315 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1316 | } |
| 1317 | catch (...) |
| 1318 | { |
| 1319 | this->__set_badbit_and_consider_rethrow(); |
| 1320 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1321 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1322 | return *this; |
| 1323 | } |
| 1324 | |
| 1325 | template<class _CharT, class _Traits> |
| 1326 | basic_istream<_CharT, _Traits>& |
| 1327 | basic_istream<_CharT, _Traits>::unget() |
| 1328 | { |
| 1329 | __gc_ = 0; |
| 1330 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1331 | try |
| 1332 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1333 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | sentry __sen(*this, true); |
| 1335 | if (__sen) |
| 1336 | { |
| 1337 | if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof()) |
| 1338 | this->setstate(ios_base::badbit); |
| 1339 | } |
| 1340 | else |
| 1341 | this->setstate(ios_base::failbit); |
| 1342 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1343 | } |
| 1344 | catch (...) |
| 1345 | { |
| 1346 | this->__set_badbit_and_consider_rethrow(); |
| 1347 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1348 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1349 | return *this; |
| 1350 | } |
| 1351 | |
| 1352 | template<class _CharT, class _Traits> |
| 1353 | int |
| 1354 | basic_istream<_CharT, _Traits>::sync() |
| 1355 | { |
| 1356 | int __r = 0; |
| 1357 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1358 | try |
| 1359 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1360 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 | sentry __sen(*this, true); |
| 1362 | if (__sen) |
| 1363 | { |
| 1364 | if (this->rdbuf() == 0) |
| 1365 | return -1; |
| 1366 | if (this->rdbuf()->pubsync() == -1) |
| 1367 | { |
| 1368 | this->setstate(ios_base::badbit); |
| 1369 | return -1; |
| 1370 | } |
| 1371 | } |
| 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 __r; |
| 1380 | } |
| 1381 | |
| 1382 | template<class _CharT, class _Traits> |
| 1383 | typename basic_istream<_CharT, _Traits>::pos_type |
| 1384 | basic_istream<_CharT, _Traits>::tellg() |
| 1385 | { |
| 1386 | pos_type __r(-1); |
| 1387 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1388 | try |
| 1389 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1390 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | sentry __sen(*this, true); |
| 1392 | if (__sen) |
| 1393 | __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); |
| 1394 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1395 | } |
| 1396 | catch (...) |
| 1397 | { |
| 1398 | this->__set_badbit_and_consider_rethrow(); |
| 1399 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1400 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | return __r; |
| 1402 | } |
| 1403 | |
| 1404 | template<class _CharT, class _Traits> |
| 1405 | basic_istream<_CharT, _Traits>& |
| 1406 | basic_istream<_CharT, _Traits>::seekg(pos_type __pos) |
| 1407 | { |
| 1408 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1409 | try |
| 1410 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1411 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1412 | sentry __sen(*this, true); |
| 1413 | if (__sen) |
| 1414 | if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) |
| 1415 | this->setstate(ios_base::failbit); |
| 1416 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1417 | } |
| 1418 | catch (...) |
| 1419 | { |
| 1420 | this->__set_badbit_and_consider_rethrow(); |
| 1421 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1422 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | return *this; |
| 1424 | } |
| 1425 | |
| 1426 | template<class _CharT, class _Traits> |
| 1427 | basic_istream<_CharT, _Traits>& |
| 1428 | basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) |
| 1429 | { |
| 1430 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1431 | try |
| 1432 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1433 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1434 | sentry __sen(*this, true); |
| 1435 | if (__sen) |
| 1436 | this->rdbuf()->pubseekoff(__off, __dir, ios_base::in); |
| 1437 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1438 | } |
| 1439 | catch (...) |
| 1440 | { |
| 1441 | this->__set_badbit_and_consider_rethrow(); |
| 1442 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1443 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1444 | return *this; |
| 1445 | } |
| 1446 | |
| 1447 | template <class _CharT, class _Traits> |
| 1448 | basic_istream<_CharT, _Traits>& |
| 1449 | ws(basic_istream<_CharT, _Traits>& __is) |
| 1450 | { |
| 1451 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1452 | try |
| 1453 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1454 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); |
| 1456 | if (__sen) |
| 1457 | { |
| 1458 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 1459 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
| 1460 | _I __i(__is); |
| 1461 | _I __eof; |
| 1462 | for (; __i != __eof; ++__i) |
| 1463 | if (!__ct.is(__ct.space, *__i)) |
| 1464 | break; |
| 1465 | if (__i == __eof) |
| 1466 | __is.setstate(ios_base::failbit | ios_base::eofbit); |
| 1467 | } |
| 1468 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1469 | } |
| 1470 | catch (...) |
| 1471 | { |
| 1472 | __is.__set_badbit_and_consider_rethrow(); |
| 1473 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1474 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | return __is; |
| 1476 | } |
| 1477 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1478 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | |
| 1480 | template <class _CharT, class _Traits, class _Tp> |
| 1481 | inline _LIBCPP_INLINE_VISIBILITY |
| 1482 | basic_istream<_CharT, _Traits>& |
| 1483 | operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) |
| 1484 | { |
| 1485 | __is >> __x; |
| 1486 | return __is; |
| 1487 | } |
| 1488 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1489 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | |
| 1491 | template <class _CharT, class _Traits> |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 1492 | class _LIBCPP_VISIBLE basic_iostream |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1493 | : public basic_istream<_CharT, _Traits>, |
| 1494 | public basic_ostream<_CharT, _Traits> |
| 1495 | { |
| 1496 | public: |
| 1497 | // types: |
| 1498 | typedef _CharT char_type; |
| 1499 | typedef _Traits traits_type; |
| 1500 | typedef typename traits_type::int_type int_type; |
| 1501 | typedef typename traits_type::pos_type pos_type; |
| 1502 | typedef typename traits_type::off_type off_type; |
| 1503 | |
| 1504 | // constructor/destructor |
| 1505 | explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb); |
| 1506 | virtual ~basic_iostream(); |
| 1507 | protected: |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1508 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 +0000 | [diff] [blame^] | 1509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1510 | basic_iostream(basic_iostream&& __rhs); |
| 1511 | #endif |
| 1512 | |
| 1513 | // assign/swap |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1514 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 +0000 | [diff] [blame^] | 1515 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1516 | basic_iostream& operator=(basic_iostream&& __rhs); |
| 1517 | #endif |
| 1518 | void swap(basic_iostream& __rhs); |
| 1519 | public: |
| 1520 | }; |
| 1521 | |
| 1522 | template <class _CharT, class _Traits> |
| 1523 | inline _LIBCPP_INLINE_VISIBILITY |
| 1524 | basic_iostream<_CharT, _Traits>::basic_iostream(basic_streambuf<char_type, traits_type>* __sb) |
| 1525 | : basic_istream<_CharT, _Traits>(__sb) |
| 1526 | { |
| 1527 | } |
| 1528 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1529 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | |
| 1531 | template <class _CharT, class _Traits> |
| 1532 | inline _LIBCPP_INLINE_VISIBILITY |
| 1533 | basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1534 | : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | { |
| 1536 | } |
| 1537 | |
| 1538 | template <class _CharT, class _Traits> |
| 1539 | inline _LIBCPP_INLINE_VISIBILITY |
| 1540 | basic_iostream<_CharT, _Traits>& |
| 1541 | basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs) |
| 1542 | { |
| 1543 | swap(__rhs); |
| 1544 | return *this; |
| 1545 | } |
| 1546 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1547 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1548 | |
| 1549 | template <class _CharT, class _Traits> |
| 1550 | basic_iostream<_CharT, _Traits>::~basic_iostream() |
| 1551 | { |
| 1552 | } |
| 1553 | |
| 1554 | template <class _CharT, class _Traits> |
| 1555 | inline _LIBCPP_INLINE_VISIBILITY |
| 1556 | void |
| 1557 | basic_iostream<_CharT, _Traits>::swap(basic_iostream& __rhs) |
| 1558 | { |
| 1559 | basic_istream<char_type, traits_type>::swap(__rhs); |
| 1560 | } |
| 1561 | |
| 1562 | template<class _CharT, class _Traits, class _Allocator> |
| 1563 | basic_istream<_CharT, _Traits>& |
| 1564 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 1565 | basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1566 | { |
| 1567 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1568 | try |
| 1569 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1570 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1571 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 1572 | if (__sen) |
| 1573 | { |
| 1574 | __str.clear(); |
| 1575 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 1576 | streamsize __n = __is.width(); |
| 1577 | if (__n == 0) |
| 1578 | __n = __str.max_size(); |
| 1579 | if (__n < 0) |
| 1580 | __n = numeric_limits<streamsize>::max(); |
| 1581 | streamsize __c = 0; |
| 1582 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
| 1583 | _I __i(__is); |
| 1584 | _I __eof; |
| 1585 | for (; __i != __eof && __c < __n; ++__i, ++__c) |
| 1586 | { |
| 1587 | _CharT __ch = *__i; |
| 1588 | if (__ct.is(__ct.space, __ch)) |
| 1589 | break; |
| 1590 | __str.push_back(__ch); |
| 1591 | } |
| 1592 | __is.width(0); |
| 1593 | ios_base::iostate __err = ios_base::goodbit; |
| 1594 | if (__i == __eof) |
| 1595 | __err |= ios_base::eofbit; |
| 1596 | if (__c == 0) |
| 1597 | __err |= ios_base::failbit; |
| 1598 | __is.setstate(__err); |
| 1599 | } |
| 1600 | else |
| 1601 | __is.setstate(ios_base::failbit); |
| 1602 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1603 | } |
| 1604 | catch (...) |
| 1605 | { |
| 1606 | __is.__set_badbit_and_consider_rethrow(); |
| 1607 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1608 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1609 | return __is; |
| 1610 | } |
| 1611 | |
| 1612 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1613 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1614 | getline(basic_istream<_CharT, _Traits>& __is, |
| 1615 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) |
| 1616 | { |
| 1617 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1618 | try |
| 1619 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1620 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); |
| 1622 | if (__sen) |
| 1623 | { |
| 1624 | __str.clear(); |
| 1625 | streamsize __c = 0; |
| 1626 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 1627 | _I __i(__is); |
| 1628 | _I __eof; |
| 1629 | streamsize __n = __str.max_size(); |
| 1630 | if (__n < 0) |
| 1631 | __n = numeric_limits<streamsize>::max(); |
| 1632 | for (; __i != __eof;) |
| 1633 | { |
| 1634 | _CharT __ch = *__i; |
| 1635 | ++__i; |
| 1636 | ++__c; |
| 1637 | if (_Traits::eq(__ch, __dlm)) |
| 1638 | break; |
| 1639 | if (__c == __n) |
| 1640 | { |
| 1641 | __is.setstate(ios_base::failbit); |
| 1642 | break; |
| 1643 | } |
| 1644 | __str.push_back(__ch); |
| 1645 | } |
| 1646 | ios_base::iostate __err = ios_base::goodbit; |
| 1647 | if (__i == __eof) |
| 1648 | __err |= ios_base::eofbit; |
| 1649 | if (__c == 0) |
| 1650 | __err |= ios_base::failbit; |
| 1651 | __is.setstate(__err); |
| 1652 | } |
| 1653 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1654 | } |
| 1655 | catch (...) |
| 1656 | { |
| 1657 | __is.__set_badbit_and_consider_rethrow(); |
| 1658 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1659 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | return __is; |
| 1661 | } |
| 1662 | |
| 1663 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 1664 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1665 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1666 | getline(basic_istream<_CharT, _Traits>& __is, |
| 1667 | basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1668 | { |
| 1669 | return getline(__is, __str, __is.widen('\n')); |
| 1670 | } |
| 1671 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1672 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1673 | |
| 1674 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 1675 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1676 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1677 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 1678 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) |
| 1679 | { |
| 1680 | return getline(__is, __str, __dlm); |
| 1681 | } |
| 1682 | |
| 1683 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 1684 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1685 | basic_istream<_CharT, _Traits>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 1687 | basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1688 | { |
| 1689 | return getline(__is, __str, __is.widen('\n')); |
| 1690 | } |
| 1691 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1692 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | |
| 1694 | template <class _CharT, class _Traits, size_t _Size> |
| 1695 | basic_istream<_CharT, _Traits>& |
| 1696 | operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) |
| 1697 | { |
| 1698 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1699 | try |
| 1700 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1701 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | typename basic_istream<_CharT, _Traits>::sentry __sen(__is); |
| 1703 | if (__sen) |
| 1704 | { |
| 1705 | basic_string<_CharT, _Traits> __str; |
| 1706 | const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); |
| 1707 | typedef istreambuf_iterator<_CharT, _Traits> _I; |
| 1708 | streamsize __c = 0; |
| 1709 | _CharT __zero = __ct.widen('0'); |
| 1710 | _CharT __one = __ct.widen('1'); |
| 1711 | _I __i(__is); |
| 1712 | _I __eof; |
| 1713 | for (; __i != __eof && __c < _Size; ++__i, ++__c) |
| 1714 | { |
| 1715 | _CharT __ch = *__i; |
| 1716 | if (__ch != __zero && __ch != __one) |
| 1717 | break; |
| 1718 | __str.push_back(__ch); |
| 1719 | } |
| 1720 | __is.width(0); |
| 1721 | __x = bitset<_Size>(__str); |
| 1722 | ios_base::iostate __err = ios_base::goodbit; |
| 1723 | if (__i == __eof) |
| 1724 | __err |= ios_base::eofbit; |
| 1725 | if (__c == 0) |
| 1726 | __err |= ios_base::failbit; |
| 1727 | __is.setstate(__err); |
| 1728 | } |
| 1729 | else |
| 1730 | __is.setstate(ios_base::failbit); |
| 1731 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1732 | } |
| 1733 | catch (...) |
| 1734 | { |
| 1735 | __is.__set_badbit_and_consider_rethrow(); |
| 1736 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1737 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | return __is; |
| 1739 | } |
| 1740 | |
| 1741 | extern template class basic_istream<char>; |
| 1742 | extern template class basic_istream<wchar_t>; |
| 1743 | extern template class basic_iostream<char>; |
| 1744 | |
| 1745 | _LIBCPP_END_NAMESPACE_STD |
| 1746 | |
| 1747 | #endif // _LIBCPP_ISTREAM |