libcdoc 0.1.8
libcdoc::DataSource Struct Reference

The DataSource class. More...

#include <Io.h>

Inherited by libcdoc::ChainedSource, libcdoc::IStreamSource, libcdoc::MultiDataSource, and libcdoc::VectorSource.

Public Member Functions

 DataSource ()=default
 
virtual ~DataSource ()=default
 
virtual result_t seek (size_t pos)
 set stream input pointer
 
virtual result_t read (uint8_t *dst, size_t size)
 read bytes from input object
 
virtual bool isError ()
 check whether DataConsumer is in error state
 
virtual bool isEof ()
 check whether DataConsumer is reached to the end of data
 
virtual std::string getLastErrorStr (result_t code) const
 get textual description of the last error
 
result_t skip (size_t size)
 skip specified number of bytes
 
result_t readAll (DataConsumer &dst)
 read all data and writes to output object
 
 DataSource (const DataSource &)=delete
 
DataSourceoperator= (const DataSource &)=delete
 

Detailed Description

The DataSource class.

An abstact base class for input objects

Constructor & Destructor Documentation

◆ DataSource() [1/2]

libcdoc::DataSource::DataSource ( )
default

◆ ~DataSource()

virtual libcdoc::DataSource::~DataSource ( )
virtualdefault

◆ DataSource() [2/2]

libcdoc::DataSource::DataSource ( const DataSource )
delete

Member Function Documentation

◆ getLastErrorStr()

virtual std::string libcdoc::DataSource::getLastErrorStr ( result_t  code) const
virtual

get textual description of the last error

Implementation can decide whether to store the actual error string or return the generic text based on error code. It is undefined what will be returned if the last error code is not the one used as the argument.

Parameters
codethe last returned error code
Returns
error text

◆ isEof()

virtual bool libcdoc::DataSource::isEof ( )
inlinevirtual

check whether DataConsumer is reached to the end of data

Returns
true if end of stream

Reimplemented in libcdoc::ChainedSource, libcdoc::IStreamSource, libcdoc::VectorSource, and libcdoc::FileListSource.

◆ isError()

virtual bool libcdoc::DataSource::isError ( )
inlinevirtual

check whether DataConsumer is in error state

Returns
true if error state

Reimplemented in libcdoc::ChainedSource, libcdoc::IStreamSource, libcdoc::VectorSource, and libcdoc::FileListSource.

◆ operator=()

DataSource & libcdoc::DataSource::operator= ( const DataSource )
delete

◆ read()

virtual result_t libcdoc::DataSource::read ( uint8_t *  dst,
size_t  size 
)
inlinevirtual

read bytes from input object

The following invariant holds:

  • if there is neither error nor eof then result == size
  • if there is no errors but end of stream is reached then 0 <= result <= size
  • if there is error then result < 0
    Parameters
    dstthe destination block
    sizethe number of bytes to read
    Returns
    the number of bytes read or error code

Reimplemented in libcdoc::ChainedSource, libcdoc::IStreamSource, libcdoc::VectorSource, and libcdoc::FileListSource.

References libcdoc::NOT_IMPLEMENTED.

◆ readAll()

result_t libcdoc::DataSource::readAll ( DataConsumer dst)
inline

read all data and writes to output object

Copies all bytes (until EOF or error) to the output object. If error occurs while writing data, the destination objects' error code is returned.

Parameters
dstthe destination DataConsumer
Returns
error code or OK

References libcdoc::DataConsumer::writeAll().

◆ seek()

virtual result_t libcdoc::DataSource::seek ( size_t  pos)
inlinevirtual

set stream input pointer

Positions the read pointer at the specific distance from the stream start. If the stream does not support seeking NOT_IMPLEMENTED is returned.

Parameters
posthe position from the beggining of data
Returns
error code or OK

Reimplemented in libcdoc::IStreamSource, and libcdoc::VectorSource.

References libcdoc::NOT_IMPLEMENTED.

◆ skip()

result_t libcdoc::DataSource::skip ( size_t  size)

skip specified number of bytes

The following invariant holds:

  • if there is neither error nor eof then result == size
  • if there is no errors but end of stream is reached then 0 <= result <= size
  • if there is error then result < 0
    Parameters
    sizethe number of bytes to skip
    Returns
    the number of bytes skipped

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