Panda3D
|
A class to read sequential binary data directly from an istream. More...
#include "streamReader.h"
Public Member Functions | |
StreamReader (istream &in) | |
StreamReader (istream *in, bool owns_stream) | |
If owns_stream is true, the stream pointer will be deleted when the StreamReader destructs. More... | |
StreamReader (const StreamReader ©) | |
The copy constructor does not copy ownership of the stream. More... | |
string | extract_bytes (size_t size) |
Extracts the indicated number of bytes in the stream and returns them as a string. More... | |
size_t | extract_bytes (unsigned char *into, size_t size) |
Extracts the indicated number of bytes in the stream into the given character buffer. More... | |
float | get_be_float32 () |
Extracts a 32-bit single-precision big-endian floating-point number. More... | |
PN_float64 | get_be_float64 () |
Extracts a 64-bit big-endian floating-point number. More... | |
PN_int16 | get_be_int16 () |
Extracts a signed big-endian 16-bit integer. More... | |
PN_int32 | get_be_int32 () |
Extracts a signed big-endian 32-bit integer. More... | |
PN_int64 | get_be_int64 () |
Extracts a signed big-endian 64-bit integer. More... | |
PN_uint16 | get_be_uint16 () |
Extracts an unsigned big-endian 16-bit integer. More... | |
PN_uint32 | get_be_uint32 () |
Extracts an unsigned big-endian 32-bit integer. More... | |
PN_uint64 | get_be_uint64 () |
Extracts an unsigned big-endian 64-bit integer. More... | |
bool | get_bool () |
Extracts a boolean value. More... | |
string | get_fixed_string (size_t size) |
Extracts a fixed-length string. More... | |
float | get_float32 () |
Extracts a 32-bit single-precision floating-point number. More... | |
PN_float64 | get_float64 () |
Extracts a 64-bit floating-point number. More... | |
PN_int16 | get_int16 () |
Extracts a signed 16-bit integer. More... | |
PN_int32 | get_int32 () |
Extracts a signed 32-bit integer. More... | |
PN_int64 | get_int64 () |
Extracts a signed 64-bit integer. More... | |
PN_int8 | get_int8 () |
Extracts a signed 8-bit integer. More... | |
istream * | get_istream () const |
Returns the stream in use. More... | |
string | get_string () |
Extracts a variable-length string. More... | |
string | get_string32 () |
Extracts a variable-length string with a 32-bit length field. More... | |
PN_uint16 | get_uint16 () |
Extracts an unsigned 16-bit integer. More... | |
PN_uint32 | get_uint32 () |
Extracts an unsigned 32-bit integer. More... | |
PN_uint64 | get_uint64 () |
Extracts an unsigned 64-bit integer. More... | |
PN_uint8 | get_uint8 () |
Extracts an unsigned 8-bit integer. More... | |
string | get_z_string () |
Extracts a variable-length string, as a NULL-terminated string. More... | |
void | operator= (const StreamReader ©) |
The copy constructor does not copy ownership of the stream. More... | |
string | readline () |
Assumes the stream represents a text file, and extracts one line up to and including the trailing newline character. More... | |
void | skip_bytes (size_t size) |
Skips over the indicated number of bytes in the stream. More... | |
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 30 of file streamReader.h.
|
inline |
If owns_stream is true, the stream pointer will be deleted when the StreamReader destructs.
Definition at line 35 of file streamReader.I.
|
inline |
The copy constructor does not copy ownership of the stream.
Definition at line 48 of file streamReader.I.
References operator=().
string 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 123 of file streamReader.cxx.
Referenced by DownloadDb::get_hash(), DownloadDb::Db::parse_record_header(), WavAudioCursor::read_samples(), Multifile::read_subfile(), skip_bytes(), and WavAudioCursor::WavAudioCursor().
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 144 of file streamReader.cxx.
References readline().
|
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 334 of file streamReader.I.
References get_be_float64(), and ReversedNumericData::store_value().
Referenced by get_be_uint64().
|
inline |
Extracts a 64-bit big-endian floating-point number.
Definition at line 353 of file streamReader.I.
References ReversedNumericData::store_value().
Referenced by get_be_float32().
|
inline |
Extracts a signed big-endian 16-bit integer.
Definition at line 247 of file streamReader.I.
References get_be_int32(), and ReversedNumericData::store_value().
Referenced by get_float64().
|
inline |
Extracts a signed big-endian 32-bit integer.
Definition at line 261 of file streamReader.I.
References get_be_int64(), and ReversedNumericData::store_value().
Referenced by get_be_int16().
|
inline |
Extracts a signed big-endian 64-bit integer.
Definition at line 275 of file streamReader.I.
References get_be_uint16(), and ReversedNumericData::store_value().
Referenced by get_be_int32().
|
inline |
Extracts an unsigned big-endian 16-bit integer.
Definition at line 289 of file streamReader.I.
References get_be_uint32(), and ReversedNumericData::store_value().
Referenced by get_be_int64().
|
inline |
Extracts an unsigned big-endian 32-bit integer.
Definition at line 303 of file streamReader.I.
References get_be_uint64(), and ReversedNumericData::store_value().
Referenced by get_be_uint16(), and HashVal::input_binary().
|
inline |
Extracts an unsigned big-endian 64-bit integer.
Definition at line 317 of file streamReader.I.
References get_be_float32(), and ReversedNumericData::store_value().
Referenced by get_be_uint32().
|
inline |
Extracts a boolean value.
Definition at line 97 of file streamReader.I.
References get_int8(), and get_uint8().
Referenced by get_istream().
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 86 of file streamReader.cxx.
References skip_bytes().
Referenced by get_z_string().
|
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 214 of file streamReader.I.
References get_float64(), and NativeNumericData::store_value().
Referenced by get_uint64(), and WavAudioCursor::read_samples().
|
inline |
Extracts a 64-bit floating-point number.
Definition at line 233 of file streamReader.I.
References get_be_int16(), and NativeNumericData::store_value().
Referenced by get_float32(), and WavAudioCursor::read_samples().
|
inline |
Extracts a signed 16-bit integer.
Definition at line 127 of file streamReader.I.
References get_int32(), and NativeNumericData::store_value().
Referenced by get_uint8(), WavAudioCursor::read_samples(), and Multifile::read_subfile().
|
inline |
Extracts a signed 32-bit integer.
Definition at line 141 of file streamReader.I.
References get_int64(), and NativeNumericData::store_value().
Referenced by DownloadDb::get_hash(), get_int16(), and WavAudioCursor::read_samples().
|
inline |
Extracts a signed 64-bit integer.
Definition at line 155 of file streamReader.I.
References get_uint16(), and NativeNumericData::store_value().
Referenced by get_int32(), and WavAudioCursor::read_samples().
|
inline |
Extracts a signed 8-bit integer.
Definition at line 107 of file streamReader.I.
References get_uint8().
Referenced by get_bool().
|
inline |
Returns the stream in use.
Definition at line 87 of file streamReader.I.
References get_bool().
Referenced by DownloadDb::get_hash(), and operator=().
string StreamReader::get_string | ( | ) |
Extracts a variable-length string.
Definition at line 25 of file streamReader.cxx.
References get_string32(), and get_uint16().
string StreamReader::get_string32 | ( | ) |
Extracts a variable-length string with a 32-bit length field.
Definition at line 44 of file streamReader.cxx.
References get_uint32(), and get_z_string().
Referenced by get_string().
|
inline |
Extracts an unsigned 16-bit integer.
Definition at line 169 of file streamReader.I.
References get_uint32(), and NativeNumericData::store_value().
Referenced by get_int64(), get_string(), and WavAudioCursor::WavAudioCursor().
|
inline |
Extracts an unsigned 32-bit integer.
Definition at line 183 of file streamReader.I.
References get_uint64(), and NativeNumericData::store_value().
Referenced by Texture::ensure_loader_type(), DatagramInputFile::get_datagram(), get_string32(), get_uint16(), HashVal::input_dec(), Multifile::read_subfile(), DatagramInputFile::save_datagram(), and WavAudioCursor::WavAudioCursor().
|
inline |
Extracts an unsigned 64-bit integer.
Definition at line 197 of file streamReader.I.
References get_float32(), and NativeNumericData::store_value().
Referenced by DatagramInputFile::get_datagram(), get_uint32(), and DatagramInputFile::save_datagram().
|
inline |
Extracts an unsigned 8-bit integer.
Definition at line 117 of file streamReader.I.
References get_int16().
Referenced by get_bool(), get_int8(), and WavAudioCursor::read_samples().
string StreamReader::get_z_string | ( | ) |
Extracts a variable-length string, as a NULL-terminated string.
Definition at line 65 of file streamReader.cxx.
References get_fixed_string().
Referenced by get_string32().
|
inline |
The copy constructor does not copy ownership of the stream.
Definition at line 61 of file streamReader.I.
References get_istream().
Referenced by StreamReader().
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 166 of file streamReader.cxx.
Referenced by ObjToEggConverter::convert_file(), and extract_bytes().
void StreamReader::skip_bytes | ( | size_t | size | ) |
Skips over the indicated number of bytes in the stream.
Definition at line 105 of file streamReader.cxx.
References extract_bytes().
Referenced by Texture::ensure_loader_type(), get_fixed_string(), WavAudioCursor::read_samples(), WavAudioCursor::seek(), and WavAudioCursor::WavAudioCursor().