Panda3D

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
DatagramOutputFile Class Reference

This class can be used to write a binary file that consists of an arbitrary header followed by a number of datagrams. More...

`#include "datagramOutputFile.h"`

Inheritance diagram for DatagramOutputFile:

## Public Member Functions
void | close ()
| Closes the file.
virtual bool | copy_datagram (SubfileInfo &result, const Filename &filename)
| Copies the file data from the entire indicated file (via the vfs) as the next datagram.
virtual bool | copy_datagram (SubfileInfo &result, const SubfileInfo &source)
| Copies the file data from the range of the indicated file (outside of the vfs) as the next datagram.
virtual void | flush ()
| Ensures that all datagrams previously written will be visible in the output file.
virtual const FileReference * | get_file ()
| Returns the FileReference that provides the target for these datagrams, if any, or NULL if the datagrams do not written to a file on disk.
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.
virtual const Filename & | get_filename ()
| Returns the filename that provides the target for these datagrams, if any, or empty string if the datagrams do not get written to a file on disk.
std::ostream & | get_stream ()
virtual bool | is_error ()
| Returns true if the file has reached an error condition.
bool | open (const Filename &filename)
| Opens the indicated filename for writing.
bool | open (const FileReference *file)
| Opens the indicated filename for writing.
bool | open (std::ostream &out, const Filename &filename=Filename())
| Starts writing to the indicated stream.
virtual bool | put_datagram (const Datagram &data)
| Writes the given datagram to the file.
bool | write_header (const std::string &header)
| Writes a sequence of bytes to the beginning of the datagram file.
bool | write_header (const vector_uchar &header)
| Writes a sequence of bytes to the beginning of the datagram file.
Public Member Functions inherited from DatagramSink
| DatagramSink ()
| Does nothing since this is class is just the definition of an interface.
virtual | ~DatagramSink ()
| Does nothing since this is class is just the definition of an interface.

## Public Attributes
| get_stream
| Returns the ostream represented by the output file.
Public Attributes inherited from DatagramSink
| get_file
| Returns the FileReference that provides the target for these datagrams, if any, or NULL if the datagrams do not written to a file on disk.
| 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.
| get_filename
| Returns the filename that provides the target for these datagrams, if any, or empty string if the datagrams do not get written to a file on disk.

## Detailed Description

This class can be used to write a binary file that consists of an arbitrary header followed by a number of datagrams.

Definition at line 30 of file datagramOutputFile.h.

## Constructor & Destructor Documentation

## ◆ DatagramOutputFile()

DatagramOutputFile::DatagramOutputFile | ( |  | ) |
| inline

Definition at line 17 of file datagramOutputFile.I.

## ◆ ~DatagramOutputFile()

DatagramOutputFile::~DatagramOutputFile | ( |  | ) |
| inline

Definition at line 28 of file datagramOutputFile.I.

## Member Function Documentation

## ◆ close()

void DatagramOutputFile::close | ( |  | ) |

Closes the file.

This is also implicitly done when the DatagramOutputFile destructs.

Definition at line 72 of file datagramOutputFile.cxx.

References VirtualFileSystem::get_global_ptr().

Referenced by open(), open(), and BamCache::store().

## ◆ copy_datagram() [1/2]

bool DatagramOutputFile::copy_datagram | ( | SubfileInfo & | result,
|  | const Filename & | filename )
| virtual

Copies the file data from the entire indicated file (via the vfs) as the next datagram.

This is intended to support potentially very large datagrams.

Returns true on success, false on failure or if this method is unimplemented. On true, fills "result" with the information that references the copied file, if possible.

Reimplemented from DatagramSink.

Definition at line 158 of file datagramOutputFile.cxx.

References StreamWriter::add_uint32(), StreamWriter::add_uint64(), and VirtualFileSystem::get_global_ptr().

## ◆ copy_datagram() [2/2]

bool DatagramOutputFile::copy_datagram | ( | SubfileInfo & | result,
|  | const SubfileInfo & | source )
| virtual

Copies the file data from the range of the indicated file (outside of the vfs) as the next datagram.

This is intended to support potentially very large datagrams.

Returns true on success, false on failure or if this method is unimplemented. On true, fills "result" with the information that references the copied file, if possible.

Reimplemented from DatagramSink.

Definition at line 227 of file datagramOutputFile.cxx.

References StreamWriter::add_uint32(), StreamWriter::add_uint64(), SubfileInfo::get_filename(), SubfileInfo::get_size(), SubfileInfo::get_start(), and Filename::open_read().

## ◆ flush()

void DatagramOutputFile::flush | ( |  | ) |
| virtual

Ensures that all datagrams previously written will be visible in the output file.

Implements DatagramSink.

Definition at line 298 of file datagramOutputFile.cxx.

## ◆ get_file()

const FileReference * DatagramOutputFile::get_file | ( |  | ) |
| virtual

Returns the FileReference that provides the target for these datagrams, if any, or NULL if the datagrams do not written to a file on disk.

Reimplemented from DatagramSink.

Definition at line 319 of file datagramOutputFile.cxx.

## ◆ get_file_pos()

streampos DatagramOutputFile::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 DatagramOutputFiles that return a meaningful file position, this will be pointing to the first byte following the datagram returned after a call to put_datagram().

Reimplemented from DatagramSink.

Definition at line 332 of file datagramOutputFile.cxx.

Referenced by BamCache::store().

## ◆ get_filename()

const Filename & DatagramOutputFile::get_filename | ( |  | ) |
| virtual

Returns the filename that provides the target for these datagrams, if any, or empty string if the datagrams do not get written to a file on disk.

Reimplemented from DatagramSink.

Definition at line 310 of file datagramOutputFile.cxx.

## ◆ is_error()

bool DatagramOutputFile::is_error | ( |  | ) |
| virtual

Returns true if the file has reached an error condition.

Implements DatagramSink.

Definition at line 282 of file datagramOutputFile.cxx.

## ◆ open() [1/3]

bool DatagramOutputFile::open | ( | const Filename & | filename | ) |
| inline

Opens the indicated filename for writing.

Returns true on success, false on failure.

Definition at line 37 of file datagramOutputFile.I.

References open().

## ◆ open() [2/3]

bool DatagramOutputFile::open | ( | const FileReference * | file | ) |

Opens the indicated filename for writing.

Returns true if successful, false on failure.

Definition at line 27 of file datagramOutputFile.cxx.

References close(), FileReference::get_filename(), VirtualFileSystem::get_global_ptr(), and Filename::set_binary().

Referenced by open(), and BamCache::store().

## ◆ open() [3/3]

bool DatagramOutputFile::open | ( | std::ostream & | out,
|  | const Filename & | filename = Filename() )

Starts writing to the indicated stream.

Returns true on success, false on failure. The DatagramOutputFile does not take ownership of the stream; you are responsible for closing or deleting it when you are done.

Definition at line 53 of file datagramOutputFile.cxx.

References close().

## ◆ put_datagram()

bool DatagramOutputFile::put_datagram | ( | const Datagram & | data | ) |
| virtual

Writes the given datagram to the file.

Returns true on success, false if there is an error.

Implements DatagramSink.

Definition at line 125 of file datagramOutputFile.cxx.

References StreamWriter::add_uint32(), and StreamWriter::add_uint64().

## ◆ write_header() [1/2]

bool DatagramOutputFile::write_header | ( | const std::string & | header | ) |

Writes a sequence of bytes to 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 written. It may not be called once the first datagram is written.

Definition at line 111 of file datagramOutputFile.cxx.

## ◆ write_header() [2/2]

bool DatagramOutputFile::write_header | ( | const vector_uchar & | header | ) |

Writes a sequence of bytes to 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 written. It may not be called once the first datagram is written.

Definition at line 95 of file datagramOutputFile.cxx.

Referenced by BamCache::store().

## Member Data Documentation

## ◆ get_stream

std::ostream & DatagramOutputFile::get_stream
| inline

Returns the ostream represented by the output file.

Definition at line 57 of file datagramOutputFile.h.

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

- panda/src/putil/datagramOutputFile.h
- panda/src/putil/datagramOutputFile.cxx
- panda/src/putil/datagramOutputFile.I