Skip to content

Commit

Permalink
Common: in Stream class remove virtual overrides without implementation
Browse files Browse the repository at this point in the history
This prevents numerous warnings in stricter compilers.
  • Loading branch information
ivan-mogilko committed Dec 20, 2023
1 parent ff5e686 commit 9ddd7e5
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions Common/util/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class IStream
// - on failure, returns -1
virtual int32_t WriteByte(uint8_t b) = 0;
// Seeks to offset from the origin
virtual bool Seek(soff_t offset, StreamSeek origin) = 0;
virtual bool Seek(soff_t offset, StreamSeek origin = kSeekCurrent) = 0;
// Flush stream buffer to the underlying device
virtual bool Flush() = 0;
// Closes the stream
Expand Down Expand Up @@ -126,46 +126,29 @@ class Stream : public IStream
//-----------------------------------------------------
// Helpers for learning the stream's state and capabilities
//-----------------------------------------------------

// Tells if stream is functional, and which operations are supported
bool IsValid() const { return GetMode() != kStream_None; }
bool CanRead() const { return (GetMode() & kStream_Read) != 0; }
bool CanWrite() const { return (GetMode() & kStream_Write) != 0; }
bool CanSeek() const { return (GetMode() & kStream_Seek) != 0; }

//-----------------------------------------------------
// Stream interface
// IStream interface
//-----------------------------------------------------

// Returns an optional path of a stream's source, such as a filepath;
// primarily for diagnostic purposes
const char *GetPath() const override { return _path.GetCStr(); }
// Tells which mode the stream is working in, which defines
// supported io operations, such as reading, writing, seeking, etc.
// Invalid streams return kStream_None to indicate that they are not functional.
virtual StreamMode GetMode() const = 0;
StreamMode GetMode() const override { return kStream_None; }
// Tells if there were errors during previous io operation(s);
// the call to GetError() *resets* the error record.
virtual bool GetError() const { return false; }
virtual bool EOS() const = 0;
virtual soff_t GetLength() const = 0;
virtual soff_t GetPosition() const = 0;

virtual void Close() = 0;

// Reads number of bytes in the provided buffer
virtual size_t Read(void *buffer, size_t size) = 0;
// ReadByte conforms to fgetc behavior:
// - if stream is valid, then returns an *unsigned char* packed in the int
// - if EOS, then returns -1
virtual int32_t ReadByte() = 0;
// Writes number of bytes from the provided buffer
virtual size_t Write(const void *buffer, size_t size) = 0;
// WriteByte conforms to fputc behavior:
// - on success, returns the unsigned char packed in the int
// - on failure, returns -1
virtual int32_t WriteByte(uint8_t b) = 0;
bool GetError() const override { return false; }

//-----------------------------------------------------
// Values reading and writing interface
//-----------------------------------------------------
// Convenience methods for reading values of particular size
virtual int8_t ReadInt8() = 0;
virtual int16_t ReadInt16() = 0;
Expand All @@ -186,11 +169,6 @@ class Stream : public IStream
virtual size_t WriteArrayOfInt32(const int32_t *buffer, size_t count) = 0;
virtual size_t WriteArrayOfInt64(const int64_t *buffer, size_t count) = 0;

virtual bool Seek(soff_t offset, StreamSeek origin = kSeekCurrent) = 0;

// Flush stream buffer to the underlying device
virtual bool Flush() = 0;

//-----------------------------------------------------
// Helper methods for read and write
//-----------------------------------------------------
Expand Down

0 comments on commit 9ddd7e5

Please sign in to comment.