Beatmup
Beatmup::MemoryInputStream Class Reference

InputStream reading from memory. More...

#include <input_stream.h>

Inheritance diagram for Beatmup::MemoryInputStream:
Beatmup::InputStream

Public Member Functions

 MemoryInputStream (const void *data, msize size)
 
bool operator() (void *buffer, msize bytes)
 Reads a given number of bytes into a specific memory location. More...
 
bool seek (msize pos)
 Moves the read pointer to a given position in the stream. More...
 
bool eof () const
 Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty). More...
 

Private Attributes

const char * data
 
const msize size
 
msize ptr
 

Detailed Description

InputStream reading from memory.

Definition at line 75 of file input_stream.h.

Constructor & Destructor Documentation

◆ MemoryInputStream()

Beatmup::MemoryInputStream::MemoryInputStream ( const void *  data,
msize  size 
)
inline

Definition at line 81 of file input_stream.h.

81 : data(static_cast<const char*>(data)), size(size), ptr(0) {}

Member Function Documentation

◆ operator()()

bool MemoryInputStream::operator() ( void *  buffer,
msize  bytes 
)
virtual

Reads a given number of bytes into a specific memory location.

Parameters
[in]bufferThe address to store the data to
[in]bytesNumber of bytes to read
Returns
true on success.

Implements Beatmup::InputStream.

Definition at line 59 of file input_stream.cpp.

59  {
60  const msize step = ptr + bytes < size ? bytes : size - ptr;
61  memcpy(buffer, data + ptr, step);
62  ptr += step;
63  return step == bytes;
64 }
uint32_t msize
memory size
Definition: basic_types.h:30
jlong jint jfloat step

◆ seek()

bool MemoryInputStream::seek ( msize  pos)
virtual

Moves the read pointer to a given position in the stream.

Parameters
posThe position in bytes from the beginning of the stream
Returns
true on success.

Implements Beatmup::InputStream.

Definition at line 66 of file input_stream.cpp.

66  {
67  if (pos < size)
68  ptr = pos;
69  return pos < size;
70 }

◆ eof()

bool MemoryInputStream::eof ( ) const
virtual

Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty).

Implements Beatmup::InputStream.

Definition at line 72 of file input_stream.cpp.

72  {
73  return ptr >= size;
74 }

Member Data Documentation

◆ data

const char* Beatmup::MemoryInputStream::data
private

Definition at line 77 of file input_stream.h.

◆ size

const msize Beatmup::MemoryInputStream::size
private

Definition at line 78 of file input_stream.h.

◆ ptr

msize Beatmup::MemoryInputStream::ptr
private

Definition at line 79 of file input_stream.h.


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