mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-04 16:26:53 +00:00
COMMON: Add a class SafeSubReadStream
SafeSubReadStream is basically a SeekableSubReadStream that re-seek()s the parent stream before each read(). That way, more than one SafeSubReadStream of the same parent stream can be used safely at the same time, at the cost of increasing IO.
This commit is contained in:
parent
d77502eaf4
commit
88d562a361
@ -242,6 +242,13 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) {
|
||||
// Make sure the parent stream is at the right position
|
||||
seek(0, SEEK_CUR);
|
||||
|
||||
return SeekableSubReadStream::read(dataPtr, dataSize);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
@ -102,6 +102,25 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A seekable substream that removes the exclusivity demand required by the
|
||||
* normal SeekableSubReadStream, at the cost of seek()ing the parent stream
|
||||
* before each read().
|
||||
*
|
||||
* More than one SafeSubReadStream to the same parent stream can be used
|
||||
* at the same time; they won't mess up each other. They will, however,
|
||||
* reposition the parent stream, so don't depend on its position to be
|
||||
* the same after a read() or seek() on one of its SafeSubReadStream.
|
||||
*/
|
||||
class SafeSubReadStream : public SeekableSubReadStream {
|
||||
public:
|
||||
SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) :
|
||||
SeekableSubReadStream(parentStream, begin, end, disposeParentStream) {
|
||||
}
|
||||
|
||||
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
||||
};
|
||||
|
||||
|
||||
} // End of namespace Common
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user