inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, time_duration& td) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<time_input_facet>(is.getloc())) { std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, td); } else { time_input_facet* f = new time_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, td); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; }
inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, local_date_time& ldt) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename local_date_time::utc_time_type utc_time_type; typedef typename date_time::time_input_facet<utc_time_type, CharT> time_input_facet; // intermediate objects std::basic_string<CharT> tz_str; utc_time_type pt(not_a_date_time); std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<time_input_facet>(is.getloc())) { std::use_facet<time_input_facet>(is.getloc()).get_local_time(sit, str_end, is, pt, tz_str); } else { time_input_facet* f = new time_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get_local_time(sit, str_end, is, pt, tz_str); } if(tz_str.empty()) { time_zone_ptr null_ptr; // a null time_zone_ptr creates a local_date_time that is UTC ldt = local_date_time(pt, null_ptr); } else { time_zone_ptr tz_ptr(new posix_time_zone(date_time::convert_string_type<CharT,char>(tz_str))); // the "date & time" constructor expects the time label to *not* be utc. // a posix_tz_string also expects the time label to *not* be utc. ldt = local_date_time(pt.date(), pt.time_of_day(), tz_ptr, local_date_time::EXCEPTION_ON_ERROR); } } catch(...) { // mask tells us what exceptions are turned on std::ios_base::iostate exception_mask = is.exceptions(); // if the user wants exceptions on failbit, we'll rethrow our // date_time exception & set the failbit if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} // ignore this one throw; // rethrow original exception } else { // if the user want's to fail quietly, we simply set the failbit is.setstate(std::ios_base::failbit); } } } return is; }
std::basic_istream<stream_char_type, stream_char_traits> & operator >>(std::basic_istream<stream_char_type, stream_char_traits> & is, basic_string_facade<storage, char_traits> & str) { typedef std::ctype<stream_char_type> ctype_type; typedef std::basic_istream<stream_char_type, stream_char_traits> istream_type; typedef ext::basic_string_facade<storage, char_traits> string_type; typedef typename string_type::size_type size_type; std::ios_base::iostate state = std::ios_base::goodbit; const typename istream_type::sentry ok(is); if (ok) { const auto & lc = is.getloc(); auto * buf = is.rdbuf(); const ctype_type & ctype_fac = std::use_facet<ctype_type>(lc); str.clear(); std::streamsize w = is.width(); size_type size = 0 < w && static_cast<size_type>(w) < str.max_size() ? w : str.max_size(); try { auto meta = buf->sgetc(); for (; 0 < size; --size, meta = buf->snextc()) { if (stream_char_traits::eq_int_type(stream_char_traits::eof(), meta)) { // end of file state |= std::ios_base::eofbit; break; } auto ch = stream_char_traits::to_char_type(meta); if (ctype_fac.is(ctype_type::space, ch)) { break; } str.push_back(ch); } // for } catch (...) { is.setstate(std::ios::badbit); } } // if ok is.width(0); if (str.empty()) // read nothing state |= std::ios_base::failbit; is.setstate(state); return is; }
std::basic_istream<ch, char_traits>& operator>>(std::basic_istream<ch, char_traits> &is, uuid &u) { const typename std::basic_istream<ch, char_traits>::sentry ok(is); if (ok) { unsigned char data[16]; typedef std::ctype<ch> ctype_t; ctype_t const& ctype = std::use_facet<ctype_t>(is.getloc()); ch xdigits[16]; { char szdigits[] = "0123456789ABCDEF"; ctype.widen(szdigits, szdigits+16, xdigits); } ch*const xdigits_end = xdigits+16; ch c; for (std::size_t i=0; i<u.size() && is; ++i) { is >> c; c = ctype.toupper(c); ch* f = std::find(xdigits, xdigits_end, c); if (f == xdigits_end) { is.setstate(std::ios_base::failbit); break; } unsigned char byte = static_cast<unsigned char>(std::distance(&xdigits[0], f)); is >> c; c = ctype.toupper(c); f = std::find(xdigits, xdigits_end, c); if (f == xdigits_end) { is.setstate(std::ios_base::failbit); break; } byte <<= 4; byte |= static_cast<unsigned char>(std::distance(&xdigits[0], f)); data[i] = byte; if (is) { if (i == 3 || i == 5 || i == 7 || i == 9) { is >> c; if (c != is.widen('-')) is.setstate(std::ios_base::failbit); } } } if (is) { std::copy(data, data+16, u.begin()); } }
inline std::basic_istream<Elem, Traits>& operator>>(std::basic_istream<Elem, Traits>& lhs, sprout::uuids::uuid& rhs) { typedef typename std::basic_ios<Elem, Traits>::char_type char_type; typename std::basic_istream<Elem, Traits>::sentry const ok(lhs); typedef std::ctype<Elem> ctype_type; if (ok) { sprout::uuids::uuid::value_type data[16]; ctype_type const& ctype = std::use_facet<ctype_type>(lhs.getloc()); char_type xdigits[16]; { char const szdigits[] = "0123456789ABCDEF"; ctype.widen(szdigits, szdigits + 16, xdigits); } char_type const* const xdigits_end = xdigits + 16; char_type c; for (sprout::uuids::uuid::size_type i = 0, last = rhs.size(); i < last && lhs; ++i) { lhs >> c; c = ctype.toupper(c); char_type const* f = std::find(xdigits, xdigits_end, c); if (f == xdigits_end) { lhs.setstate(std::ios_base::failbit); break; } sprout::uuids::uuid::value_type byte = static_cast<sprout::uuids::uuid::value_type>(std::distance(&xdigits[0], f)); lhs >> c; c = ctype.toupper(c); f = std::find(xdigits, xdigits_end, c); if (f == xdigits_end) { lhs.setstate(std::ios_base::failbit); break; } byte <<= 4; byte |= static_cast<sprout::uuids::uuid::value_type>(std::distance(&xdigits[0], f)); data[i] = byte; if (lhs) { if (i == 3 || i == 5 || i == 7 || i == 9) { lhs >> c; if (c != lhs.widen('-')) { lhs.setstate(std::ios_base::failbit); break; } } } } if (lhs) { std::copy(data, data + 16, rhs.begin()); } }
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, const e& cliteral) { e buffer(0); //get buffer in >> buffer; //read data if (buffer != cliteral) //if it failed in.setstate(in.rdstate() | std::ios::badbit); //set the state return in; }
std::basic_istream<charT, traits> & operator >> ( std::basic_istream<charT, traits> & s, boolean & b ) { std::string word; s >> word; std::transform(word.begin(), word.end(), word.begin(), ::tolower); if ( s ) { if ( word == "true" || word == "yes" || word == "on" || word == "1") { b = true; } else if ( word == "false" || word == "no" || word == "off" || word == "0") { b = false; } else { s.setstate( std::ios::failbit ); } } return s; }
std::basic_istream<_CharT, _Traits> & operator>>(std::basic_istream<_CharT, _Traits> & __is, const get_time_manip<_CharT> & __x) { if (!reinterpret_cast<stream_buf_impl<_CharT, _Traits> *>(__is.rdbuf())->parse(__x)) __is.setstate(std::ios_base::failbit); return __is; }
inline SPROUT_NON_CONSTEXPR std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& lhs, sprout::bitset<N>& rhs) { typedef typename Traits::char_type char_type; typedef std::basic_istream<Char, Traits> istream_type; typedef typename istream_type::ios_base ios_base; std::basic_string<Char, Traits> tmp; tmp.reserve(N); char_type const zero = lhs.widen('0'); char_type const one = lhs.widen('1'); typename ios_base::iostate state = ios_base::goodbit; typename istream_type::sentry sentry(lhs); if (sentry) { try { for (std::size_t i = N; i > 0; --i) { static typename Traits::int_type eof = Traits::eof(); typename Traits::int_type c1 = lhs.rdbuf()->sbumpc(); if (Traits::eq_int_type(c1, eof)) { state |= ios_base::eofbit; break; } else { char_type const c2 = Traits::to_char_type(c1); if (Traits::eq(c2, zero)) { tmp.push_back(zero); } else if (Traits::eq(c2, one)) { tmp.push_back(one); } else if (Traits::eq_int_type(lhs.rdbuf()->sputbackc(c2), eof)) { state |= ios_base::failbit; break; } } } } catch(...) { lhs.setstate(ios_base::badbit); } } if (tmp.empty() && N) { state |= ios_base::failbit; } else { rhs.copy_from_string(tmp, static_cast<std::size_t>(0), N, zero, one); if (state) { lhs.setstate(state); return lhs; } } return lhs; }
inline bool equal( std::basic_istream< charT, traits >& is, charT const& should_be ){ auto result = test(is, should_be); if(!result) is.setstate(std::ios_base::failbit); return result; }
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, const e(&sliteral)[N]) { e buffer[N-1] = {}; //get buffer in >> buffer[0]; //skips whitespace if (N>2) in.read(buffer+1, N-2); //read the rest if (strncmp(buffer, sliteral, N-1)) //if it failed in.setstate(in.rdstate() | std::ios::badbit); //set the state return in; }
inline bool equal( std::basic_istream< charT, traits >& is, ShouldBe const& should_be ){ ShouldBe in; if(is && is >> in && in == should_be) return true; is.setstate(std::ios_base::failbit); return false; }
std::basic_istream< CharT, TraitsT >& operator>> (std::basic_istream< CharT, TraitsT >& strm, point& p) { if (strm.good()) { CharT left_brace = static_cast< CharT >(0), comma = static_cast< CharT >(0), right_brace = static_cast< CharT >(0); strm.setf(std::ios_base::skipws); strm >> left_brace >> p.m_x >> comma >> p.m_y >> right_brace; if (left_brace != '(' || comma != ',' || right_brace != ')') strm.setstate(std::ios_base::failbit); }
inline SPROUT_NON_CONSTEXPR std::basic_istream<Elem, Traits>& operator>>(std::basic_istream<Elem, Traits>& lhs, sprout::math::quaternion<T>& rhs) { std::ctype<Elem> const& ct = std::use_facet<std::ctype<Elem> >(lhs.getloc()); T a = T(); T b = T(); T c = T(); T d = T(); sprout::complex<T> u = sprout::complex<T>(); sprout::complex<T> v = sprout::complex<T>(); Elem ch = Elem(); char cc; lhs >> ch; if (!lhs.good()) { goto finish; } cc = ct.narrow(ch, char()); if (cc == '(') { lhs >> ch; if (!lhs.good()) { goto finish; } cc = ct.narrow(ch, char()); if (cc == '(') { lhs.putback(ch); lhs >> u; a = u.real(); b = u.imag(); if (!lhs.good()) { goto finish; } lhs >> ch; if (!lhs.good()) { goto finish; } cc = ct.narrow(ch, char()); if (cc == ')') { rhs = sprout::math::quaternion<T>(a, b); } else if (cc == ',') { lhs >> v; c = v.real(); d = v.imag(); if (!lhs.good()) { goto finish; } lhs >> ch; if (!lhs.good()) { goto finish; } cc = ct.narrow(ch, char()); if (cc == ')') { rhs = sprout::math::quaternion<T>(a, b, c, d); } else { lhs.setstate(std::ios_base::failbit); } } else {
std::basic_istream<CharT>& operator >> (std::basic_istream<CharT>& is, enum_base<D, V>& rhs) { std::basic_string<CharT> str; is >> str; BOOST_DEDUCED_TYPENAME D::optional ret = D::get_by_name(str.c_str()); if(ret) rhs = *ret; else is.setstate(std::ios::badbit); return is; }
inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, ptime& pt) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::time_input_facet<ptime, CharT> time_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<time_input_facet>(is.getloc())) { std::use_facet<time_input_facet>(is.getloc()).get(sit, str_end, is, pt); } else { time_input_facet* f = new time_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, pt); } } catch(...) { // mask tells us what exceptions are turned on std::ios_base::iostate exception_mask = is.exceptions(); // if the user wants exceptions on failbit, we'll rethrow our // date_time exception & set the failbit if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} // ignore this one throw; // rethrow original exception } else { // if the user want's to fail quietly, we simply set the failbit is.setstate(std::ios_base::failbit); } } } return is; }
inline std::basic_istream<char_t, traits_t>& operator>>(std::basic_istream<char_t, traits_t>& is, player_class_def_t& cl) { std::basic_string<char_t, traits_t> buff; std::getline(is, buff, ';'); { std::basic_istringstream<char_t> iss(buff); iss>>cl.skin_id; if (iss.fail() || !iss.eof()) { is.setstate(std::ios_base::failbit); } } std::getline(is, buff); return is; }
std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& in, uint8_t& target) { uint32_t value = 0xdecea5edU; in >> value; if (!in && value == 0xdecea5edU) return in; if (value > uint8_t(~0)) { in.setstate(std::ios::failbit); value = ~0U; } target = uint8_t(value); return in; }
inline std::basic_istream<char_t, traits_t>& operator>>(std::basic_istream<char_t, traits_t>& is, std::tr1::basic_regex<char_t, rx_traits_t>& regex) { std::basic_string<char_t, traits_t> buff; std::getline(is, buff); if (!is.fail()) { try { regex.assign(buff); } catch (std::exception const&) { assert(false); is.setstate(std::ios_base::failbit); } } return is; }
std::basic_istream<CharT, CharTraits> & operator>>(std::basic_istream<CharT, CharTraits> &in, Square &sq) { if (!in.good()) return in; CharT file_ch; if (!in.get(file_ch)) return in; if (file_ch < CharT{'a'} || file_ch > CharT{'h'}) { in.setstate(std::basic_istream<CharT, CharTraits>::failbit); return in; } CharT rank_ch; if (!in.get(rank_ch)) return in; if (rank_ch < CharT{'1'} || rank_ch > CharT{'8'}) { in.setstate(std::basic_istream<CharT, CharTraits>::failbit); return in; } sq = Square((std::uint8_t((rank_ch - CharT{'1'}) & 7) << 3) | (std::uint8_t((file_ch - CharT{'a'}) & 7))); return in; }
inline SPROUT_NON_CONSTEXPR std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& lhs, sprout::complex<T>& rhs) { T re, im; Char ch; lhs >> ch; if (ch == '(') { lhs >> re >> ch; if (ch == ',') { lhs >> im >> ch; if (ch == ')') { rhs = sprout::complex<T>(re, im); } else { lhs.setstate(std::ios_base::failbit); } } else if (ch == ')') {
inline SPROUT_NON_CONSTEXPR std::basic_istream<T, StreamTraits>& operator>>(std::basic_istream<T, StreamTraits>& lhs, sprout::basic_string<T, N, Traits>& rhs) { typedef T elem_type; typedef StreamTraits traits_type; typedef std::basic_istream<T, StreamTraits> istream_type; typedef sprout::basic_string<T, N, Traits> string_type; typedef std::ctype<elem_type> ctype_type; typedef typename string_type::size_type size_type; std::ios_base::iostate state = std::ios_base::goodbit; bool changed = false; size_type current = 0; if (typename istream_type::sentry(lhs)) { ctype_type const& ctype_fac = std::use_facet<ctype_type>(lhs.getloc()); try { size_type remain = 0 < lhs.width() && static_cast<size_type>(lhs.width()) < rhs.max_size() ? static_cast<size_type>(lhs.width()) : rhs.max_size() ; typename traits_type::int_type meta = lhs.rdbuf()->sgetc(); for (; remain; --remain, meta = lhs.rdbuf()->snextc()) if (traits_type::eq_int_type(traits_type::eof(), meta)) { state |= std::ios_base::eofbit; break; } else if (ctype_fac.is(ctype_type::space, traits_type::to_char_type(meta))) { break; } else { rhs[current] = traits_type::to_char_type(meta); changed = true; ++current; } } catch (...) { state |= std::ios_base::badbit; } } lhs.width(0); if (!changed) { state |= std::ios_base::failbit; } lhs.setstate(state); rhs.resize(current); return lhs; }
std::basic_istream<CharT,Traits>& operator>>(std::basic_istream<CharT,Traits>& in, pcg128_t& value) { typename std::basic_istream<CharT,Traits>::sentry s(in); if (!s) return in; constexpr auto BASE = pcg128_t(10ULL); pcg128_t current(0ULL); bool did_nothing = true; bool overflow = false; for(;;) { CharT wide_ch = in.get(); if (!in.good()) break; auto ch = in.narrow(wide_ch, '\0'); if (ch < '0' || ch > '9') { in.unget(); break; } did_nothing = false; pcg128_t digit(uint32_t(ch - '0')); pcg128_t timesbase = current*BASE; overflow = overflow || timesbase < current; current = timesbase + digit; overflow = overflow || current < digit; } if (did_nothing || overflow) { in.setstate(std::ios::failbit); if (overflow) current = ~pcg128_t(0ULL); } value = current; return in; }
std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d) { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; typedef duration_punct<CharT> Facet; std::locale loc = is.getloc(); //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; if (!std::has_facet<Facet>(loc)) { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; is.imbue(std::locale(loc, new Facet)); } //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; loc = is.getloc(); const Facet& f = std::use_facet<Facet>(loc); typedef typename chrono_detail::duration_io_intermediate<Rep>::type intermediate_type; intermediate_type r; std::ios_base::iostate err = std::ios_base::goodbit; // read value into r //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; is >> r; //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; if (is.good()) { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; // now determine unit typedef std::istreambuf_iterator<CharT, Traits> in_iterator; in_iterator i(is); in_iterator e; //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; if (i != e && *i == ' ') // mandatory ' ' after value { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; ++i; if (i != e) { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; // unit is num / den (yet to be determined) unsigned long long num = 0; unsigned long long den = 0; if (*i == '[') { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; // parse [N/D]s or [N/D]seconds format ++i; CharT x; is >> num >> x >> den; if (!is.good() || (x != '/')) { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; is.setstate(is.failbit); return is; } i = in_iterator(is); if (*i != ']') { //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; is.setstate(is.failbit); return is; } ++i; const std::basic_string<CharT> units[] = { f.template singular<ratio<1> >(), f.template plural<ratio<1> >(), f.template short_name<ratio<1> >() }; //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; const std::basic_string<CharT>* k = chrono_detail::scan_keyword(i, e, units, units + sizeof(units)/sizeof(units[0]), //~ std::use_facet<std::ctype<CharT> >(loc), err); //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; is.setstate(err); switch ((k - units) / 3) { case 0: //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; break; default: is.setstate(err); //std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; return is; } } else {