// Have we reached EOF now? If so, set at_eof_ and return early,
// but don't modify buffer_pos_ (which should still be equal to
// the size of buffer_).
- if (!input_.good()) {
+ if (input_.eof()) {
at_eof_ = true;
return (END_OF_STREAM);
}
+ // This has to come after the .eof() check as some
+ // implementations seem to check the eofbit also in .fail().
+ if (input_.fail()) {
+ isc_throw(ReadError,
+ "Error reading from the input stream: " << getName());
+ }
buffer_.push_back(c);
}
{}
};
+ /// \brief Exception thrown when we fail to read from the input
+ /// stream or file.
+ struct ReadError : public Unexpected {
+ ReadError(const char* file, size_t line, const char* what) :
+ Unexpected(file, line, what)
+ {}
+ };
+
/// \brief Returned by getChar() when end of stream is reached.
static const int END_OF_STREAM;
/// \brief Returns a single character from the input source. If end
/// of file is reached, \c END_OF_STREAM is returned.
+ ///
+ /// \throws ReadError when reading from the input stream or file
+ /// fails.
int getChar();
/// \brief Skips backward a single character in the input