Panda3D
|
This class can be used to read a binary file that consists of an arbitrary header followed by a number of datagrams. More...
#include "datagramInputFile.h"
Public Member Functions | |
void | close () |
Closes the file. | |
virtual bool | get_datagram (Datagram &data) |
Reads the next datagram from the file. | |
virtual VirtualFile * | get_file () |
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a VirtualFile. | |
virtual streampos | get_file_pos () |
Returns the current file position within the data stream, if any, or 0 if the file position is not meaningful or cannot be determined. | |
virtual bool | is_eof () |
Returns true if the file has reached the end-of-file. | |
virtual bool | is_error () |
Returns true if the file has reached an error condition. | |
bool | open (Filename filename) |
Opens the indicated filename for reading. | |
bool | open (istream &in) |
Starts reading from the indicated stream. | |
bool | read_header (string &header, size_t num_bytes) |
Reads a sequence of bytes from the beginning of the datagram file. |
This class can be used to read a binary file that consists of an arbitrary header followed by a number of datagrams.
Definition at line 30 of file datagramInputFile.h.
void DatagramInputFile::close | ( | ) |
Closes the file.
This is also implicitly done when the DatagramInputFile destructs.
Definition at line 75 of file datagramInputFile.cxx.
References VirtualFileSystem::close_read_file(), and VirtualFileSystem::get_global_ptr().
Referenced by RecorderController::close(), BamFile::close(), and open().
bool DatagramInputFile::get_datagram | ( | Datagram & | data | ) | [virtual] |
Reads the next datagram from the file.
Returns true on success, false if there is an error or end of file.
Implements DatagramGenerator.
Definition at line 124 of file datagramInputFile.cxx.
References Datagram::clear(), Thread::consider_yield(), and StreamReader::get_uint32().
Referenced by NodePath::decode_from_bam_stream().
VirtualFile * DatagramInputFile::get_file | ( | ) | [virtual] |
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a VirtualFile.
Reimplemented from DatagramGenerator.
Definition at line 216 of file datagramInputFile.cxx.
streampos DatagramInputFile::get_file_pos | ( | ) | [virtual] |
Returns the current file position within the data stream, if any, or 0 if the file position is not meaningful or cannot be determined.
For DatagramInputFiles that return a meaningful file position, this will be pointing to the first byte following the datagram returned after a call to get_datagram().
Reimplemented from DatagramGenerator.
Definition at line 233 of file datagramInputFile.cxx.
bool DatagramInputFile::is_eof | ( | ) | [virtual] |
Returns true if the file has reached the end-of-file.
This test may only be made after a call to read_header() or get_datagram() has failed.
Implements DatagramGenerator.
Definition at line 186 of file datagramInputFile.cxx.
bool DatagramInputFile::is_error | ( | ) | [virtual] |
Returns true if the file has reached an error condition.
Implements DatagramGenerator.
Definition at line 197 of file datagramInputFile.cxx.
Referenced by RecorderController::is_error().
bool DatagramInputFile::open | ( | istream & | in | ) |
Starts reading from the indicated stream.
Returns true on success, false on failure. The DatagramInputFile does not take ownership of the stream; you are responsible for closing or deleting it when you are done.
Definition at line 59 of file datagramInputFile.cxx.
References close().
bool DatagramInputFile::open | ( | Filename | filename | ) |
Opens the indicated filename for reading.
Returns true on success, false on failure.
Definition at line 32 of file datagramInputFile.cxx.
References close(), VirtualFileSystem::get_global_ptr(), and Filename::set_binary().
Referenced by RecorderController::begin_playback(), NodePath::decode_from_bam_stream(), TypedWritable::decode_raw_from_bam_stream(), and BamFile::open_read().
bool DatagramInputFile::read_header | ( | string & | header, |
size_t | num_bytes | ||
) |
Reads a sequence of bytes from the beginning of the datagram file.
This may be called any number of times after the file has been opened and before the first datagram is read. It may not be called once the first datagram has been read.
Definition at line 99 of file datagramInputFile.cxx.
References Thread::consider_yield().
Referenced by RecorderController::begin_playback(), NodePath::decode_from_bam_stream(), and TypedWritable::decode_raw_from_bam_stream().