Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

StreamReader Class Reference

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

#include <streamReader.h>

List of all members.

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.

 StreamReader (const StreamReader &copy)
 The copy constructor does not copy ownership of the stream.

void operator= (const StreamReader &copy)
 The copy constructor does not copy ownership of the stream.

 ~StreamReader ()
istream * get_istream () const
 Returns the stream in use.

bool get_bool ()
 Extracts a boolean value.

PN_int8 get_int8 ()
 Extracts a signed 8-bit integer.

PN_uint8 get_uint8 ()
 Extracts an unsigned 8-bit integer.

PN_int16 get_int16 ()
 Extracts a signed 16-bit integer.

PN_int32 get_int32 ()
 Extracts a signed 32-bit integer.

PN_int64 get_int64 ()
 Extracts a signed 64-bit integer.

PN_uint16 get_uint16 ()
 Extracts an unsigned 16-bit integer.

PN_uint32 get_uint32 ()
 Extracts an unsigned 32-bit integer.

PN_uint64 get_uint64 ()
 Extracts an unsigned 64-bit integer.

float get_float32 ()
 Extracts a 32-bit single-precision floating-point number.

PN_float64 get_float64 ()
 Extracts a 64-bit floating-point number.

PN_int16 get_be_int16 ()
 Extracts a signed big-endian 16-bit integer.

PN_int32 get_be_int32 ()
 Extracts a signed big-endian 32-bit integer.

PN_int64 get_be_int64 ()
 Extracts a signed big-endian 64-bit integer.

PN_uint16 get_be_uint16 ()
 Extracts an unsigned big-endian 16-bit integer.

PN_uint32 get_be_uint32 ()
 Extracts an unsigned big-endian 32-bit integer.

PN_uint64 get_be_uint64 ()
 Extracts an unsigned big-endian 64-bit integer.

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.

string get_string ()
 Extracts a variable-length string.

string get_z_string ()
 Extracts a variable-length string, as a NULL-terminated string.

string get_fixed_string (size_t size)
 Extracts a fixed-length string.

void skip_bytes (size_t size)
 Skips over the indicated number of bytes in the stream.

string extract_bytes (size_t size)
 Extracts the indicated number of bytes in the stream and returns them as a string.

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


Private Attributes

istream * _in
bool _owns_stream


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 42 of file streamReader.h.


Constructor & Destructor Documentation

StreamReader::StreamReader istream &  in  )  [inline]
 

Definition at line 31 of file streamReader.I.

References INLINE.

StreamReader::StreamReader istream *  in,
bool  owns_stream
[inline]
 

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

Definition at line 48 of file streamReader.I.

References INLINE.

StreamReader::StreamReader const StreamReader &  copy  )  [inline]
 

The copy constructor does not copy ownership of the stream.

Definition at line 65 of file streamReader.I.

References _in, and _owns_stream.

StreamReader::~StreamReader  )  [inline]
 

Definition at line 95 of file streamReader.I.

References get_uint8(), and INLINE.


Member Function Documentation

string StreamReader::extract_bytes size_t  size  ) 
 

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

Definition at line 129 of file streamReader.cxx.

References _in.

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 417 of file streamReader.I.

PN_float64 StreamReader::get_be_float64  )  [inline]
 

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

Definition at line 439 of file streamReader.I.

PN_int16 StreamReader::get_be_int16  )  [inline]
 

Extracts a signed big-endian 16-bit integer.

Definition at line 309 of file streamReader.I.

PN_int32 StreamReader::get_be_int32  )  [inline]
 

Extracts a signed big-endian 32-bit integer.

Definition at line 326 of file streamReader.I.

References _in, INLINE, and nassertr.

PN_int64 StreamReader::get_be_int64  )  [inline]
 

Extracts a signed big-endian 64-bit integer.

Definition at line 343 of file streamReader.I.

PN_uint16 StreamReader::get_be_uint16  )  [inline]
 

Extracts an unsigned big-endian 16-bit integer.

Definition at line 360 of file streamReader.I.

PN_uint32 StreamReader::get_be_uint32  )  [inline]
 

Extracts an unsigned big-endian 32-bit integer.

Definition at line 377 of file streamReader.I.

PN_uint64 StreamReader::get_be_uint64  )  [inline]
 

Extracts an unsigned big-endian 64-bit integer.

Definition at line 394 of file streamReader.I.

bool StreamReader::get_bool  )  [inline]
 

Extracts a boolean value.

Definition at line 123 of file streamReader.I.

References _in, INLINE, PN_int16, and NativeNumericData::store_value().

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 84 of file streamReader.cxx.

References _in, and nassertv.

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 270 of file streamReader.I.

References _in, INLINE, PN_int64, and ReversedNumericData::store_value().

PN_float64 StreamReader::get_float64  )  [inline]
 

Extracts a 64-bit floating-point number.

Definition at line 292 of file streamReader.I.

References _in.

PN_int16 StreamReader::get_int16  )  [inline]
 

Extracts a signed 16-bit integer.

Definition at line 162 of file streamReader.I.

PN_int32 StreamReader::get_int32  )  [inline]
 

Extracts a signed 32-bit integer.

Definition at line 179 of file streamReader.I.

References _in, INLINE, PN_uint32, and NativeNumericData::store_value().

PN_int64 StreamReader::get_int64  )  [inline]
 

Extracts a signed 64-bit integer.

Definition at line 196 of file streamReader.I.

References _in, INLINE, PN_uint64, and NativeNumericData::store_value().

PN_int8 StreamReader::get_int8  )  [inline]
 

Extracts a signed 8-bit integer.

Definition at line 136 of file streamReader.I.

References _in, INLINE, PN_int32, and NativeNumericData::store_value().

istream * StreamReader::get_istream  )  const [inline]
 

Returns the stream in use.

Definition at line 110 of file streamReader.I.

string StreamReader::get_string  ) 
 

Extracts a variable-length string.

Definition at line 34 of file streamReader.cxx.

References size_t.

PN_uint16 StreamReader::get_uint16  )  [inline]
 

Extracts an unsigned 16-bit integer.

Definition at line 213 of file streamReader.I.

References _in, INLINE, nassertr, and NativeNumericData::store_value().

PN_uint32 StreamReader::get_uint32  )  [inline]
 

Extracts an unsigned 32-bit integer.

Definition at line 230 of file streamReader.I.

References _in, INLINE, PN_float64, and NativeNumericData::store_value().

PN_uint64 StreamReader::get_uint64  )  [inline]
 

Extracts an unsigned 64-bit integer.

Definition at line 247 of file streamReader.I.

References _in, INLINE, PN_int16, and ReversedNumericData::store_value().

PN_uint8 StreamReader::get_uint8  )  [inline]
 

Extracts an unsigned 8-bit integer.

Definition at line 149 of file streamReader.I.

References _in, INLINE, PN_int64, and NativeNumericData::store_value().

Referenced by ~StreamReader().

string StreamReader::get_z_string  ) 
 

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

Definition at line 59 of file streamReader.cxx.

void StreamReader::operator= const StreamReader &  copy  )  [inline]
 

The copy constructor does not copy ownership of the stream.

Definition at line 82 of file streamReader.I.

References _in, and INLINE.

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 165 of file streamReader.cxx.

void StreamReader::skip_bytes size_t  size  ) 
 

Skips over the indicated number of bytes in the stream.

Definition at line 108 of file streamReader.cxx.

References _in, and size_t.


Member Data Documentation

istream* StreamReader::_in [private]
 

Definition at line 85 of file streamReader.h.

Referenced by extract_bytes(), get_be_int32(), get_bool(), get_fixed_string(), get_float32(), get_float64(), get_int32(), get_int64(), get_int8(), get_uint16(), get_uint32(), get_uint64(), get_uint8(), operator=(), skip_bytes(), and StreamReader().

bool StreamReader::_owns_stream [private]
 

Definition at line 86 of file streamReader.h.

Referenced by StreamReader().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:55:19 2003 for Panda by doxygen1.3