PIDUINO
Loading...
Searching...
No Matches
Piduino::IoDevice

Abstract base class for input/output devices. More...

#include <iodevice.h>

Inheritance diagram for Piduino::IoDevice:
Collaboration diagram for Piduino::IoDevice:

Public Types

enum  OpenModeFlag {
  NotOpen = 0x0000 , Append = std::ios_base::app , AtEnd = std::ios_base::ate , Binary = std::ios_base::binary ,
  ReadOnly = std::ios_base::in , WriteOnly = std::ios_base::out , ReadWrite = ReadOnly | WriteOnly , Truncate = std::ios_base::trunc ,
  IosModes = Append | AtEnd | Binary | ReadOnly | WriteOnly | Truncate , Unbuffered = (Truncate << 1)
}
 Flags that specify how the device is to be opened. More...
 
typedef Flags< OpenModeFlagOpenMode
 Type representing a combination of OpenModeFlag values.
 

Public Member Functions

 IoDevice ()
 Constructs a new IoDevice object.
 
virtual ~IoDevice ()
 Destroys the IoDevice object.
 
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 bool open (OpenMode mode)
 Opens the device with the specified open mode.
 
virtual void close ()
 Closes the device.
 
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.
 

Protected Member Functions

 IoDevice (Private &dd)
 Constructs an IoDevice with a given private implementation.
 

Protected Attributes

std::unique_ptr< Privated_ptr
 Pointer to the private implementation.
 

Detailed Description

Abstract base class for input/output devices.

The IoDevice class provides a generic interface for devices that support input and/or output operations. It defines common functionality for file-like objects, such as files, sockets, or pipes, and provides methods to query and control the device's state and mode of operation.

Derived classes should implement the pure virtual methods to provide device-specific behavior.

Definition at line 37 of file iodevice.h.

Member Typedef Documentation

◆ OpenMode

Type representing a combination of OpenModeFlag values.

Definition at line 70 of file iodevice.h.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ IoDevice() [1/2]

Piduino::IoDevice::IoDevice ( )

Constructs a new IoDevice object.

◆ ~IoDevice()

virtual Piduino::IoDevice::~IoDevice ( )
virtual

Destroys the IoDevice object.

◆ IoDevice() [2/2]

Piduino::IoDevice::IoDevice ( Private dd)
protected

Constructs an IoDevice with a given private implementation.

Parameters
ddReference to the private implementation.

Member Function Documentation

◆ close()

virtual void Piduino::IoDevice::close ( )
virtual

Closes the device.

Reimplemented in Piduino::Converter, Piduino::FileDevice, Piduino::I2cDev, and Piduino::SpiDev.

◆ error()

virtual int Piduino::IoDevice::error ( ) const
virtual

Returns the code of the last error.

Returns
The error code.

◆ errorString()

virtual std::string Piduino::IoDevice::errorString ( ) const
virtual

Returns a human-readable description of the last error.

Returns
The error string.

◆ isBuffered()

bool Piduino::IoDevice::isBuffered ( ) const

Returns true if the device is buffered.

Returns
True if buffered, false otherwise.

◆ isDebug()

bool Piduino::IoDevice::isDebug ( ) const

Returns true if debug mode is enabled.

Returns
True if debug mode is enabled, false otherwise.

◆ isOpen()

virtual bool Piduino::IoDevice::isOpen ( ) const
virtual

Returns true if the device is currently open.

Returns
True if open, false otherwise.

◆ isReadable()

bool Piduino::IoDevice::isReadable ( ) const

Returns true if the device is readable.

Returns
True if readable, false otherwise.

◆ isSequential()

virtual bool Piduino::IoDevice::isSequential ( ) const
virtual

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

Returns true if text mode is enabled.

Returns
True if text mode is enabled, false otherwise.

◆ isWritable()

bool Piduino::IoDevice::isWritable ( ) const

Returns true if the device is writable.

Returns
True if writable, false otherwise.

◆ open()

virtual bool Piduino::IoDevice::open ( OpenMode  mode)
virtual

Opens the device with the specified open mode.

Parameters
modeThe open mode flags.
Returns
True if the device was successfully opened, false otherwise.

Reimplemented in Piduino::Converter, Piduino::I2cDev, Piduino::SpiDev, and Piduino::FileDevice.

◆ openMode()

OpenMode Piduino::IoDevice::openMode ( ) const

Returns the current open mode of the device.

Returns
The open mode flags.

◆ setDebug()

void Piduino::IoDevice::setDebug ( bool  enabled)

Enables or disables debug mode for the device.

Parameters
enabledTrue to enable debug mode, false to disable.

◆ setTextModeEnabled()

void Piduino::IoDevice::setTextModeEnabled ( bool  enabled)

Enables or disables text mode for the device.

Parameters
enabledTrue to enable text mode, false to disable.

Member Data Documentation

◆ d_ptr

std::unique_ptr<Private> Piduino::IoDevice::d_ptr
protected

Pointer to the private implementation.

Definition at line 190 of file iodevice.h.