mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 15:15:31 +00:00
Changed definition of Stream::getPtr(size), now moves the position locator by 'size' bytes.
This commit is contained in:
parent
86089816a7
commit
4065ac0199
3 changed files with 19 additions and 7 deletions
|
@ -55,7 +55,12 @@ class SliceStream : public Stream
|
||||||
size_t size() const { return length; }
|
size_t size() const { return length; }
|
||||||
|
|
||||||
const void *getPtr() { return getPtr(0, length); }
|
const void *getPtr() { return getPtr(0, length); }
|
||||||
const void *getPtr(size_t size) { return getPtr(pos, size); }
|
const void *getPtr(size_t size)
|
||||||
|
{
|
||||||
|
void *ptr = getPtr(pos, size);
|
||||||
|
seek(pos+size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
const void *getPtr(size_t pos, size_t size)
|
const void *getPtr(size_t pos, size_t size)
|
||||||
{
|
{
|
||||||
// Boundry checks on pos and size. Bounding the size is
|
// Boundry checks on pos and size. Bounding the size is
|
||||||
|
|
|
@ -71,9 +71,15 @@ class MemoryStream : public Stream
|
||||||
size_t size() const { return length; }
|
size_t size() const { return length; }
|
||||||
bool eof() const { return pos == length; }
|
bool eof() const { return pos == length; }
|
||||||
|
|
||||||
/// Get the base pointer to the entire buffer
|
|
||||||
const void *getPtr() { return data; }
|
const void *getPtr() { return data; }
|
||||||
const void *getPtr(size_t size) { return ((char*)data)+pos; }
|
const void *getPtr(size_t size)
|
||||||
|
{
|
||||||
|
// This variant of getPtr must move the position pointer
|
||||||
|
size_t opos = pos;
|
||||||
|
pos += size;
|
||||||
|
if(pos > length) pos = length;
|
||||||
|
return ((char*)data)+opos;
|
||||||
|
}
|
||||||
const void *getPtr(size_t pos, size_t size)
|
const void *getPtr(size_t pos, size_t size)
|
||||||
{
|
{
|
||||||
if(pos > length) pos = length;
|
if(pos > length) pos = length;
|
||||||
|
|
|
@ -60,13 +60,14 @@ class Stream
|
||||||
/// memory-based streams where using them would be an optimization.
|
/// memory-based streams where using them would be an optimization.
|
||||||
virtual const void *getPtr() { assert(0); }
|
virtual const void *getPtr() { assert(0); }
|
||||||
|
|
||||||
/// Get a pointer to a memory region of 'size' bytes from the
|
|
||||||
/// current position.
|
|
||||||
virtual const void *getPtr(size_t size) { assert(0); }
|
|
||||||
|
|
||||||
/// Get a pointer to a memory region of 'size' bytes starting from
|
/// Get a pointer to a memory region of 'size' bytes starting from
|
||||||
/// position 'pos'
|
/// position 'pos'
|
||||||
virtual const void *getPtr(size_t pos, size_t size) { assert(0); }
|
virtual const void *getPtr(size_t pos, size_t size) { assert(0); }
|
||||||
|
|
||||||
|
/// Get a pointer to a memory region of 'size' bytes from the
|
||||||
|
/// current position. Unlike the two other getPtr variants, this
|
||||||
|
/// will advance the position past the returned area.
|
||||||
|
virtual const void *getPtr(size_t size) { assert(0); }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::shared_ptr<Stream> StreamPtr;
|
typedef boost::shared_ptr<Stream> StreamPtr;
|
||||||
|
|
Loading…
Reference in a new issue