xentara-plugin v1.2
The Xentara Plugin Framework
|
A handle for reading a data value. More...
#include <data/ReadHandle.hpp>
Public Types | |
enum class | Error { NoError , NullHandle , Unknown , WriteOnly , NoData , TypeMismatch } |
An enum describing read errors. More... | |
Public Member Functions | |
ReadHandle () | |
Default constructor. | |
ReadHandle (Error error) | |
Constructor for an error handle that always returns a read error. | |
ReadHandle (const std::error_code &error) | |
Constructor for an error handle that returns an arbitrary std::error_code. | |
template<typename Structure > | |
ReadHandle (const memory::MemoryHandle< Structure > &memoryHandle) | |
Constructor using a memory handle. | |
template<typename Structure > | |
ReadHandle (memory::MemoryHandle< Structure > &&memoryHandle) | |
Constructor that moves a memory handle. | |
auto | nativeType () const -> NativeType |
Gets the native type of the handle. | |
template<typename Type > | |
auto | read () const -> utils::eh::expected< Type, std::error_code > |
Reads the current value. | |
auto | hardError () const -> std::error_code |
Gets the error of an error handle. | |
auto | operator== (Error error) const -> bool |
Checks whether the handle is an error handle that returns a certain error. | |
auto | operator== (const std::error_code &error) const -> bool |
Checks whether the handle is an error handle that returns a certain error. | |
Static Public Member Functions | |
static auto | errorCategory () -> const std::error_category & |
Gets the error category for error codes of type [Error]. | |
A handle for reading a data value.
|
strong |
An enum describing read errors.
xentara::data::ReadHandle::ReadHandle | ( | ) |
Default constructor.
This constructor creates a null handle that is not associated with any value. Reading the handle will always return make_error_code(Error::NullHandle).
xentara::data::ReadHandle::ReadHandle | ( | Error | error | ) |
Constructor for an error handle that always returns a read error.
This constructor creates a handle that always returns a certain error when reading. Reading the handle will always return make_error_code(error).
error | The error the handle should return when attempting to read from it. |
xentara::data::ReadHandle::ReadHandle | ( | const std::error_code & | error | ) |
Constructor for an error handle that returns an arbitrary std::error_code.
This constructor creates a handle that always returns a certain error when reading. Reading the handle will always return the given error.
error | The error code the handle should return when attempting to read from it. |
xentara::data::ReadHandle::ReadHandle | ( | const memory::MemoryHandle< Structure > & | memoryHandle | ) |
Constructor using a memory handle.
memoryHandle | A handle to the memory containing the value |
xentara::data::ReadHandle::ReadHandle | ( | memory::MemoryHandle< Structure > && | memoryHandle | ) |
Constructor that moves a memory handle.
memoryHandle | A handle to the memory containing the value |
|
static |
Gets the error category for error codes of type [Error].
auto xentara::data::ReadHandle::hardError | ( | ) | const -> std::error_code |
Gets the error of an error handle.
This function returns the error code of an error handle created using ReadHandle(Error error) or ReadHandle(const std::error_code &error). An error handle will always return the given error when calling read(), and will never return a valid value.
Soft errors, meaning errors that might go away at some point, can only be gotten using read().
auto xentara::data::ReadHandle::nativeType | ( | ) | const -> NativeType |
Gets the native type of the handle.
This function can be used to determine what is the best type is to use as a template parameter for the read() function. You can use this function if you want to treat certain data types separately, and not rely on the built-in conversions. For example, you can use this function if you want to normally read the value as a string, but handle numbers and Booleans differently.
auto xentara::data::ReadHandle::operator== | ( | const std::error_code & | error | ) | const -> bool |
Checks whether the handle is an error handle that returns a certain error.
This operator checks whether the handle is an error handle created using ReadHandle(const std::error_code &error) or ReadHandle(Error error). An error handle will always return the given error when calling read(), and will never return a valid value.
Soft errors, meaning errors that might go away at some point, can only be gotten using read().
auto xentara::data::ReadHandle::operator== | ( | Error | error | ) | const -> bool |
Checks whether the handle is an error handle that returns a certain error.
This operator checks whether the handle is an error handle created using ReadHandle(Error error) or ReadHandle(const std::error_code &error). An error handle will always return the given error when calling read(), and will never return a valid value.
Soft errors, meaning errors that might go away at some point, can only be gotten using read().
auto xentara::data::ReadHandle::read | ( | ) | const -> utils::eh::expected<Type, std::error_code> |
Reads the current value.
The read value will be converted to the type specified by the Type template parameter, if possible. If the value cannot be converted, the function will return Error::TypeMismatch.
You can use std::any as template parameter to retrieve the value without knowing the type beforehand. The returned object will then contain the value is a suitable type wrappen in std::any. This value can then be passed to WriteHandle::write(), for example, to copy the value to somewhere else.
Type | the type that the value should be converted to, or std::any to return the value as a type-erased std::any object. |