mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Change API of raw_istream to be more similar to raw_ostream.
This commit is contained in:
@@ -16,21 +16,37 @@ class raw_istream {
|
||||
public:
|
||||
raw_istream() = default;
|
||||
virtual ~raw_istream() = default;
|
||||
virtual bool read(void* data, std::size_t len) = 0;
|
||||
|
||||
raw_istream& read(void* data, std::size_t len) {
|
||||
read_impl(data, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual void close() = 0;
|
||||
|
||||
bool has_error() const { return m_error; }
|
||||
void clear_error() { m_error = false; }
|
||||
|
||||
raw_istream(const raw_istream&) = delete;
|
||||
raw_istream& operator=(const raw_istream&) = delete;
|
||||
|
||||
protected:
|
||||
void error_detected() { m_error = true; }
|
||||
|
||||
private:
|
||||
virtual void read_impl(void* data, std::size_t len) = 0;
|
||||
|
||||
bool m_error = false;
|
||||
};
|
||||
|
||||
class raw_mem_istream : public raw_istream {
|
||||
public:
|
||||
raw_mem_istream(const char* mem, std::size_t len) : m_cur(mem), m_left(len) {}
|
||||
virtual ~raw_mem_istream() = default;
|
||||
virtual bool read(void* data, std::size_t len);
|
||||
virtual void close() {}
|
||||
void close() override;
|
||||
|
||||
private:
|
||||
void read_impl(void* data, std::size_t len) override;
|
||||
|
||||
const char* m_cur;
|
||||
std::size_t m_left;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user