IOLink  IOL_v1.6.1_release
iolink::StreamAccess Class Referenceabstract

Mother interface for all stream-like data accessors. More...

#include <iolink/storage/StreamAccess.h>

Inheritance diagram for iolink::StreamAccess:
iolink::DataAccess

Public Member Functions

virtual StreamAccessCapabilitySet capabilities () const =0
 
bool support (StreamAccessCapabilitySet flags)
 Checks if the StreamAccess supports the given capabilities.
 
virtual bool good () const
 Checks if the stream is currently valid for reading (only) Default implementation returns true if nor 'end of file' or 'fail' status are raised. More...
 
virtual bool eof () const =0
 Checks if the cursor is at the end of the stream for reading For writing, this status is not relevant. More...
 
virtual bool fail () const =0
 
std::string toString () const
 Return a string representation.
 
virtual size_t read (size_t size, void *dst)
 Read data from cursor current position into destination buffer. More...
 
virtual uint8_t peek ()
 Return the current byte without moving the cursor. More...
 
virtual size_t write (size_t size, const void *src)
 Write content of src buffer into StreamAccess. More...
 
virtual void flush ()
 Assure that all data is written to the endpoint. More...
 
virtual size_t tell ()
 Returns the current position of the cursor. More...
 
virtual void seek (int64_t offset, SeekOrigin origin)
 Move the cursor to the desired position. More...
 
virtual void * buffer ()
 Return a mutable pointer to the internal CPU memory buffer. More...
 
virtual const void * bufferReadOnly () const
 Return an immutable pointer to the internal CPU memory buffer. More...
 
virtual size_t bufferSize ()
 Size in bytes of the internal CPU buffer. More...
 

Detailed Description

Mother interface for all stream-like data accessors.

This interface capabilities are indicated by the StreamAccessCapabilitySet returned by the method StreamAccess::capabilities. Each capability enables the use of a specific set of methods. When one of those methods is called, if its corresponding capability is not supported, a NotImplemented exception will be thrown.

See also
StreamAccessCapability for capabilities managed by this object

Member Function Documentation

◆ buffer()

virtual void* iolink::StreamAccess::buffer ( )
virtual

Return a mutable pointer to the internal CPU memory buffer.

Available when the RandomAccess has the MEMORY_ACCESS capability.

Exceptions
NotImplementedIf the implementation does not support memory access.

◆ bufferReadOnly()

virtual const void* iolink::StreamAccess::bufferReadOnly ( ) const
virtual

Return an immutable pointer to the internal CPU memory buffer.

Available when the RandomAccess has the MEMORY_ACCESS capability.

Exceptions
NotImplementedIf the implementation does not support memory access.

◆ bufferSize()

virtual size_t iolink::StreamAccess::bufferSize ( )
virtual

Size in bytes of the internal CPU buffer.

Available when the RandomAccess has the MEMORY_ACCESS capability.

Exceptions
NotImplementedIf the implementation does not support memory access.

◆ capabilities()

virtual StreamAccessCapabilitySet iolink::StreamAccess::capabilities ( ) const
pure virtual
Returns
capabilities for current stream

◆ eof()

virtual bool iolink::StreamAccess::eof ( ) const
pure virtual

Checks if the cursor is at the end of the stream for reading For writing, this status is not relevant.

Returns
true if the end of stream is reached. No more byte can be read.

◆ flush()

virtual void iolink::StreamAccess::flush ( )
virtual

Assure that all data is written to the endpoint.

Available when the StreamAccess has the WRITE capability.

◆ good()

virtual bool iolink::StreamAccess::good ( ) const
virtual

Checks if the stream is currently valid for reading (only) Default implementation returns true if nor 'end of file' or 'fail' status are raised.

Returns
true if the stream can be read

◆ peek()

virtual uint8_t iolink::StreamAccess::peek ( )
virtual

Return the current byte without moving the cursor.

Available when the StreamAccess has the READ capability.

Exceptions
Errorif cursor is at EOF.

◆ read()

virtual size_t iolink::StreamAccess::read ( size_t  size,
void *  dst 
)
virtual

Read data from cursor current position into destination buffer.

Cursor position is incremented by the actually read bytes count.

Available when the StreamAccess has the READ capability.

Parameters
sizeSize in byte of the area to read
dstDestination buffer. This buffer should have a size of "size"
Returns
Count of actually read bytes.

◆ seek()

virtual void iolink::StreamAccess::seek ( int64_t  offset,
SeekOrigin  origin 
)
virtual

Move the cursor to the desired position.

Available when the StreamAccess has the SEEK capability.

Cursor position must be set as following: new position = current position + offset If new computed position is less than 0, previous current position is kept.

Parameters
offsetOffset used to move the cursor according to the origin.
originThe origin from which to move the cursor. Can be the start of the stream, the current position of the cursor, or the end of the stream. Positive offsets always make the cursor move forward in the stream, whatever the origin. Negative offsets always make the cursor move backward.
Exceptions
Errorif trying to set cursor before BEGIN position (negative value)

◆ tell()

virtual size_t iolink::StreamAccess::tell ( )
virtual

Returns the current position of the cursor.

Available when the StreamAccess has the SEEK capability.

◆ write()

virtual size_t iolink::StreamAccess::write ( size_t  size,
const void *  src 
)
virtual

Write content of src buffer into StreamAccess.

Stream cursor is incremented by actually written bytes count.

Available when the StreamAccess has the WRITE capability.

Parameters
sizeSize in byte of given buffer to write
srcSource buffer. This buffer should have a size of "size"
Returns
Count of actually written bytes. It may not be considered as an error that return value if different than size (ie. an exception may not be thrown). It is up to user to decide what to do in this case.

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