SatCat5
satcat5::io::FileWriter Class Reference

Detailed Description

Write bytes or packets to a file.

Definition at line 16 of file file_io.h.

#include <file_io.h>

Inheritance diagram for satcat5::io::FileWriter:
[legend]
Collaboration diagram for satcat5::io::FileWriter:
[legend]

Public Member Functions

 FileWriter (const char *filename=0, bool close_on_finalize=false)
 Create the FileWriter object. More...
 
void open (const char *filename)
 Open the specified file. More...
 
void close ()
 
void seek (unsigned offset)
 Move write cursor to the specified absolute offset.
 
unsigned get_write_space () const override
 How many bytes can be written without blocking? More...
 
void write_bytes (unsigned nbytes, const void *src)
 Write 0 or more bytes from a buffer. More...
 
bool write_finalize () override
 Mark end of frame and release temporary working data. More...
 
void write_abort () override
 If possible, abort the current partially-written packet. More...
 
void write_u8 (u8 data)
 One of many functions for writing integer/floating point values, see details. More...
 
void write_str (const char *str)
 Write the contents of a null-terminated string. More...
 
template<class T >
void write_obj (const T &obj)
 Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr) const;
 

Protected Member Functions

void write_next (u8 data) override
 Write the next byte to the underlying buffer or device. More...
 
virtual void write_overflow ()
 Optional error handling for write overflow. More...
 

Protected Attributes

const bool m_close_on_finalize
 
FILE * m_file
 
unsigned m_last_commit
 
friend LimitedWrite
 
friend WriteableBroadcast
 
friend WriteableRedirect
 

Constructor & Destructor Documentation

◆ FileWriter()

FileWriter::FileWriter ( const char *  filename = 0,
bool  close_on_finalize = false 
)
explicit

Create the FileWriter object.

Parameters
filenameOptionally open a file immediately.
close_on_finalizeIf true, calling write_finalize closes the current file. If false, keep writing.

Definition at line 19 of file file_io.cc.

Member Function Documentation

◆ get_write_space()

unsigned FileWriter::get_write_space ( ) const
overridevirtual

How many bytes can be written without blocking?

Child objects of io::Writeable MUST override this method.

Implements satcat5::io::Writeable.

Definition at line 53 of file file_io.cc.

◆ open()

void FileWriter::open ( const char *  filename)

Open the specified file.

If "close_on_finalize" is set, then user must call open() after each call to write_finalize().

Definition at line 33 of file file_io.cc.

◆ write_abort()

void FileWriter::write_abort ( )
overridevirtual

If possible, abort the current partially-written packet.

Child objects of io::Writeable SHOULD override this method if it is practical to prevent in-progress data from being relayed downstream.

Reimplemented from satcat5::io::Writeable.

Definition at line 72 of file file_io.cc.

◆ write_bytes()

void FileWriter::write_bytes ( unsigned  nbytes,
const void *  src 
)
virtual

Write 0 or more bytes from a buffer.

Child objects of io::Writeable MAY override write_bytes as needed for performance.

Reimplemented from satcat5::io::Writeable.

Definition at line 59 of file file_io.cc.

◆ write_finalize()

bool FileWriter::write_finalize ( )
overridevirtual

Mark end of frame and release temporary working data.

Child objects of io::Writeable SHOULD override this method to mark frame bounds.

Returns
True if successful, false on error.

Reimplemented from satcat5::io::Writeable.

Definition at line 64 of file file_io.cc.

◆ write_next()

void FileWriter::write_next ( u8  data)
overrideprotectedvirtual

Write the next byte to the underlying buffer or device.

Child objects of io::Writeable MUST override this method.

Implements satcat5::io::Writeable.

Definition at line 84 of file file_io.cc.

◆ write_overflow()

void Writeable::write_overflow ( )
protectedvirtualinherited

◆ write_str()

void Writeable::write_str ( const char *  str)
inherited

Write the contents of a null-terminated string.

Note: Null-termination is not copied to the output.

Definition at line 180 of file io_writeable.cc.

◆ write_u8()

void Writeable::write_u8 ( u8  data)
inherited

One of many functions for writing integer/floating point values, see details.

Several functions are provided for reading and writing scalar types to/from io::Readable and io::Writeable instances. Since there are many of these that are frequently inherited, they are hidden from documentation. These functions follow a shared template:

  • read_ or write_ prefix.
  • u for unsigned, s for signed, f for floating-point.
  • Data-type width in bits.
    • Available widths for ints: 8/16/24/32/48/64.
    • Available widths for floats: 32/64.
  • l suffix if little-endian, no suffix if big-endian.

Example: write_s48l is "Write 48 bits (6 bytes) to this io::Writeable as a signed value in little-endian order".

Definition at line 20 of file io_writeable.cc.


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