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