A class to read sequential binary data directly from an istream. More...
#include "streamReader.h"
Public Member Functions | |
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. More... | |
StreamReader (const StreamReader ©) | |
The copy constructor does not copy ownership of the stream. 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... | |
vector_uchar | extract_bytes (size_t size) |
Extracts the indicated number of bytes in the stream and returns them as a string. 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... | |
int16_t | get_be_int16 () |
Extracts a signed big-endian 16-bit integer. More... | |
int32_t | get_be_int32 () |
Extracts a signed big-endian 32-bit integer. More... | |
int64_t | get_be_int64 () |
Extracts a signed big-endian 64-bit integer. More... | |
uint16_t | get_be_uint16 () |
Extracts an unsigned big-endian 16-bit integer. More... | |
uint32_t | get_be_uint32 () |
Extracts an unsigned big-endian 32-bit integer. More... | |
uint64_t | get_be_uint64 () |
Extracts an unsigned big-endian 64-bit integer. More... | |
bool | get_bool () |
Extracts a boolean value. More... | |
std::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... | |
int16_t | get_int16 () |
Extracts a signed 16-bit integer. More... | |
int32_t | get_int32 () |
Extracts a signed 32-bit integer. More... | |
int64_t | get_int64 () |
Extracts a signed 64-bit integer. More... | |
int8_t | get_int8 () |
Extracts a signed 8-bit integer. More... | |
std::istream * | get_istream () const |
std::string | get_string () |
Extracts a variable-length string. More... | |
std::string | get_string32 () |
Extracts a variable-length string with a 32-bit length field. More... | |
uint16_t | get_uint16 () |
Extracts an unsigned 16-bit integer. More... | |
uint32_t | get_uint32 () |
Extracts an unsigned 32-bit integer. More... | |
uint64_t | get_uint64 () |
Extracts an unsigned 64-bit integer. More... | |
uint8_t | get_uint8 () |
Extracts an unsigned 8-bit integer. More... | |
std::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... | |
std::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... | |
Public Attributes | |
get_istream | |
Returns the stream in use. 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 28 of file streamReader.h.
|
inlineexplicit |
If owns_stream is true, the stream pointer will be deleted when the StreamReader destructs.
Definition at line 29 of file streamReader.I.
|
inline |
The copy constructor does not copy ownership of the stream.
Definition at line 39 of file streamReader.I.
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 120 of file streamReader.cxx.
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 134 of file streamReader.cxx.
|
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 280 of file streamReader.I.
|
inline |
Extracts a 64-bit big-endian floating-point number.
Definition at line 297 of file streamReader.I.
References ReversedNumericData::store_value().
|
inline |
Extracts a signed big-endian 16-bit integer.
Definition at line 206 of file streamReader.I.
References ReversedNumericData::store_value().
|
inline |
Extracts a signed big-endian 32-bit integer.
Definition at line 218 of file streamReader.I.
References ReversedNumericData::store_value().
|
inline |
Extracts a signed big-endian 64-bit integer.
Definition at line 230 of file streamReader.I.
References ReversedNumericData::store_value().
|
inline |
Extracts an unsigned big-endian 16-bit integer.
Definition at line 242 of file streamReader.I.
References ReversedNumericData::store_value().
|
inline |
Extracts an unsigned big-endian 32-bit integer.
Definition at line 254 of file streamReader.I.
References ReversedNumericData::store_value().
Referenced by HashVal::input_binary().
|
inline |
Extracts an unsigned big-endian 64-bit integer.
Definition at line 266 of file streamReader.I.
References ReversedNumericData::store_value().
|
inline |
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 82 of file streamReader.cxx.
|
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 177 of file streamReader.I.
|
inline |
Extracts a 64-bit floating-point number.
Definition at line 194 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts a signed 16-bit integer.
Definition at line 103 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts a signed 32-bit integer.
Definition at line 115 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts a signed 64-bit integer.
Definition at line 127 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts a signed 8-bit integer.
Definition at line 87 of file streamReader.I.
string StreamReader::get_string | ( | ) |
Extracts a variable-length string.
Definition at line 24 of file streamReader.cxx.
string StreamReader::get_string32 | ( | ) |
Extracts a variable-length string with a 32-bit length field.
Definition at line 43 of file streamReader.cxx.
|
inline |
Extracts an unsigned 16-bit integer.
Definition at line 139 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts an unsigned 32-bit integer.
Definition at line 151 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts an unsigned 64-bit integer.
Definition at line 163 of file streamReader.I.
References NativeNumericData::store_value().
|
inline |
Extracts an unsigned 8-bit integer.
Definition at line 95 of file streamReader.I.
Referenced by get_bool().
string StreamReader::get_z_string | ( | ) |
Extracts a variable-length string, as a NULL-terminated string.
Definition at line 64 of file streamReader.cxx.
|
inline |
The copy constructor does not copy ownership of the stream.
Definition at line 49 of file streamReader.I.
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 156 of file streamReader.cxx.
void StreamReader::skip_bytes | ( | size_t | size | ) |
Skips over the indicated number of bytes in the stream.
Definition at line 102 of file streamReader.cxx.
Referenced by WavAudioCursor::seek().
|
inline |
Returns the stream in use.
Definition at line 38 of file streamReader.h.