NAP
ErrorState Class Reference

#include <utility/errorstate.h>

Public Member Functions

bool check (bool successCondition, const char *errorString)
 
template<typename... Args>
bool check (bool successCondition, const char *format, Args &&... args)
 
void fail (const std::string &errorString)
 
template<typename... Args>
void fail (const std::string &format, Args &&... args)
 
const std::string toString () const
 

Detailed Description

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.

Member Function Documentation

◆ check() [1/2]

bool check ( bool  successCondition,
const char *  errorString 
)

Check whether the specified condition evaluates to true and adds an error message to the state if not

Parameters
successConditionThe condition to check (i.e. true/false)
errorStringThe error message that belongs to the 'fail' state
Returns
Whether the condition evaluated to true (i.e. success) or not

◆ check() [2/2]

bool check ( bool  successCondition,
const char *  format,
Args &&...  args 
)

Same as non-templated check(), but here to allow for easy formatting of error messages

◆ fail() [1/2]

void fail ( const std::string &  errorString)

Added a failure message to the stack. Useful in situations where you already know that you've failed, in which case the check() function is redundant.

Parameters
errorStringThe error message that belongs to the 'fail' state

◆ fail() [2/2]

void fail ( const std::string &  format,
Args &&...  args 
)

Same as non-templated fail(), but here to allow for easy formatting of error messages

◆ toString()

const std::string toString ( ) const

Format the error state of this object into a human-readable message

Returns
The full error message