Panda3D
|
A StreamWriter object is used to write sequential binary data directly to an ostream. More...
#include "streamWriter.h"
Public Member Functions | |
StreamWriter (ostream &out) | |
StreamWriter (ostream *out, bool owns_stream) | |
StreamWriter (const StreamWriter ©) | |
The copy constructor does not copy ownership of the stream. | |
void | add_be_float32 (float value) |
Adds a 32-bit single-precision big-endian floating-point number to the stream. | |
void | add_be_float64 (PN_float64 value) |
Adds a 64-bit big-endian floating-point number to the streamWriter. | |
void | add_be_int16 (PN_int16 value) |
Adds a signed 16-bit big-endian integer to the streamWriter. | |
void | add_be_int32 (PN_int32 value) |
Adds a signed 32-bit big-endian integer to the streamWriter. | |
void | add_be_int64 (PN_int64 value) |
Adds a signed 64-bit big-endian integer to the streamWriter. | |
void | add_be_uint16 (PN_uint16 value) |
Adds an unsigned 16-bit big-endian integer to the streamWriter. | |
void | add_be_uint32 (PN_uint32 value) |
Adds an unsigned 32-bit big-endian integer to the streamWriter. | |
void | add_be_uint64 (PN_uint64 value) |
Adds an unsigned 64-bit big-endian integer to the streamWriter. | |
void | add_bool (bool value) |
Adds a boolean value to the stream. | |
void | add_fixed_string (const string &str, size_t size) |
Adds a fixed-length string to the stream. | |
void | add_float32 (float value) |
Adds a 32-bit single-precision floating-point number to the stream. | |
void | add_float64 (PN_float64 value) |
Adds a 64-bit floating-point number to the stream. | |
void | add_int16 (PN_int16 value) |
Adds a signed 16-bit integer to the stream. | |
void | add_int32 (PN_int32 value) |
Adds a signed 32-bit integer to the stream. | |
void | add_int64 (PN_int64 value) |
Adds a signed 64-bit integer to the stream. | |
void | add_int8 (PN_int8 value) |
Adds a signed 8-bit integer to the stream. | |
void | add_string (const string &str) |
Adds a variable-length string to the stream. | |
void | add_string32 (const string &str) |
Adds a variable-length string to the stream, using a 32-bit length field. | |
void | add_uint16 (PN_uint16 value) |
Adds an unsigned 16-bit integer to the stream. | |
void | add_uint32 (PN_uint32 value) |
Adds an unsigned 32-bit integer to the stream. | |
void | add_uint64 (PN_uint64 value) |
Adds an unsigned 64-bit integer to the stream. | |
void | add_uint8 (PN_uint8 value) |
Adds an unsigned 8-bit integer to the stream. | |
void | add_z_string (string str) |
Adds a variable-length string to the stream, as a NULL-terminated string. | |
void | append_data (const void *data, size_t size) |
Appends some more raw data to the end of the streamWriter. | |
void | append_data (const string &data) |
Appends some more raw data to the end of the streamWriter. | |
void | flush () |
Calls flush() on the underlying stream. | |
ostream * | get_ostream () const |
Returns the stream in use. | |
void | operator= (const StreamWriter ©) |
The copy constructor does not copy ownership of the stream. | |
void | pad_bytes (size_t size) |
Adds the indicated number of zero bytes to the stream. | |
void | write (const string &str) |
A synonym of append_data(). |
A StreamWriter object is used to write sequential binary data directly to an ostream.
Its interface is very similar to Datagram by design; it's primarily intended as a convenience to eliminate the overhead of writing bytes to a Datagram and then writing the Datagram to a stream.
Definition at line 33 of file streamWriter.h.
StreamWriter::StreamWriter | ( | const StreamWriter & | copy | ) | [inline] |
The copy constructor does not copy ownership of the stream.
Definition at line 47 of file streamWriter.I.
void StreamWriter::add_be_float32 | ( | float | value | ) | [inline] |
Adds a 32-bit single-precision big-endian floating-point number to the stream.
Since this kind of float is not necessarily portable across different architectures, special care is required.
Definition at line 296 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_be_float64 | ( | PN_float64 | value | ) | [inline] |
Adds a 64-bit big-endian floating-point number to the streamWriter.
Definition at line 312 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_be_int16 | ( | PN_int16 | value | ) | [inline] |
Adds a signed 16-bit big-endian integer to the streamWriter.
Definition at line 222 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_be_int32 | ( | PN_int32 | value | ) | [inline] |
Adds a signed 32-bit big-endian integer to the streamWriter.
Definition at line 234 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_be_int64 | ( | PN_int64 | value | ) | [inline] |
Adds a signed 64-bit big-endian integer to the streamWriter.
Definition at line 246 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_be_uint16 | ( | PN_uint16 | value | ) | [inline] |
Adds an unsigned 16-bit big-endian integer to the streamWriter.
Definition at line 258 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_be_uint32 | ( | PN_uint32 | value | ) | [inline] |
Adds an unsigned 32-bit big-endian integer to the streamWriter.
Definition at line 270 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
Referenced by HashVal::output_binary().
void StreamWriter::add_be_uint64 | ( | PN_uint64 | value | ) | [inline] |
Adds an unsigned 64-bit big-endian integer to the streamWriter.
Definition at line 282 of file streamWriter.I.
References append_data(), and ReversedNumericData::get_data().
void StreamWriter::add_bool | ( | bool | value | ) | [inline] |
Adds a boolean value to the stream.
Definition at line 96 of file streamWriter.I.
References add_uint8().
void StreamWriter::add_fixed_string | ( | const string & | str, |
size_t | size | ||
) | [inline] |
Adds a fixed-length string to the stream.
If the string given is less than the requested size, this will pad the string out with zeroes; if it is greater than the requested size, this will silently truncate the string.
Definition at line 377 of file streamWriter.I.
References append_data(), and pad_bytes().
void StreamWriter::add_float32 | ( | float | value | ) | [inline] |
Adds a 32-bit single-precision floating-point number to the stream.
Since this kind of float is not necessarily portable across different architectures, special care is required.
Definition at line 195 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
void StreamWriter::add_float64 | ( | PN_float64 | value | ) | [inline] |
Adds a 64-bit floating-point number to the stream.
Definition at line 210 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
void StreamWriter::add_int16 | ( | PN_int16 | value | ) | [inline] |
Adds a signed 16-bit integer to the stream.
Definition at line 126 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
void StreamWriter::add_int32 | ( | PN_int32 | value | ) | [inline] |
Adds a signed 32-bit integer to the stream.
Definition at line 137 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
Referenced by DownloadDb::Db::write_bogus_header().
void StreamWriter::add_int64 | ( | PN_int64 | value | ) | [inline] |
Adds a signed 64-bit integer to the stream.
Definition at line 148 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
void StreamWriter::add_int8 | ( | PN_int8 | value | ) | [inline] |
Adds a signed 8-bit integer to the stream.
Definition at line 106 of file streamWriter.I.
References append_data().
void StreamWriter::add_string | ( | const string & | str | ) | [inline] |
Adds a variable-length string to the stream.
This actually adds a count followed by n bytes.
Definition at line 324 of file streamWriter.I.
References add_uint16(), and append_data().
void StreamWriter::add_string32 | ( | const string & | str | ) | [inline] |
Adds a variable-length string to the stream, using a 32-bit length field.
Definition at line 342 of file streamWriter.I.
References add_uint32(), and append_data().
void StreamWriter::add_uint16 | ( | PN_uint16 | value | ) | [inline] |
Adds an unsigned 16-bit integer to the stream.
Definition at line 159 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
Referenced by add_string().
void StreamWriter::add_uint32 | ( | PN_uint32 | value | ) | [inline] |
Adds an unsigned 32-bit integer to the stream.
Definition at line 170 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
Referenced by add_string32(), DatagramOutputFile::copy_datagram(), Multifile::flush(), DatagramOutputFile::put_datagram(), and DownloadDb::Db::write_bogus_header().
void StreamWriter::add_uint64 | ( | PN_uint64 | value | ) | [inline] |
Adds an unsigned 64-bit integer to the stream.
Definition at line 181 of file streamWriter.I.
References append_data(), and NativeNumericData::get_data().
void StreamWriter::add_uint8 | ( | PN_uint8 | value | ) | [inline] |
Adds an unsigned 8-bit integer to the stream.
Definition at line 116 of file streamWriter.I.
References append_data().
Referenced by add_bool(), and add_z_string().
void StreamWriter::add_z_string | ( | string | str | ) | [inline] |
Adds a variable-length string to the stream, as a NULL-terminated string.
Definition at line 357 of file streamWriter.I.
References add_uint8(), and append_data().
void StreamWriter::append_data | ( | const void * | data, |
size_t | size | ||
) | [inline] |
Appends some more raw data to the end of the streamWriter.
Definition at line 394 of file streamWriter.I.
Referenced by add_be_float32(), add_be_float64(), add_be_int16(), add_be_int32(), add_be_int64(), add_be_uint16(), add_be_uint32(), add_be_uint64(), add_fixed_string(), add_float32(), add_float64(), add_int16(), add_int32(), add_int64(), add_int8(), add_string(), add_string32(), add_uint16(), add_uint32(), add_uint64(), add_uint8(), add_z_string(), append_data(), and write().
void StreamWriter::append_data | ( | const string & | data | ) | [inline] |
Appends some more raw data to the end of the streamWriter.
Definition at line 405 of file streamWriter.I.
References append_data().
void StreamWriter::flush | ( | void | ) | [inline] |
Calls flush() on the underlying stream.
Definition at line 415 of file streamWriter.I.
ostream * StreamWriter::get_ostream | ( | ) | const [inline] |
Returns the stream in use.
Definition at line 86 of file streamWriter.I.
void StreamWriter::operator= | ( | const StreamWriter & | copy | ) | [inline] |
The copy constructor does not copy ownership of the stream.
Definition at line 60 of file streamWriter.I.
void StreamWriter::pad_bytes | ( | size_t | size | ) |
Adds the indicated number of zero bytes to the stream.
Definition at line 24 of file streamWriter.cxx.
Referenced by add_fixed_string().
void StreamWriter::write | ( | const string & | data | ) | [inline] |
A synonym of append_data().
This is useful when assigning the StreamWriter to sys.stderr and/or sys.stdout in Python.
Definition at line 427 of file streamWriter.I.
References append_data().