#include <utility/errorstate.h>
Public Member Functions | |
template<typename T > | |
bool | check (bool successCondition, T &&errorMessage) |
template<typename... Args> | |
bool | check (bool successCondition, const char *format, Args &&... args) |
template<typename T > | |
void | fail (T &&errorMessage) |
template<typename... Args> | |
void | fail (const char *format, Args &&... args) |
const std::string | toString () const |
bool | hasErrors () const |
ErrorState is a class that can be used to maintain an error state over (nested) function calls. It's useful to be able to return detailed error information from somewhere deep down the stack. It's kind of a poor-man's exception handling in that regard.
bool check | ( | bool | successCondition, |
const char * | format, | ||
Args &&... | args | ||
) |
Same as non-templated check(), but allows for easy formatting of error messages.
successCondition | The condition to check (i.e. true/false) |
format | The error message that that is formatted |
args | the formatting arguments |
bool check | ( | bool | successCondition, |
T && | errorMessage | ||
) |
Check whether the specified condition evaluates to true and adds an error message to the state if not. Often checks are performed on initialization to ensure the resource is valid, for example:
successCondition | The condition to check (i.e. true/false) |
errorMessage | The error message that belongs to the 'fail' state |
void fail | ( | const char * | format, |
Args &&... | args | ||
) |
void fail | ( | T && | errorMessage | ) |
bool hasErrors | ( | ) | const |
const std::string toString | ( | ) | const |
Format the error state of this object into a human-readable message