mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Started buffer_stream.h, WIP
This commit is contained in:
parent
9cb57f9ccd
commit
71c3be13fc
23
stream/filters/buffer_stream.h
Normal file
23
stream/filters/buffer_stream.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef MANGLE_STREAM_BUFFER_H
|
||||||
|
#define MANGLE_STREAM_BUFFER_H
|
||||||
|
|
||||||
|
#include "../servers/memory_stream.h"
|
||||||
|
#include "../clients/iwrapper.h"
|
||||||
|
|
||||||
|
namespace Mangle {
|
||||||
|
namespace Stream {
|
||||||
|
|
||||||
|
/** A Stream that reads another Stream into a buffer, and serves it as
|
||||||
|
a MemoryStream.
|
||||||
|
*/
|
||||||
|
class BufferStream : public MemoryStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BufferStream(Stream *input)
|
||||||
|
{
|
||||||
|
// Allocate memory, read the stream into it. Then call set()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}} // namespaces
|
||||||
|
#endif
|
@ -32,8 +32,17 @@ class MemoryStream : public Stream
|
|||||||
hasSize = true;
|
hasSize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryStream()
|
||||||
|
: data(NULL), length(0), pos(0);
|
||||||
|
{
|
||||||
|
isSeekable = true;
|
||||||
|
hasPosition = true;
|
||||||
|
hasSize = true;
|
||||||
|
}
|
||||||
|
|
||||||
size_t read(void *buf, size_t count)
|
size_t read(void *buf, size_t count)
|
||||||
{
|
{
|
||||||
|
assert(data != NULL);
|
||||||
assert(pos <= length);
|
assert(pos <= length);
|
||||||
|
|
||||||
// Don't read more than we have
|
// Don't read more than we have
|
||||||
@ -63,6 +72,14 @@ class MemoryStream : public Stream
|
|||||||
|
|
||||||
// New members in MemoryStream:
|
// New members in MemoryStream:
|
||||||
|
|
||||||
|
/// Set a new buffer and length. This will rewind the position to zero.
|
||||||
|
void set(const void* _data, size_t _length)
|
||||||
|
{
|
||||||
|
data = _data;
|
||||||
|
length = _length;
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the base pointer to the entire buffer
|
/// Get the base pointer to the entire buffer
|
||||||
const void *getPtr() const { return data; }
|
const void *getPtr() const { return data; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user