Panda3D
Public Member Functions | Public Attributes | List of all members
StreamWriter Class Reference

A StreamWriter object is used to write sequential binary data directly to an ostream. More...

#include "streamWriter.h"

Public Member Functions

 StreamWriter (std::ostream &out)
 
 StreamWriter (std::ostream *out, bool owns_stream)
 
 StreamWriter (const StreamWriter &copy)
 The copy constructor does not copy ownership of the stream. More...
 
void add_be_float32 (float value)
 Adds a 32-bit single-precision big-endian floating-point number to the stream. More...
 
void add_be_float64 (PN_float64 value)
 Adds a 64-bit big-endian floating-point number to the streamWriter. More...
 
void add_be_int16 (int16_t value)
 Adds a signed 16-bit big-endian integer to the streamWriter. More...
 
void add_be_int32 (int32_t value)
 Adds a signed 32-bit big-endian integer to the streamWriter. More...
 
void add_be_int64 (int64_t value)
 Adds a signed 64-bit big-endian integer to the streamWriter. More...
 
void add_be_uint16 (uint16_t value)
 Adds an unsigned 16-bit big-endian integer to the streamWriter. More...
 
void add_be_uint32 (uint32_t value)
 Adds an unsigned 32-bit big-endian integer to the streamWriter. More...
 
void add_be_uint64 (uint64_t value)
 Adds an unsigned 64-bit big-endian integer to the streamWriter. More...
 
void add_bool (bool value)
 Adds a boolean value to the stream. More...
 
void add_fixed_string (const std::string &str, size_t size)
 Adds a fixed-length string to the stream. More...
 
void add_float32 (float value)
 Adds a 32-bit single-precision floating-point number to the stream. More...
 
void add_float64 (PN_float64 value)
 Adds a 64-bit floating-point number to the stream. More...
 
void add_int16 (int16_t value)
 Adds a signed 16-bit integer to the stream. More...
 
void add_int32 (int32_t value)
 Adds a signed 32-bit integer to the stream. More...
 
void add_int64 (int64_t value)
 Adds a signed 64-bit integer to the stream. More...
 
void add_int8 (int8_t value)
 Adds a signed 8-bit integer to the stream. More...
 
void add_string (const std::string &str)
 Adds a variable-length string to the stream. More...
 
void add_string32 (const std::string &str)
 Adds a variable-length string to the stream, using a 32-bit length field. More...
 
void add_uint16 (uint16_t value)
 Adds an unsigned 16-bit integer to the stream. More...
 
void add_uint32 (uint32_t value)
 Adds an unsigned 32-bit integer to the stream. More...
 
void add_uint64 (uint64_t value)
 Adds an unsigned 64-bit integer to the stream. More...
 
void add_uint8 (uint8_t value)
 Adds an unsigned 8-bit integer to the stream. More...
 
void add_z_string (std::string str)
 Adds a variable-length string to the stream, as a NULL-terminated string. More...
 
void append_data (const void *data, size_t size)
 Appends some more raw data to the end of the streamWriter. More...
 
void append_data (const std::string &data)
 Appends some more raw data to the end of the streamWriter. More...
 
void flush ()
 Calls flush() on the underlying stream. More...
 
std::ostream * get_ostream () const
 
void operator= (const StreamWriter &copy)
 The copy constructor does not copy ownership of the stream. More...
 
void pad_bytes (size_t size)
 Adds the indicated number of zero bytes to the stream. More...
 
void write (const std::string &str)
 A synonym of append_data(). More...
 

Public Attributes

 get_ostream
 Returns the stream in use. More...
 

Detailed Description

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 29 of file streamWriter.h.

Constructor & Destructor Documentation

◆ StreamWriter()

StreamWriter::StreamWriter ( const StreamWriter copy)
inline

The copy constructor does not copy ownership of the stream.

Definition at line 44 of file streamWriter.I.

Member Function Documentation

◆ add_be_float32()

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 245 of file streamWriter.I.

◆ add_be_float64()

void StreamWriter::add_be_float64 ( PN_float64  value)
inline

Adds a 64-bit big-endian floating-point number to the streamWriter.

Definition at line 258 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

◆ add_be_int16()

void StreamWriter::add_be_int16 ( int16_t  value)
inline

Adds a signed 16-bit big-endian integer to the streamWriter.

Definition at line 189 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

◆ add_be_int32()

void StreamWriter::add_be_int32 ( int32_t  value)
inline

Adds a signed 32-bit big-endian integer to the streamWriter.

Definition at line 198 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

◆ add_be_int64()

void StreamWriter::add_be_int64 ( int64_t  value)
inline

Adds a signed 64-bit big-endian integer to the streamWriter.

Definition at line 207 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

◆ add_be_uint16()

void StreamWriter::add_be_uint16 ( uint16_t  value)
inline

Adds an unsigned 16-bit big-endian integer to the streamWriter.

Definition at line 216 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

◆ add_be_uint32()

void StreamWriter::add_be_uint32 ( uint32_t  value)
inline

Adds an unsigned 32-bit big-endian integer to the streamWriter.

Definition at line 225 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

Referenced by HashVal::output_binary().

◆ add_be_uint64()

void StreamWriter::add_be_uint64 ( uint64_t  value)
inline

Adds an unsigned 64-bit big-endian integer to the streamWriter.

Definition at line 234 of file streamWriter.I.

References append_data(), and ReversedNumericData::get_data().

◆ add_bool()

void StreamWriter::add_bool ( bool  value)
inline

Adds a boolean value to the stream.

Definition at line 87 of file streamWriter.I.

References add_uint8().

◆ add_fixed_string()

void StreamWriter::add_fixed_string ( const std::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 311 of file streamWriter.I.

References append_data(), and pad_bytes().

◆ add_float32()

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 167 of file streamWriter.I.

◆ add_float64()

void StreamWriter::add_float64 ( PN_float64  value)
inline

Adds a 64-bit floating-point number to the stream.

Definition at line 180 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

◆ add_int16()

void StreamWriter::add_int16 ( int16_t  value)
inline

Adds a signed 16-bit integer to the stream.

Definition at line 111 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

◆ add_int32()

void StreamWriter::add_int32 ( int32_t  value)
inline

Adds a signed 32-bit integer to the stream.

Definition at line 120 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

Referenced by DownloadDb::Db::write_bogus_header().

◆ add_int64()

void StreamWriter::add_int64 ( int64_t  value)
inline

Adds a signed 64-bit integer to the stream.

Definition at line 129 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

◆ add_int8()

void StreamWriter::add_int8 ( int8_t  value)
inline

Adds a signed 8-bit integer to the stream.

Definition at line 95 of file streamWriter.I.

References append_data().

◆ add_string()

void StreamWriter::add_string ( const std::string &  str)
inline

Adds a variable-length string to the stream.

This actually adds a count followed by n bytes.

Definition at line 268 of file streamWriter.I.

◆ add_string32()

void StreamWriter::add_string32 ( const std::string &  str)
inline

Adds a variable-length string to the stream, using a 32-bit length field.

Definition at line 283 of file streamWriter.I.

References add_uint32(), and append_data().

◆ add_uint16()

void StreamWriter::add_uint16 ( uint16_t  value)
inline

Adds an unsigned 16-bit integer to the stream.

Definition at line 138 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

◆ add_uint32()

void StreamWriter::add_uint32 ( uint32_t  value)
inline

Adds an unsigned 32-bit integer to the stream.

Definition at line 147 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

Referenced by add_string32(), and DownloadDb::Db::write_bogus_header().

◆ add_uint64()

void StreamWriter::add_uint64 ( uint64_t  value)
inline

Adds an unsigned 64-bit integer to the stream.

Definition at line 156 of file streamWriter.I.

References append_data(), and NativeNumericData::get_data().

◆ add_uint8()

void StreamWriter::add_uint8 ( uint8_t  value)
inline

Adds an unsigned 8-bit integer to the stream.

Definition at line 103 of file streamWriter.I.

References append_data().

Referenced by add_bool(), and add_z_string().

◆ add_z_string()

void StreamWriter::add_z_string ( std::string  str)
inline

Adds a variable-length string to the stream, as a NULL-terminated string.

Definition at line 295 of file streamWriter.I.

References add_uint8(), and append_data().

◆ append_data() [1/2]

void StreamWriter::append_data ( const void *  data,
size_t  size 
)
inline

◆ append_data() [2/2]

void StreamWriter::append_data ( const std::string &  data)
inline

Appends some more raw data to the end of the streamWriter.

Definition at line 333 of file streamWriter.I.

◆ flush()

void StreamWriter::flush ( void  )
inline

Calls flush() on the underlying stream.

Definition at line 341 of file streamWriter.I.

◆ operator=()

void StreamWriter::operator= ( const StreamWriter copy)
inline

The copy constructor does not copy ownership of the stream.

Definition at line 57 of file streamWriter.I.

◆ pad_bytes()

void StreamWriter::pad_bytes ( size_t  size)

Adds the indicated number of zero bytes to the stream.

Definition at line 20 of file streamWriter.cxx.

Referenced by add_fixed_string().

◆ write()

void StreamWriter::write ( const std::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 350 of file streamWriter.I.

Member Data Documentation

◆ get_ostream

std::ostream * StreamWriter::get_ostream
inline

Returns the stream in use.

Definition at line 39 of file streamWriter.h.


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