InputStream: "protect" attributes
This commit is contained in:
@@ -64,6 +64,7 @@ public:
|
||||
*/
|
||||
Cond &cond;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* indicates whether the stream is ready for reading and
|
||||
* whether the other attributes in this struct are valid
|
||||
@@ -80,7 +81,6 @@ public:
|
||||
*/
|
||||
offset_type size;
|
||||
|
||||
public:
|
||||
/**
|
||||
* the current offset within the stream
|
||||
*/
|
||||
@@ -217,6 +217,13 @@ public:
|
||||
mime = _mime;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
bool KnownSize() const {
|
||||
assert(ready);
|
||||
|
||||
return size >= 0;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
offset_type GetSize() const {
|
||||
assert(ready);
|
||||
@@ -239,6 +246,15 @@ public:
|
||||
return offset;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
offset_type GetRest() const {
|
||||
assert(ready);
|
||||
assert(size >= 0);
|
||||
assert(offset >= 0);
|
||||
|
||||
return size - offset;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
bool IsSeekable() const {
|
||||
assert(ready);
|
||||
|
@@ -93,7 +93,7 @@ private:
|
||||
* buffer contain more data for the next read operation?
|
||||
*/
|
||||
bool ReadingFromBuffer() const {
|
||||
return tail > 0 && offset < input->offset;
|
||||
return tail > 0 && offset < input->GetOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ private:
|
||||
SetReady();
|
||||
}
|
||||
|
||||
offset = src->offset;
|
||||
offset = src->GetOffset();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -127,7 +127,7 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
|
||||
/* buffered read */
|
||||
|
||||
assert(head == (size_t)offset);
|
||||
assert(tail == (size_t)input->offset);
|
||||
assert(tail == (size_t)input->GetOffset());
|
||||
|
||||
if (read_size > tail - head)
|
||||
read_size = tail - head;
|
||||
@@ -142,7 +142,7 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
|
||||
|
||||
size_t nbytes = input->Read(ptr, read_size, error);
|
||||
|
||||
if (input->offset > (InputPlugin::offset_type)sizeof(buffer))
|
||||
if (input->GetOffset() > (offset_type)sizeof(buffer))
|
||||
/* disable buffering */
|
||||
tail = 0;
|
||||
else if (tail == (size_t)offset) {
|
||||
@@ -151,7 +151,7 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
|
||||
memcpy(buffer + tail, ptr, nbytes);
|
||||
tail += nbytes;
|
||||
|
||||
assert(tail == (size_t)input->offset);
|
||||
assert(tail == (size_t)input->GetOffset());
|
||||
}
|
||||
|
||||
CopyAttributes();
|
||||
@@ -172,7 +172,7 @@ RewindInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
|
||||
|
||||
assert(!ReadingFromBuffer() ||
|
||||
head == (size_t)offset);
|
||||
assert(tail == (size_t)input->offset);
|
||||
assert(tail == (size_t)input->GetOffset());
|
||||
|
||||
head = (size_t)new_offset;
|
||||
offset = new_offset;
|
||||
@@ -194,7 +194,7 @@ InputStream *
|
||||
input_rewind_open(InputStream *is)
|
||||
{
|
||||
assert(is != nullptr);
|
||||
assert(is->offset == 0);
|
||||
assert(is->GetOffset() == 0);
|
||||
|
||||
if (is->IsReady() && is->IsSeekable())
|
||||
/* seekable resources don't need this plugin */
|
||||
|
Reference in New Issue
Block a user