Provides an interface for reading from and writing to files with stream.
More...
#include <filestream.h>
|
| FileStream () |
|
| FileStream (const std::string &path) |
|
virtual ssize_t | write (const char *data, size_t maxSize) |
|
ssize_t | write (const char *str) |
|
ssize_t | write (const std::string &str) |
|
ssize_t | write (char c) |
|
virtual ssize_t | read (char *data, size_t maxSize) |
|
virtual bool | open (OpenMode mode=ReadWrite) |
|
virtual void | close () |
|
virtual void | setPath (const std::string &path) |
|
virtual std::string | path () const |
|
bool | setFd (int fd) |
|
int | fd () const |
|
bool | isOurFile () const |
|
OpenMode | openMode () const |
| Returns the current open mode of the device.
|
|
virtual bool | isOpen () const |
| Returns true if the device is currently open.
|
|
bool | isReadable () const |
| Returns true if the device is readable.
|
|
bool | isWritable () const |
| Returns true if the device is writable.
|
|
bool | isBuffered () const |
| Returns true if the device is buffered.
|
|
virtual bool | isSequential () const |
| Returns true if this device is sequential; otherwise returns false.
|
|
void | setTextModeEnabled (bool enabled) |
| Enables or disables text mode for the device.
|
|
bool | isTextModeEnabled () const |
| Returns true if text mode is enabled.
|
|
void | setDebug (bool enabled) |
| Enables or disables debug mode for the device.
|
|
bool | isDebug () const |
| Returns true if debug mode is enabled.
|
|
virtual std::string | errorString () const |
| Returns a human-readable description of the last error.
|
|
virtual int | error () const |
| Returns the code of the last error.
|
|
|
std::unique_ptr< Private > | d_ptr |
| Pointer to the private implementation.
|
|
Provides an interface for reading from and writing to files with stream.
Definition at line 34 of file filestream.h.
◆ OpenMode
Type representing a combination of OpenModeFlag values.
Definition at line 70 of file iodevice.h.
◆ OpenModeFlag
Flags that specify how the device is to be opened.
These flags control the behavior of the device when it is opened. They can be combined using bitwise OR.
Enumerator |
---|
NotOpen | Device is not open.
|
Append | Set the stream's position indicator to the end of the stream before each output operation.
|
AtEnd | Set the stream's position indicator to the end of the stream on opening.
|
Binary | Open the device in binary mode (no text translation).
|
ReadOnly | Open the device for input operations only.
Text mode: When reading, end-of-line terminators are translated to '
'. When writing, end-of-line terminators are translated to the local encoding (e.g., '\r
' for Win32).
|
WriteOnly | Open the device for output operations only.
|
ReadWrite | Open the device for both input and output operations.
|
Truncate | Discard any existing content when opening the device.
|
IosModes | Combination of all standard I/O modes.
|
Unbuffered | Open the device in unbuffered mode (implementation-defined).
|
Definition at line 48 of file iodevice.h.
◆ FileStream() [1/3]
Piduino::FileStream::FileStream |
( |
| ) |
|
◆ FileStream() [2/3]
Piduino::FileStream::FileStream |
( |
const std::string & |
path | ) |
|
Constructs a new stream object to represent the file with the given path.
◆ FileStream() [3/3]
Piduino::FileStream::FileStream |
( |
Private & |
dd | ) |
|
|
protected |
◆ close()
virtual void Piduino::FileDevice::close |
( |
| ) |
|
|
virtualinherited |
Closes the device and sets its OpenMode to NotOpen
Reimplemented from Piduino::IoDevice.
◆ error()
virtual int Piduino::IoDevice::error |
( |
| ) |
const |
|
virtualinherited |
Returns the code of the last error.
- Returns
- The error code.
◆ errorString()
virtual std::string Piduino::IoDevice::errorString |
( |
| ) |
const |
|
virtualinherited |
Returns a human-readable description of the last error.
- Returns
- The error string.
◆ fd()
int Piduino::FileDevice::fd |
( |
| ) |
const |
|
inherited |
Returns the file descriptor of the file, if it is open, else returns -1.
Do not use the close() function with this descriptor !
◆ isBuffered()
bool Piduino::IoDevice::isBuffered |
( |
| ) |
const |
|
inherited |
Returns true if the device is buffered.
- Returns
- True if buffered, false otherwise.
◆ isDebug()
bool Piduino::IoDevice::isDebug |
( |
| ) |
const |
|
inherited |
Returns true if debug mode is enabled.
- Returns
- True if debug mode is enabled, false otherwise.
◆ isOpen()
virtual bool Piduino::IoDevice::isOpen |
( |
| ) |
const |
|
virtualinherited |
Returns true if the device is currently open.
- Returns
- True if open, false otherwise.
◆ isOurFile()
bool Piduino::FileDevice::isOurFile |
( |
| ) |
const |
|
inherited |
◆ isReadable()
bool Piduino::IoDevice::isReadable |
( |
| ) |
const |
|
inherited |
Returns true if the device is readable.
- Returns
- True if readable, false otherwise.
◆ isSequential()
virtual bool Piduino::IoDevice::isSequential |
( |
| ) |
const |
|
virtualinherited |
Returns true if this device is sequential; otherwise returns false.
Sequential devices, as opposed to random-access devices, have no concept of a start, an end, a size, or a current position, and do not support seeking. You can only read from the device when it reports that data is available. The most common example of a sequential device is a network socket. On Unix, special files such as /dev/zero and fifo pipes are sequential. Regular files, on the other hand, do support random access. They have both a size and a current position, and they also support seeking backwards and forwards in the data stream. Regular files are non-sequential.
The IoDevice implementation returns false.
- Returns
- True if the device is sequential, false otherwise.
◆ isTextModeEnabled()
bool Piduino::IoDevice::isTextModeEnabled |
( |
| ) |
const |
|
inherited |
Returns true if text mode is enabled.
- Returns
- True if text mode is enabled, false otherwise.
◆ isWritable()
bool Piduino::IoDevice::isWritable |
( |
| ) |
const |
|
inherited |
Returns true if the device is writable.
- Returns
- True if writable, false otherwise.
◆ open()
Opens the file device using OpenMode mode, and then returns true
if successful; otherwise returns false
and sets an error code which can be obtained by calling the error() method. The error string is also reset.
Reimplemented from Piduino::IoDevice.
◆ openMode()
OpenMode Piduino::IoDevice::openMode |
( |
| ) |
const |
|
inherited |
Returns the current open mode of the device.
- Returns
- The open mode flags.
◆ path()
virtual std::string Piduino::FileDevice::path |
( |
| ) |
const |
|
virtualinherited |
◆ read()
virtual ssize_t Piduino::FileStream::read |
( |
char * |
data, |
|
|
size_t |
maxSize |
|
) |
| |
|
virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Reads at most maxSize bytes from the stream into data, and returns the number of bytes read. If an error occurs, such as when attempting to read from a stream opened in WriteOnly mode, this function returns -1.
0 is returned when no more data is available for reading. However, reading past the end of the stream is considered an error, so this function returns -1 in those cases (that is, reading on a closed socket or after a process has died).
- See also
- write()
Reimplemented from Piduino::FileDevice.
Reimplemented in Piduino::Terminal.
◆ setDebug()
void Piduino::IoDevice::setDebug |
( |
bool |
enabled | ) |
|
|
inherited |
Enables or disables debug mode for the device.
- Parameters
-
enabled | True to enable debug mode, false to disable. |
◆ setFd()
bool Piduino::FileDevice::setFd |
( |
int |
fd | ) |
|
|
inherited |
◆ setPath()
virtual void Piduino::FileDevice::setPath |
( |
const std::string & |
path | ) |
|
|
virtualinherited |
Sets the path of the file. The path can have no prefix, a relative path, or an absolute path.
Do not call this function if the file has already been opened, if so, the file is closed before the path is modified.
If the file name has no path or a relative path, the path used will be the application's current directory path at the time of the open() call.
Note that the directory separator is "/".
- See also
- path()
◆ setTextModeEnabled()
void Piduino::IoDevice::setTextModeEnabled |
( |
bool |
enabled | ) |
|
|
inherited |
Enables or disables text mode for the device.
- Parameters
-
enabled | True to enable text mode, false to disable. |
◆ write() [1/4]
ssize_t Piduino::FileStream::write |
( |
char |
c | ) |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Writes the character c to the stream. Returns the number of bytes that were actually written, or -1 if an error occurred.
- See also
- read()
◆ write() [2/4]
virtual ssize_t Piduino::FileStream::write |
( |
const char * |
data, |
|
|
size_t |
maxSize |
|
) |
| |
|
virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Writes at most maxSize bytes of data from data to the stream. Returns the number of bytes that were actually written, or -1 if an error occurred.
- See also
- read()
Reimplemented from Piduino::FileDevice.
Reimplemented in Piduino::SerialPort.
◆ write() [3/4]
ssize_t Piduino::FileStream::write |
( |
const char * |
str | ) |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Writes data from a zero-terminated string of 8-bit characters to the stream. Returns the number of bytes that were actually written, or -1 if an error occurred.
- See also
- read()
◆ write() [4/4]
ssize_t Piduino::FileStream::write |
( |
const std::string & |
str | ) |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Writes the content of string to the stream. Returns the number of bytes that were actually written, or -1 if an error occurred.
- See also
- read()
◆ d_ptr
std::unique_ptr<Private> Piduino::IoDevice::d_ptr |
|
protectedinherited |
Pointer to the private implementation.
Definition at line 190 of file iodevice.h.