Panda3D
Public Member Functions | List of all members
DatagramInputFile Class Reference

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"

Inheritance diagram for DatagramInputFile:
DatagramGenerator

Public Member Functions

void close ()
 Closes the file. More...
 
virtual bool get_datagram (Datagram &data)
 Reads the next datagram from the file. More...
 
virtual const FileReferenceget_file ()
 Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a file on disk. More...
 
virtual std::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. More...
 
virtual const Filenameget_filename ()
 Returns the filename that provides the source for these datagrams, if any, or empty string if the datagrams do not originate from a file on disk. More...
 
std::istream & get_stream ()
 Returns the istream represented by the input file. More...
 
virtual time_t get_timestamp () const
 Returns the on-disk timestamp of the file that was read, at the time it was opened, if that is available, or 0 if it is not. More...
 
virtual VirtualFileget_vfile ()
 Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a VirtualFile. More...
 
virtual bool is_eof ()
 Returns true if the file has reached the end-of-file. More...
 
virtual bool is_error ()
 Returns true if the file has reached an error condition. More...
 
bool open (const FileReference *file)
 Opens the indicated filename for reading. More...
 
bool open (const Filename &filename)
 Opens the indicated filename for reading. More...
 
bool open (std::istream &in, const Filename &filename=Filename())
 Starts reading from the indicated stream. More...
 
bool read_header (std::string &header, size_t num_bytes)
 Reads a sequence of bytes from the beginning of the datagram file. More...
 
virtual bool save_datagram (SubfileInfo &info)
 Skips over the next datagram without extracting it, but saves the relevant file information in the SubfileInfo object so that its data may be read later. More...
 
- Public Member Functions inherited from DatagramGenerator
 DatagramGenerator ()
 Does nothing since this is class is just the definition of an interface. More...
 
virtual ~DatagramGenerator ()
 Does nothing since this is class is just the definition of an interface. More...
 

Detailed Description

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 28 of file datagramInputFile.h.

Member Function Documentation

◆ close()

void DatagramInputFile::close ( )

Closes the file.

This is also implicitly done when the DatagramInputFile destructs.

Definition at line 80 of file datagramInputFile.cxx.

Referenced by RecorderController::close(), BamFile::close(), and open().

◆ get_datagram()

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 126 of file datagramInputFile.cxx.

◆ get_file()

const FileReference * DatagramInputFile::get_file ( )
virtual

Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a file on disk.

Reimplemented from DatagramGenerator.

Definition at line 344 of file datagramInputFile.cxx.

◆ get_file_pos()

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 366 of file datagramInputFile.cxx.

◆ get_filename()

const Filename & DatagramInputFile::get_filename ( )
virtual

Returns the filename that provides the source for these datagrams, if any, or empty string if the datagrams do not originate from a file on disk.

Reimplemented from DatagramGenerator.

Definition at line 326 of file datagramInputFile.cxx.

◆ get_stream()

std::istream & DatagramInputFile::get_stream ( )
inline

Returns the istream represented by the input file.

Definition at line 47 of file datagramInputFile.I.

◆ get_timestamp()

time_t DatagramInputFile::get_timestamp ( ) const
virtual

Returns the on-disk timestamp of the file that was read, at the time it was opened, if that is available, or 0 if it is not.

Reimplemented from DatagramGenerator.

Definition at line 335 of file datagramInputFile.cxx.

◆ get_vfile()

VirtualFile * DatagramInputFile::get_vfile ( )
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 353 of file datagramInputFile.cxx.

◆ is_eof()

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 302 of file datagramInputFile.cxx.

◆ is_error()

bool DatagramInputFile::is_error ( )
virtual

Returns true if the file has reached an error condition.

Implements DatagramGenerator.

Definition at line 310 of file datagramInputFile.cxx.

Referenced by RecorderController::is_error().

◆ open() [1/3]

bool DatagramInputFile::open ( const FileReference file)

Opens the indicated filename for reading.

Returns true on success, false on failure.

Definition at line 33 of file datagramInputFile.cxx.

References close(), and Filename::set_binary().

Referenced by RecorderController::begin_playback(), open(), BamFile::open_read(), and PT().

◆ open() [2/3]

bool DatagramInputFile::open ( const Filename filename)
inline

Opens the indicated filename for reading.

Returns true on success, false on failure.

Definition at line 39 of file datagramInputFile.I.

References open().

◆ open() [3/3]

bool DatagramInputFile::open ( std::istream &  in,
const Filename filename = Filename() 
)

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 60 of file datagramInputFile.cxx.

References close().

◆ read_header()

bool DatagramInputFile::read_header ( std::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 104 of file datagramInputFile.cxx.

Referenced by RecorderController::begin_playback(), and PT().

◆ save_datagram()

bool DatagramInputFile::save_datagram ( SubfileInfo info)
virtual

Skips over the next datagram without extracting it, but saves the relevant file information in the SubfileInfo object so that its data may be read later.

For non-file-based datagram generators, this may mean creating a temporary file and copying the contents of the datagram to disk.

Returns true on success, false on failure or if this method is unimplemented.

Reimplemented from DatagramGenerator.

Definition at line 224 of file datagramInputFile.cxx.


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