Skip to content

FileTransport

class nmeasim::io::FileTransport · Library API

Writes lines to a file, flushing after every write so that the file can be tailed while the simulator runs.

#include <nmeasim/io/transports/file_transport.hpp>

Inherits nmeasim::io::Transport

Declared in src/io/include/nmeasim/io/transports/file_transport.hpp (line 27)

Lines are written byte for byte as given, without timestamps or header: the file is opened in binary mode, so the CR LF that ends every sentence reaches the file unchanged on every platform.

See also

Summary

Public member functions

Name Description
FileTransport() Creates a closed transport for the file at path; nothing is opened until open.
~FileTransport() Destroys the transport, closing the file first.
description() Returns File followed by the path.
open() Opens the file for writing in binary mode, appending or, on the first successful open of a transport created with append false, truncating.
close() Closes the file, flushing what is still buffered, and moves to State::Closed.
write() Writes line to the file and flushes it.
path() Returns the path of the file written to.

Private data members

Name Description
file_ The output file; also holds the path while closed.
append_ True to open in append mode, false to truncate.

Public member functions

FileTransport()

explicit FileTransport(QString path, bool append = true, QObject* parent = nullptr)

Creates a closed transport for the file at path; nothing is opened until open.

Parameters

Name Type Description
path QString Path of the file, absolute or relative to the working directory of the process. The directory must exist; the file is created when it does not.
append bool True to append to an existing file, false to truncate it. Only the first successful open truncates; later opens of the same transport continue the file, so stopping and restarting the simulation does not lose what was written.
parent QObject* Qt parent that owns the transport; null leaves ownership to the caller.

Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:39 · defined in src/io/src/transports/file_transport.cpp:10

~FileTransport()

~FileTransport() override

Destroys the transport, closing the file first.

Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:41 · defined in src/io/src/transports/file_transport.cpp:13

description()

QString description() const override

Returns File followed by the path.

Returns QString: For example File /tmp/output.nmea.

Overrides description · Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:46 · defined in src/io/src/transports/file_transport.cpp:17

open()

bool open() override

Opens the file for writing in binary mode, appending or, on the first successful open of a transport created with append false, truncating.

Returns true at once when already open. Fails with Cannot open <path> for writing and the system's reason when the file cannot be opened, for example because its directory does not exist or is not writable.

Returns bool: True when the file is open, false when opening failed.

Overrides open · Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:55 · defined in src/io/src/transports/file_transport.cpp:21

close()

void close() override

Closes the file, flushing what is still buffered, and moves to State::Closed.

Overrides close · Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:57 · defined in src/io/src/transports/file_transport.cpp:42

write()

void write(const QByteArray& line) override

Writes line to the file and flushes it.

Write errors, such as a full disk, are not reported; they only leave bytes_written unchanged.

Parameters

Name Type Description
line const QByteArray& One complete line, terminator included.

Overrides write · Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:64 · defined in src/io/src/transports/file_transport.cpp:49

path()

QString path() const

Returns the path of the file written to.

Returns QString: The path as passed to the constructor.

Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:69

Private data members

file_

QFile file_

The output file; also holds the path while closed.

Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:73

append_

bool append_

True to open in append mode, false to truncate.

Set to true by the first successful open.

Declared in src/io/include/nmeasim/io/transports/file_transport.hpp:76

Inherited members

From nmeasim::io::FileTransport: bytes_written(), client_count(), client_count_changed(), count_bytes(), error_occurred(), fail(), is_open(), last_error(), set_state(), State, state(), state_changed(), Transport()