Nebula
Loading...
Searching...
No Matches
memorystream.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13#include "io/stream.h"
14
15//------------------------------------------------------------------------------
16namespace IO
17{
18class MemoryStream : public Stream
19{
21public:
25 virtual ~MemoryStream();
27 virtual bool CanRead() const;
29 virtual bool CanWrite() const;
31 virtual bool CanSeek() const;
33 virtual bool CanBeMapped() const;
35 virtual void SetSize(Size s);
37 virtual Size GetSize() const;
39 virtual Position GetPosition() const;
41 virtual bool Open();
43 virtual void Close();
45 virtual void Write(const void* ptr, Size numBytes);
47 virtual Size Read(void* ptr, Size numBytes);
49 virtual void Seek(Offset offset, SeekOrigin origin);
51 virtual bool Eof() const;
53 virtual void* Map();
55 virtual void* MemoryMap();
57 virtual void Unmap();
59 void* GetRawPointer() const;
60
61protected:
63 void Realloc(Size s);
65 bool HasRoom(Size numBytes) const;
67 void MakeRoom(Size numBytes);
68
69 static const Size InitialSize = 256;
73 unsigned char* buffer;
74};
75
76} // namespace IO
77//------------------------------------------------------------------------------
Implements a stream class which writes to and reads from system RAM.
Definition memorystream.h:19
virtual void * MemoryMap()
map for direct memory-access
Definition memorystream.cc:333
virtual void * Map()
map for direct memory-access
Definition memorystream.cc:320
unsigned char * buffer
Definition memorystream.h:73
virtual void Close()
close the stream
Definition memorystream.cc:150
virtual ~MemoryStream()
destructor
Definition memorystream.cc:28
void Realloc(Size s)
re-allocate the memory buffer
Definition memorystream.cc:262
Position position
Definition memorystream.h:72
bool HasRoom(Size numBytes) const
return true if there's enough space for n more bytes
Definition memorystream.cc:251
void MakeRoom(Size numBytes)
make room for at least n more bytes
Definition memorystream.cc:290
virtual void Unmap()
unmap a mapped stream
Definition memorystream.cc:343
__DeclareClass(MemoryStream)
virtual Position GetPosition() const
get the current position of the read/write cursor
Definition memorystream.cc:106
virtual bool CanWrite() const
memory streams support writing
Definition memorystream.cc:57
Size capacity
Definition memorystream.h:70
static const Size InitialSize
Definition memorystream.h:69
virtual bool Eof() const
return true if end-of-stream reached
Definition memorystream.cc:239
virtual bool CanBeMapped() const
memory streams are mappable
Definition memorystream.cc:75
virtual bool CanSeek() const
memory streams support seeking
Definition memorystream.cc:66
virtual Size GetSize() const
get the size of the stream in bytes
Definition memorystream.cc:97
Size size
Definition memorystream.h:71
virtual Size Read(void *ptr, Size numBytes)
directly read from the stream
Definition memorystream.cc:191
virtual bool Open()
open the stream
Definition memorystream.cc:117
virtual void Seek(Offset offset, SeekOrigin origin)
seek in stream
Definition memorystream.cc:213
virtual bool CanRead() const
memory streams support reading
Definition memorystream.cc:48
MemoryStream()
constructor
Definition memorystream.cc:16
void * GetRawPointer() const
get a direct "raw" pointer to the data
Definition memorystream.cc:357
virtual void SetSize(Size s)
set new size of the stream in bytes
Definition memorystream.cc:84
Offers an abstract interface for read/write access to a sequence of bytes.
Definition stream.h:28
SeekOrigin
seek origins
Definition stream.h:54
int64_t Offset
Definition stream.h:33
int64_t Position
typedefs
Definition stream.h:32
int64_t Size
Definition stream.h:34
Instances of wrapped stream classes.
Definition orientation.cc:10
@ Write
Definition filewatcher.h:47