예제 #1
0
  //! Loads file into the memory. Data will be automatically destroyed by the
  // destructor
  //! \param stream Stream to load from
  file(std::basic_istream<Ch> &stream) {
    using namespace std;

    // Load data and add terminating 0
    stream.unsetf(ios::skipws);
    m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
    if (stream.fail() || stream.bad())
      throw runtime_error("error reading stream");
    m_data.push_back(0);
  }
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;
}
예제 #3
0
int Buffer::pushBytesFromStream(std::basic_istream<char>& istr, int cnt)
{
    if (writeAvailable() < cnt)
        cnt = writeAvailable();

    istr.read((char*)_tail, cnt);
    if (istr.eof())
    {
        cnt = istr.gcount();
    }
    else if (istr.fail())
    {
        return -1;
    }
    _tail += cnt;
    return cnt;
}