1 #ifndef NTA_ERRORS_H_INCLUDED
2 #define NTA_ERRORS_H_INCLUDED
6 #include "nta/Option.h"
11 typedef std::function<void(
const Error*)> ErrorCallback;
20 UNWRAP_WRONG_RESULT_VARIANT,
91 new(&err)
Error(other.err);
93 new(&data) T(other.data);
103 new(&ret.data) T((data));
112 new(&ret.err)
Error(std::move(err));
124 UNWRAP_WRONG_RESULT_VARIANT));
134 UNWRAP_WRONG_RESULT_VARIANT));
158 UNWRAP_WRONG_RESULT_VARIANT));
168 #endif // NTA_ERRORS_H_INCLUDED
static void set_push_callback(const ErrorCallback &callback)
Sets the push callback function.
static ErrorCallback m_periodic_callback
The function used to handle errors at the end of each frame.
static const Error * m_errors
A linked list of unhandled errors.
~Result()
Public destructor.
static void push_error(const Error &err)
Adds and error to the front of the list.
const Error * prev
The most recent unhandled error before this one.
std::string get_errortype_string(ErrorType t)
converts ErrorType enum to string
static const Error * peek_error()
Returns the error at the front of the list.
static Option some(const T &data)
Creates an Option holding some data.
static const Error * pop_error()
Removes (and returns) the error from the front of the list.
Result< S > convert_error()
Converts an error variant of Result<T> to an error variant of Result
std::string description
A description of what when wrong.
Result(const Result &other)
Public copy constructor.
Result< S > map(std::function< S(T)> func)
Applies a function if no error has occured, else returns the same error.
static Option none()
Creates a None variant Option.
Result()
Private constructor (use new_ok or new_err)
Error get_err() const
Get the Error (only use if is_err() returns true)
static void clear_errors()
Deletes all errors (without handling any of them)
static void set_periodic_callback(const ErrorCallback &callback)
Sets the periodic callback function.
bool is_ok() const
Is this normal data.
bool is_err() const
Is this an Error.
static Result new_err(const Error &err)
static Result new_ok(const T &data)
T get_data_or(T optb) const
Tries getting data, returning a default value if this is an error.
T unwrap_or(T optb) const
Same as get_data_or.
bool is_err_variant
Whether or not an error occured.
T get_data() const
Get the data (only use if is_ok() returns true)
ErrorType type
The type of error that occured.
static ErrorCallback m_push_callback
The function used to handle errors as they occur.
T unwrap() const
Same as get_data.
static void handle_errors()
Handles all outstanding errors.