Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
StreamReader Class Reference

A class to read sequential binary data directly from an istream. More...

#include "streamReader.h"

Public Member Functions

 StreamReader (const StreamReader &copy)
 The copy constructor does not copy ownership of the stream.
 
 StreamReader (std::istream &in)
 
 StreamReader (std::istream *in, bool owns_stream)
 If owns_stream is true, the stream pointer will be deleted when the StreamReader destructs.
 
vector_uchar extract_bytes (size_t size)
 Extracts the indicated number of bytes in the stream and returns them as a string.
 
size_t extract_bytes (unsigned char *into, size_t size)
 Extracts the indicated number of bytes in the stream into the given character buffer.
 
float get_be_float32 ()
 Extracts a 32-bit single-precision big-endian floating-point number.
 
PN_float64 get_be_float64 ()
 Extracts a 64-bit big-endian floating-point number.
 
int16_t get_be_int16 ()
 Extracts a signed big-endian 16-bit integer.
 
int32_t get_be_int32 ()
 Extracts a signed big-endian 32-bit integer.
 
int64_t get_be_int64 ()
 Extracts a signed big-endian 64-bit integer.
 
uint16_t get_be_uint16 ()
 Extracts an unsigned big-endian 16-bit integer.
 
uint32_t get_be_uint32 ()
 Extracts an unsigned big-endian 32-bit integer.
 
uint64_t get_be_uint64 ()
 Extracts an unsigned big-endian 64-bit integer.
 
bool get_bool ()
 Extracts a boolean value.
 
std::string get_fixed_string (size_t size)
 Extracts a fixed-length string.
 
float get_float32 ()
 Extracts a 32-bit single-precision floating-point number.
 
PN_float64 get_float64 ()
 Extracts a 64-bit floating-point number.
 
int16_t get_int16 ()
 Extracts a signed 16-bit integer.
 
int32_t get_int32 ()
 Extracts a signed 32-bit integer.
 
int64_t get_int64 ()
 Extracts a signed 64-bit integer.
 
int8_t get_int8 ()
 Extracts a signed 8-bit integer.
 
std::istream * get_istream () const
 
std::string get_string ()
 Extracts a variable-length string.
 
std::string get_string32 ()
 Extracts a variable-length string with a 32-bit length field.
 
uint16_t get_uint16 ()
 Extracts an unsigned 16-bit integer.
 
uint32_t get_uint32 ()
 Extracts an unsigned 32-bit integer.
 
uint64_t get_uint64 ()
 Extracts an unsigned 64-bit integer.
 
uint8_t get_uint8 ()
 Extracts an unsigned 8-bit integer.
 
std::string get_z_string ()
 Extracts a variable-length string, as a NULL-terminated string.
 
void operator= (const StreamReader &copy)
 The copy constructor does not copy ownership of the stream.
 
std::string readline ()
 Assumes the stream represents a text file, and extracts one line up to and including the trailing newline character.
 
void skip_bytes (size_t size)
 Skips over the indicated number of bytes in the stream.
 

Public Attributes

 get_istream
 Returns the stream in use.
 

Detailed Description

A class to read sequential binary data directly from an istream.

Its interface is similar to DatagramIterator by design; see also StreamWriter.

Definition at line 28 of file streamReader.h.

Constructor & Destructor Documentation

◆ StreamReader() [1/3]

StreamReader::StreamReader ( std::istream & in)
inline

Definition at line 17 of file streamReader.I.

◆ StreamReader() [2/3]

StreamReader::StreamReader ( std::istream * in,
bool owns_stream )
inlineexplicit

If owns_stream is true, the stream pointer will be deleted when the StreamReader destructs.

Definition at line 28 of file streamReader.I.

◆ StreamReader() [3/3]

StreamReader::StreamReader ( const StreamReader & copy)
inline

The copy constructor does not copy ownership of the stream.

Definition at line 38 of file streamReader.I.

◆ ~StreamReader()

StreamReader::~StreamReader ( )
inline

Definition at line 60 of file streamReader.I.

Member Function Documentation

◆ extract_bytes() [1/2]

vector_uchar StreamReader::extract_bytes ( size_t size)

Extracts the indicated number of bytes in the stream and returns them as a string.

Returns empty string at end-of-file.

Definition at line 139 of file streamReader.cxx.

◆ extract_bytes() [2/2]

size_t StreamReader::extract_bytes ( unsigned char * into,
size_t size )

Extracts the indicated number of bytes in the stream into the given character buffer.

Assumes that the buffer is big enough to hold the requested number of bytes. Returns the number of bytes that were successfully written.

Definition at line 125 of file streamReader.cxx.

Referenced by WavAudioCursor::WavAudioCursor(), and WavAudioCursor::read_samples().

◆ get_be_float32()

float StreamReader::get_be_float32 ( )
inline

Extracts a 32-bit single-precision big-endian floating-point number.

Since this kind of float is not necessarily portable across different architectures, special care is required.

Definition at line 279 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_be_float64()

PN_float64 StreamReader::get_be_float64 ( )
inline

Extracts a 64-bit big-endian floating-point number.

Definition at line 296 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_be_int16()

int16_t StreamReader::get_be_int16 ( )
inline

Extracts a signed big-endian 16-bit integer.

Definition at line 205 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_be_int32()

int32_t StreamReader::get_be_int32 ( )
inline

Extracts a signed big-endian 32-bit integer.

Definition at line 217 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_be_int64()

int64_t StreamReader::get_be_int64 ( )
inline

Extracts a signed big-endian 64-bit integer.

Definition at line 229 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_be_uint16()

uint16_t StreamReader::get_be_uint16 ( )
inline

Extracts an unsigned big-endian 16-bit integer.

Definition at line 241 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_be_uint32()

uint32_t StreamReader::get_be_uint32 ( )
inline

Extracts an unsigned big-endian 32-bit integer.

Definition at line 253 of file streamReader.I.

References ReversedNumericData::store_value().

Referenced by HashVal::input_binary().

◆ get_be_uint64()

uint64_t StreamReader::get_be_uint64 ( )
inline

Extracts an unsigned big-endian 64-bit integer.

Definition at line 265 of file streamReader.I.

References ReversedNumericData::store_value().

◆ get_bool()

bool StreamReader::get_bool ( )
inline

Extracts a boolean value.

Definition at line 78 of file streamReader.I.

References get_uint8().

◆ get_fixed_string()

string StreamReader::get_fixed_string ( size_t size)

Extracts a fixed-length string.

However, if a zero byte occurs within the string, it marks the end of the string.

Definition at line 87 of file streamReader.cxx.

◆ get_float32()

float StreamReader::get_float32 ( )
inline

Extracts a 32-bit single-precision floating-point number.

Since this kind of float is not necessarily portable across different architectures, special care is required.

Definition at line 176 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by WavAudioCursor::read_samples().

◆ get_float64()

PN_float64 StreamReader::get_float64 ( )
inline

Extracts a 64-bit floating-point number.

Definition at line 193 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by WavAudioCursor::read_samples().

◆ get_int16()

int16_t StreamReader::get_int16 ( )
inline

Extracts a signed 16-bit integer.

Definition at line 102 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by WavAudioCursor::read_samples().

◆ get_int32()

int32_t StreamReader::get_int32 ( )
inline

Extracts a signed 32-bit integer.

Definition at line 114 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by WavAudioCursor::read_samples().

◆ get_int64()

int64_t StreamReader::get_int64 ( )
inline

Extracts a signed 64-bit integer.

Definition at line 126 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by WavAudioCursor::read_samples().

◆ get_int8()

int8_t StreamReader::get_int8 ( )
inline

Extracts a signed 8-bit integer.

Definition at line 86 of file streamReader.I.

◆ get_string()

string StreamReader::get_string ( )

Extracts a variable-length string.

Definition at line 23 of file streamReader.cxx.

References get_uint16().

◆ get_string32()

string StreamReader::get_string32 ( )

Extracts a variable-length string with a 32-bit length field.

Definition at line 48 of file streamReader.cxx.

References get_uint32().

◆ get_uint16()

uint16_t StreamReader::get_uint16 ( )
inline

Extracts an unsigned 16-bit integer.

Definition at line 138 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by WavAudioCursor::WavAudioCursor(), and get_string().

◆ get_uint32()

uint32_t StreamReader::get_uint32 ( )
inline

◆ get_uint64()

uint64_t StreamReader::get_uint64 ( )
inline

Extracts an unsigned 64-bit integer.

Definition at line 162 of file streamReader.I.

References NativeNumericData::store_value().

Referenced by DatagramInputFile::get_datagram(), and DatagramInputFile::save_datagram().

◆ get_uint8()

uint8_t StreamReader::get_uint8 ( )
inline

Extracts an unsigned 8-bit integer.

Definition at line 94 of file streamReader.I.

Referenced by get_bool(), and WavAudioCursor::read_samples().

◆ get_z_string()

string StreamReader::get_z_string ( )

Extracts a variable-length string, as a NULL-terminated string.

Definition at line 69 of file streamReader.cxx.

◆ operator=()

void StreamReader::operator= ( const StreamReader & copy)
inline

The copy constructor does not copy ownership of the stream.

Definition at line 48 of file streamReader.I.

◆ readline()

string StreamReader::readline ( )

Assumes the stream represents a text file, and extracts one line up to and including the trailing newline character.

Returns empty string when the end of file is reached.

The interface here is intentionally designed to be similar to that for Python's File.readline() function.

Definition at line 161 of file streamReader.cxx.

◆ skip_bytes()

void StreamReader::skip_bytes ( size_t size)

Skips over the indicated number of bytes in the stream.

Definition at line 107 of file streamReader.cxx.

Referenced by WavAudioCursor::WavAudioCursor(), and WavAudioCursor::read_samples().

Member Data Documentation

◆ get_istream

std::istream * StreamReader::get_istream
inline

Returns the stream in use.

Definition at line 38 of file streamReader.h.


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