Dev Essential
Loading...
Searching...
No Matches
a_util::result::Result Class Reference

#include <result_type_decl.h>

Public Member Functions

 Result ()
 
 Result (bool val)
 
 Result (const ResultInfo< void > &)
 
template<typename ErrorType>
 Result (const ResultInfo< ErrorType > &error)
 
template<typename ErrorType>
 Result (ResultInfo< ErrorType > error, const char *error_description, std::int32_t line, const char *file, const char *function)
 
 Result (std::int32_t error_code)
 
 Result (std::int32_t error_code, const char *error_description, std::int32_t line, const char *file, const char *function)
 
 Result (const Result &other_result, const char *error_description, std::int32_t line, const char *file, const char *function)
 
 ~Result ()
 
 Result (const Result &other)
 
Resultoperator= (const ResultInfo< void > &)
 
Resultoperator= (Result other)
 
Resultoperator= (bool val)
 
Resultoperator= (std::int32_t val)
 
 Result (Result &&other)
 
std::int32_t getErrorCode () const
 
const char * getErrorLabel () const
 
const char * getDescription () const
 
std::int32_t getLine () const
 
const char * getFile () const
 
const char * getFunction () const
 
 operator bool () const noexcept
 

Friends

void swap (Result &lhs, Result &rhs)
 
bool operator== (const Result &lhs, const Result &rhs)
 

Detailed Description

A common result class usable as return value throughout.

Constructor & Destructor Documentation

◆ Result() [1/10]

a_util::result::Result::Result ( )
inline

Construct empty which basically means no error occurred.

Postcondition
a_util::result::SUCCESS == getErrorCode() &&
-1 == getLine() &&
"No error occurred" == getDescription() &&
"" == getFile() &&
"" == getFunction() &&
"" == getErrorLabel()

◆ Result() [2/10]

a_util::result::Result::Result ( bool val)
inline

Construct from bool

Parameters
[in]valBool value to construct with
Postcondition
true == a_util::result::Result(true);
false == a_util::result::Result(false);
No dynamic memory is allocated

◆ Result() [3/10]

a_util::result::Result::Result ( const ResultInfo< void > & )
inline

Construct with a_util::result::SUCCESS

This constructors sole intention is to provide the best match during compilation time if a function call returns with a_util::result::SUCCESS. With decltype(a_util::result::SUCCESS) being another type than all other error codes the compiler deduces this constructor as best fit.

Postcondition
See also
Result()

◆ Result() [4/10]

template<typename ErrorType>
a_util::result::Result::Result ( const ResultInfo< ErrorType > & error)
inline

Assign error code to result object

Parameters
[in]errorThe error code

◆ Result() [5/10]

template<typename ErrorType>
a_util::result::Result::Result ( ResultInfo< ErrorType > error,
const char * error_description,
std::int32_t line,
const char * file,
const char * function )
inlineexplicit

Construct result object with complete set of error information

Template Parameters
ErrorCodeError code (to deduce specialized template to stringify the error code)
Parameters
[in]errorThe The concrete error object
[in]error_descriptionComplete description of the error (default: "")
[in]lineLine in source file the error was reported (default: -1)
[in]fileSource file the error was reported in (default: "")
[in]functionFunction the error was reported in (default: "")

◆ Result() [6/10]

a_util::result::Result::Result ( std::int32_t error_code)
inline

Create result object with just the error code type.

Parameters
[in]error_codeThe error code

◆ Result() [7/10]

a_util::result::Result::Result ( std::int32_t error_code,
const char * error_description,
std::int32_t line,
const char * file,
const char * function )
inlineexplicit

Create result object with complete set of error information from just an error code

Parameters
[in]error_codeThe error code
[in]error_descriptionComplete description of the error (default: "")
[in]lineLine in source file the error was reported (default: -1)
[in]fileSource file the error was reported in (default: "")
[in]functionFunction the error was reported in (default: "")

◆ Result() [8/10]

a_util::result::Result::Result ( const Result & other_result,
const char * error_description,
std::int32_t line,
const char * file,
const char * function )
inlineexplicit

Create result object from another result, creating new detailed information

Parameters
[in]other_resultResult to copy the error code and error code string information from.
[in]error_descriptionComplete description of the error.
[in]lineLine in source file the error was reported.
[in]fileSource file the error was reported in.
[in]functionFunction the error was reported in.

◆ ~Result()

a_util::result::Result::~Result ( )
inline

Destructor.

◆ Result() [9/10]

a_util::result::Result::Result ( const Result & other)
inline

Copy constructor.

Parameters
[in]otherWhere this gets copied from.
Note
No new memory is allocated, the error information from other are safely referenced in the new created object of type Result.

◆ Result() [10/10]

a_util::result::Result::Result ( Result && other)
inline

Move operator.

Parameters
[in]otherrvalue of type Result moved to *this. Left in an empty but valid state.

Member Function Documentation

◆ getDescription()

const char * a_util::result::Result::getDescription ( ) const
inline

Get user provided error description.

Returns
Error description as string.

◆ getErrorCode()

std::int32_t a_util::result::Result::getErrorCode ( ) const
inline

Get error code.

Returns
Error code.

◆ getErrorLabel()

const char * a_util::result::Result::getErrorLabel ( ) const
inline

Get error label as string representation.

Returns
Error code represented as string.

◆ getFile()

const char * a_util::result::Result::getFile ( ) const
inline

Get name of the file the error was reported in.

Returns
File name as string.

◆ getFunction()

const char * a_util::result::Result::getFunction ( ) const
inline

Get name of the function the error was reported in.

Returns
Function name as string.

◆ getLine()

std::int32_t a_util::result::Result::getLine ( ) const
inline

Get line in source file where the error was reported.

Returns
Line number.

◆ operator bool()

a_util::result::Result::operator bool ( ) const
inlineexplicitnoexcept

Convert result to bool

Returns
If error code equals 0, true, otherwise false

◆ operator=() [1/4]

Result & a_util::result::Result::operator= ( bool val)
inline

Assignment from bool

Parameters
[in]valBool value to construct with
Postcondition
No dynamic memory is allocated.
Returns
Reference to *this

◆ operator=() [2/4]

Result & a_util::result::Result::operator= ( const ResultInfo< void > & )
inline

Assign with a_util::result::SUCCESS

This assignments sole intention is to provide the best match during compilation time if a function call returns with a_util::result::SUCCESS. With decltype(a_util::result::SUCCESS) being another type than all other error codes the compiler deduces this assignment operator as best fit.

Postcondition
See also
Result()
Returns
*this

◆ operator=() [3/4]

Result & a_util::result::Result::operator= ( Result other)
inline

Assignment operator

Parameters
[in]otherResult type being assigned to the this object.
Note
Passing other by value is fully intentional here!
Returns
*this

◆ operator=() [4/4]

Result & a_util::result::Result::operator= ( std::int32_t val)
inline

Assignment from numeric

Parameters
[in]valNumeric value to construct with
Postcondition
No dynamic memory is allocated.
Returns
Reference to *this

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( const Result & lhs,
const Result & rhs )
friend

Comparison operator (shallow comparison)

Parameters
[in,out]lhsLeft hand side result object.
[in,out]rhsRight hand side result object.
Returns
true if both result objects match, false otherwise.

◆ swap

void swap ( Result & lhs,
Result & rhs )
friend

Specialized friend swap function to enable ADL in std::swap later.

Parameters
[in,out]lhsLeft hand side result object.
[in,out]rhsRight hand side result object.

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