Nebula
Loading...
Searching...
No Matches
IO::MemoryStream Class Reference

#include <memorystream.h>

Detailed Description

Implements a stream class which writes to and reads from system RAM.

Memory streams provide memory mapping for fast direct read/write access.

Inherits IO::Stream.

Inherited by Http::HttpNzStream, Http::HttpStream, and IO::EmbeddedMemoryStream.

Public Member Functions

 MemoryStream ()
 constructor
 
virtual ~MemoryStream ()
 destructor
 
virtual bool CanRead () const
 memory streams support reading
 
virtual bool CanWrite () const
 memory streams support writing
 
virtual bool CanSeek () const
 memory streams support seeking
 
virtual bool CanBeMapped () const
 memory streams are mappable
 
virtual void SetSize (Size s)
 set new size of the stream in bytes
 
virtual Size GetSize () const
 get the size of the stream in bytes
 
virtual Position GetPosition () const
 get the current position of the read/write cursor
 
virtual bool Open ()
 open the stream
 
virtual void Close ()
 close the stream
 
virtual void Write (const void *ptr, Size numBytes)
 directly write to the stream
 
virtual Size Read (void *ptr, Size numBytes)
 directly read from the stream
 
virtual void Seek (Offset offset, SeekOrigin origin)
 seek in stream
 
virtual bool Eof () const
 return true if end-of-stream reached
 
virtual void * Map ()
 map for direct memory-access
 
virtual void * MemoryMap ()
 map for direct memory-access
 
virtual void Unmap ()
 unmap a mapped stream
 
void * GetRawPointer () const
 get a direct "raw" pointer to the data
 
- Public Member Functions inherited from IO::Stream
 Stream ()
 constructor
 
virtual ~Stream ()
 destructor
 
void SetURI (const URI &u)
 set stream location as URI
 
const URIGetURI () const
 get stream URI
 
void SetAccessMode (AccessMode m)
 set the access mode of the stream (default is ReadAccess)
 
AccessMode GetAccessMode () const
 get the access mode of the stream
 
void SetAccessPattern (AccessPattern p)
 set the prefered access pattern (default is Sequential)
 
AccessPattern GetAccessPattern () const
 get the prefered access pattern
 
void SetMediaType (const MediaType &t)
 set optional media type of stream content
 
const MediaTypeGetMediaType () const
 get optional media type
 
bool IsOpen () const
 return true if currently open
 
virtual void Flush ()
 flush unsaved data
 
virtual void MemoryUnmap ()
 unmap memory stream
 
bool IsMapped () const
 return true if stream is currently mapped to memory
 
- Public Member Functions inherited from Core::RefCounted
 RefCounted ()
 constructor
 
int GetRefCount () const
 get the current refcount
 
void AddRef ()
 increment refcount by one
 
void Release ()
 decrement refcount and destroy object if refcount is zero
 
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
 
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
 
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
 
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
 
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
 
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
 
const Util::StringGetClassName () const
 get the class name
 
Util::FourCC GetClassFourCC () const
 get the class FourCC code
 

Protected Member Functions

void Realloc (Size s)
 re-allocate the memory buffer
 
bool HasRoom (Size numBytes) const
 return true if there's enough space for n more bytes
 
void MakeRoom (Size numBytes)
 make room for at least n more bytes
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Protected Attributes

Size capacity
 
Size size
 
Position position
 
unsigned char * buffer
 
- Protected Attributes inherited from IO::Stream
URI uri
 
AccessMode accessMode
 
AccessPattern accessPattern
 
bool isOpen
 
bool isMapped
 
MediaType mediaType
 

Static Protected Attributes

static const Size InitialSize = 256
 

Private Member Functions

 __DeclareClass (MemoryStream)
 

Additional Inherited Members

- Public Types inherited from IO::Stream
enum  AccessMode { ReadAccess , WriteAccess , AppendAccess , ReadWriteAccess }
 access modes More...
 
enum  AccessPattern { Random , Sequential }
 access prefered pattern More...
 
enum  SeekOrigin { Begin , Current , End }
 seek origins More...
 
typedef int64_t Position
 typedefs
 
typedef int64_t Offset
 
typedef int64_t Size
 
- Static Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
 

Constructor & Destructor Documentation

◆ MemoryStream()

IO::MemoryStream::MemoryStream ( )

constructor

◆ ~MemoryStream()

IO::MemoryStream::~MemoryStream ( )
virtual

destructor

Member Function Documentation

◆ __DeclareClass()

IO::MemoryStream::__DeclareClass ( MemoryStream )
private

◆ CanBeMapped()

bool IO::MemoryStream::CanBeMapped ( ) const
virtual

memory streams are mappable

Reimplemented from IO::Stream.

◆ CanRead()

bool IO::MemoryStream::CanRead ( ) const
virtual

memory streams support reading

Reimplemented from IO::Stream.

◆ CanSeek()

bool IO::MemoryStream::CanSeek ( ) const
virtual

memory streams support seeking

Reimplemented from IO::Stream.

◆ CanWrite()

bool IO::MemoryStream::CanWrite ( ) const
virtual

memory streams support writing

Reimplemented from IO::Stream.

Reimplemented in IO::EmbeddedMemoryStream.

◆ Close()

void IO::MemoryStream::Close ( )
virtual

close the stream

Close the stream.

The contents of the stream will remain intact until destruction of the object, so that the same data may be accessed or modified during a later session.

Reimplemented from IO::Stream.

◆ Eof()

bool IO::MemoryStream::Eof ( ) const
virtual

return true if end-of-stream reached

Reimplemented from IO::Stream.

◆ GetPosition()

Stream::Position IO::MemoryStream::GetPosition ( ) const
virtual

get the current position of the read/write cursor

Reimplemented from IO::Stream.

◆ GetRawPointer()

void * IO::MemoryStream::GetRawPointer ( ) const

get a direct "raw" pointer to the data

Get a direct pointer to the raw data.

This is a convenience method and only works for memory streams. NOTE: writing new data to the stream may/will result in an invalid pointer, don't keep the returned pointer around between writes!

◆ GetSize()

Stream::Size IO::MemoryStream::GetSize ( ) const
virtual

get the size of the stream in bytes

Reimplemented from IO::Stream.

◆ HasRoom()

bool IO::MemoryStream::HasRoom ( Size numBytes) const
protected

return true if there's enough space for n more bytes

◆ MakeRoom()

void IO::MemoryStream::MakeRoom ( Size numBytes)
protected

make room for at least n more bytes

This method makes room for at least N more bytes.

The actually allocated memory buffer will be greater then that. This operation involves a copy of existing data.

◆ Map()

void * IO::MemoryStream::Map ( )
virtual

map for direct memory-access

Map the stream for direct memory access.

This is much faster then reading/writing, but less flexible. A mapped stream cannot grow, instead the allowed memory range is determined by GetSize(). The read/writer must take special care to not read or write past the memory buffer boundaries!

Reimplemented from IO::Stream.

◆ MemoryMap()

void * IO::MemoryStream::MemoryMap ( )
virtual

map for direct memory-access

Reimplemented from IO::Stream.

◆ Open()

bool IO::MemoryStream::Open ( )
virtual

open the stream

Open the stream for reading or writing.

The stream may already contain data if it has been opened/closed before.

Reimplemented from IO::Stream.

Reimplemented in Http::HttpNzStream, Http::HttpStream, and IO::EmbeddedMemoryStream.

◆ Read()

Stream::Size IO::MemoryStream::Read ( void * ptr,
Size numBytes )
virtual

directly read from the stream

Reimplemented from IO::Stream.

◆ Realloc()

void IO::MemoryStream::Realloc ( Size newCapacity)
protected

re-allocate the memory buffer

This (re-)allocates the memory buffer to a new size.

If the new size is smaller then the existing size, the buffer contents will be clipped.

◆ Seek()

void IO::MemoryStream::Seek ( Offset offset,
SeekOrigin origin )
virtual

seek in stream

Reimplemented from IO::Stream.

◆ SetSize()

void IO::MemoryStream::SetSize ( Size s)
virtual

set new size of the stream in bytes

Reimplemented from IO::Stream.

◆ Unmap()

void IO::MemoryStream::Unmap ( )
virtual

unmap a mapped stream

Unmap a memory-mapped stream.

Reimplemented from IO::Stream.

◆ Write()

void IO::MemoryStream::Write ( const void * ptr,
Size numBytes )
virtual

directly write to the stream

Reimplemented from IO::Stream.

Member Data Documentation

◆ buffer

unsigned char* IO::MemoryStream::buffer
protected

◆ capacity

Size IO::MemoryStream::capacity
protected

◆ InitialSize

const Size IO::MemoryStream::InitialSize = 256
staticprotected

◆ position

Position IO::MemoryStream::position
protected

◆ size

Size IO::MemoryStream::size
protected

The documentation for this class was generated from the following files: