ma::io::Handler

To read/write data from/to an I/O device in a specific format. More...

Header
#include <UNKNOWN>

Module

Public Functions#

~Handler() noexcept

bool
canRead() const noexcept

bool
canWrite() const noexcept

Signature
detectSignature() const noexcept

bool
read(Node *output)

bool
write(const Node *input)

Device *
device() const noexcept

void
setDevice(Device *device) noexcept

Error
errorCode() const noexcept

const std::string &
errorMessage() const noexcept

Protected Functions#

Handler(HandlerPrivate &pimpl) noexcept

void
setError(Error code=Error::None, const std::string &msg="") noexcept

Signature
validateSignature() const noexcept=0

void
readDevice(Node *output)

void
writeDevice(const Node *input)

Related Non-Members#

constexpr Capability
operator&(Capability lhs, Capability rhs)

constexpr Capability
operator|(Capability lhs, Capability rhs)

Detailed Description#

This interface is the core to implement data reader/writer (e.g. trials, models). Several methods and mecanisms are already implemented to facilitate the inclusion of new formats. For example, it is not necessary to manage exception as this is done internaly. Some methods are available to set errors and retrieve them. The extraction of handler's class is implemented. In fact, only four (or five) methods must be implemented for inherting handler:

  • readDevice() method: extract data from a device and set it into a node
  • writeDevice() method: write data to a given device
  • validateSignature() method: test if the read device has a signature valid for this handler.
  • canRead() method: to inform on the capability of the handler to read data from a device
  • canWrite() method: to inform on the capability of the handler to write data to a device

Todo

Give an example for the implementation of a handler.

Member Function Documentation#

bool ma::io::Handler::canRead ( ) const noexcept [virtual]

Returns the capability of the handler to read data from a device. By default this method returns false.

bool ma::io::Handler::canWrite ( ) const noexcept [virtual]

Returns the capability of the handler to write data to a device. By default this method returns false.

Signature ma::io::Handler::detectSignature ( ) const noexcept

Try to detect the signature of the handler in the given device. A signature is generaly a keyword at the beginning of the data that help to determine the content. For example, if the device is a File, this way is safer than relying on the file extension. Internaly this methods use validateSignature(). Each inheriting handler must overload the method validateSignature().

Device * ma::io::Handler::device ( ) const noexcept

Returns the current device associated with this handler.

Error ma::io::Handler::errorCode ( ) const noexcept

Returns the current error code.

const std::string & ma::io::Handler::errorMessage ( ) const noexcept

Returns the current error message.

ma::io::Handler::Handler ( HandlerPrivate & pimpl ) noexcept

Constructor for inheriting class with extended private implementation

bool ma::io::Handler::read ( Node * output )

Read the content of the current set device and fill the given output. If an exception is thrown during the reading of the device, no content is added to the output and false is returned. In case this method returns false, you can use the methods errorCode() and errorMessage() to retrieve the error. Internally this methods call readDevice() to extract data. Each inheriting handler must overload the method readDevice().

void ma::io::Handler::readDevice ( Node * output ) [virtual]

Method to overload to read data from the current set device.

void ma::io::Handler::setDevice ( Device * device ) noexcept

Sets the current device associated with this handler.

void ma::io::Handler::setError ( Error code = Error::None , const std::string & msg = "" ) noexcept

Set a code and a detailed message for an error which happened during the reading or writing of a device.

Signature ma::io::Handler::validateSignature ( ) const noexcept [virtual]

Method to overload to determine if the associated device is compatible with the handler.

bool ma::io::Handler::write ( const Node * input )

Write the content of the input to the current set device. If an exception is thrown during the writing of the device, false is returned. In case this method returns false, you can use the methods errorCode() and errorMessage() to retrieve the error. Internally this methods call writeDevice() to extract data. Each inheriting handler must overload the method writeDevice().

void ma::io::Handler::writeDevice ( const Node * input ) [virtual]

Method to overload to write data to the current set device.

ma::io::Handler::~Handler ( ) noexcept [virtual]

Destructor (default)

Related Non-Members Documentation#

constexpr Capability ma::io::Handler::operator& ( Capability lhs , Capability rhs ) [inline]

Bitwise and operator for Capability

constexpr Capability ma::io::Handler::operator| ( Capability lhs , Capability rhs ) [inline]

Bitwise or operator for Capability