LMMS
Loading...
Searching...
No Matches
water::Result Class Reference

#include <Result.h>

Public Member Functions

bool wasOk () const noexcept
bool failed () const noexcept
 operator bool () const noexcept
bool operator! () const noexcept
const std::string & getErrorMessage () const noexcept
 Result (const Result &)
Resultoperator= (const Result &)
bool operator== (const Result &other) const noexcept
bool operator!= (const Result &other) const noexcept

Static Public Member Functions

static Result ok () noexcept
static Result fail (const std::string &errorMessage) noexcept

Private Member Functions

 Result () noexcept
 Result (const std::string &) noexcept
 operator int () const
 operator void * () const

Private Attributes

std::string errorMessage

Detailed Description

Represents the 'success' or 'failure' of an operation, and holds an associated error message to describe the error when there's a failure.

E.g.

Result myOperation()
{
if (doSomeKindOfFoobar())
return Result::ok();
else
return Result::fail ("foobar didn't work!");
}
const Result result (myOperation());
if (result.wasOk())
{
...it's all good...
}
else
{
warnUserAboutFailure ("The foobar operation failed! Error message was: "
+ result.getErrorMessage());
}
Definition Result.h:64
static Result ok() noexcept
Definition Result.h:68
static Result fail(const std::string &errorMessage) noexcept
Definition Result.cpp:58
Result(const Result &)
Definition Result.cpp:37
int result
Definition process.c:1455

Constructor & Destructor Documentation

◆ Result() [1/3]

water::Result::Result ( const Result & other)

◆ Result() [2/3]

water::Result::Result ( )
privatenoexcept

◆ Result() [3/3]

water::Result::Result ( const std::string & message)
explicitprivatenoexcept

Member Function Documentation

◆ fail()

Result water::Result::fail ( const std::string & errorMessage)
staticnoexcept

Creates a 'failure' result. If you pass a blank error message in here, a default "Unknown Error" message will be used instead.

◆ failed()

bool water::Result::failed ( ) const
noexcept

Returns true if this result indicates a failure. You can use getErrorMessage() to retrieve the error message associated with the failure.

◆ getErrorMessage()

const std::string & water::Result::getErrorMessage ( ) const
noexcept

Returns the error message that was set when this result was created. For a successful result, this will be an empty string;

◆ ok()

Result water::Result::ok ( )
inlinestaticnoexcept

Creates and returns a 'successful' result.

◆ operator bool()

water::Result::operator bool ( ) const
noexcept

Returns true if this result indicates a success. This is equivalent to calling wasOk().

◆ operator int()

water::Result::operator int ( ) const
private

◆ operator void *()

water::Result::operator void * ( ) const
private

◆ operator!()

bool water::Result::operator! ( ) const
noexcept

Returns true if this result indicates a failure. This is equivalent to calling failed().

◆ operator!=()

bool water::Result::operator!= ( const Result & other) const
noexcept

◆ operator=()

Result & water::Result::operator= ( const Result & other)

◆ operator==()

bool water::Result::operator== ( const Result & other) const
noexcept

◆ wasOk()

bool water::Result::wasOk ( ) const
noexcept

Returns true if this result indicates a success.

Member Data Documentation

◆ errorMessage

std::string water::Result::errorMessage
private

The documentation for this class was generated from the following files: