ADTF
Result

A common result class usable as return value throughout. More...

Public Member Functions

 Result ()
 Construct empty which basically means no error occurred. More...
 
 Result (bool val)
 Construct from bool. More...
 
 Result (const ResultInfo< void > &)
 Construct with a_util::result::SUCCESS. More...
 
template<typename ErrorType >
 Result (const ResultInfo< ErrorType > &error)
 Assign error code to result object. More...
 
template<typename ErrorType >
 Result (ResultInfo< ErrorType > error, const char *error_description, std::int32_t line, const char *file, const char *function)
 Construct result object with complete set of error information. More...
 
 Result (std::int32_t error_code)
 Create result object with just the error code type. More...
 
 Result (std::int32_t error_code, const char *error_description, std::int32_t line, const char *file, const char *function)
 Create result object with complete set of error information from just an error code. More...
 
 Result (const Result &other_result, const char *error_description, std::int32_t line, const char *file, const char *function)
 Create result object from another result, creating new detailed information. More...
 
 ~Result ()
 Destructor.
 
 Result (const Result &other)
 Copy constructor. More...
 
Resultoperator= (const ResultInfo< void > &)
 Assign with a_util::result::SUCCESS. More...
 
Resultoperator= (Result other)
 Assignment operator. More...
 
Resultoperator= (bool val)
 Assignment from bool. More...
 
Resultoperator= (std::int32_t val)
 Assignment from numeric. More...
 
 Result (Result &&other)
 Move operator. More...
 
std::int32_t getErrorCode () const
 Get error code. More...
 
const char * getErrorLabel () const
 Get error label as string representation. More...
 
const char * getDescription () const
 Get user provided error description. More...
 
std::int32_t getLine () const
 Get line in source file where the error was reported. More...
 
const char * getFile () const
 Get name of the file the error was reported in. More...
 
const char * getFunction () const
 Get name of the function the error was reported in. More...
 
 operator bool () const noexcept
 Convert result to bool. More...
 

Private Types

typedef detail::ResultDescription< detail::IErrorDescriptionDescriptionType
 Error description type.
 

Private Member Functions

 Result (std::int32_t error_code, const char *error_description, std::int32_t line, const char *file, const char *function, const char *label)
 Construct result object with complete set of error information. More...
 

Static Private Member Functions

static Result createFrom (std::int32_t error_code, const char *error_description, std::int32_t line, const char *file, const char *function)
 Create a detailed object of type Result on the heap from an error code. More...
 

Private Attributes

DescriptionType _result_handle
 The result handler wrapper.
 

Detailed Description

A common result class usable as return value throughout.

Definition at line 34 of file result_type_decl.h.

Constructor & Destructor Documentation

◆ Result() [1/11]

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()

Definition at line 30 of file result_type_impl.h.

Referenced by Result::Result(), Result::createFrom(), and Result::operator=().

◆ Result() [2/11]

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

Definition at line 34 of file result_type_impl.h.

◆ Result() [3/11]

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()

Definition at line 39 of file result_type_impl.h.

◆ Result() [4/11]

Result ( const ResultInfo< ErrorType > &  error)
inline

Assign error code to result object.

Parameters
[in]errorThe error code

Definition at line 44 of file result_type_impl.h.

References a_util::maybe_unused().

◆ Result() [5/11]

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: "")

Definition at line 51 of file result_type_impl.h.

References Result::Result(), ResultInfo< T >::getCode(), and a_util::maybe_unused().

◆ Result() [6/11]

Result ( std::int32_t  error_code)
inline

Create result object with just the error code type.

Parameters
[in]error_codeThe error code

Definition at line 67 of file result_type_impl.h.

◆ Result() [7/11]

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: "")

Definition at line 72 of file result_type_impl.h.

References Result::createFrom().

◆ Result() [8/11]

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.

Definition at line 82 of file result_type_impl.h.

References Result::Result(), Result::getErrorCode(), and Result::getErrorLabel().

◆ Result() [9/11]

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.

Definition at line 103 of file result_type_impl.h.

◆ Result() [10/11]

Result ( Result &&  other)
inline

Move operator.

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

Definition at line 128 of file result_type_impl.h.

References Result::Result(), and Result::swap.

◆ Result() [11/11]

Result ( std::int32_t  error_code,
const char *  error_description,
std::int32_t  line,
const char *  file,
const char *  function,
const char *  label 
)
inlineexplicitprivate

Construct result object with complete set of error information.

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: "")
[in]labelString representation of error code (default: "")

Definition at line 200 of file result_type_impl.h.

Member Function Documentation

◆ createFrom()

Result createFrom ( std::int32_t  error_code,
const char *  error_description,
std::int32_t  line,
const char *  file,
const char *  function 
)
inlinestaticprivate

Create a detailed object of type Result on the heap from an error code.

Parameters
[in]error_codeThe error code to create the result object from.
[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: "")
Returns
Object of type Result containing detailed error information.

Definition at line 211 of file result_type_impl.h.

References Result::Result().

Referenced by Result::Result().

◆ getDescription()

const char * getDescription ( ) const
inline

◆ getErrorCode()

◆ getErrorLabel()

const char * getErrorLabel ( ) const
inline

Get error label as string representation.

Returns
Error code represented as string.

Definition at line 144 of file result_type_impl.h.

References Result::_result_handle, ResultDescription< DescriptionIntf >::getDetailedDescription(), and IErrorDescription::getErrorCodeLabel().

Referenced by Result::Result().

◆ getFile()

const char * getFile ( ) const
inline

Get name of the file the error was reported in.

Returns
File name as string.

Definition at line 177 of file result_type_impl.h.

References Result::_result_handle, ResultDescription< DescriptionIntf >::getDetailedDescription(), and IErrorDescription::getFileName().

◆ getFunction()

const char * getFunction ( ) const
inline

Get name of the function the error was reported in.

Returns
Function name as string.

Definition at line 186 of file result_type_impl.h.

References Result::_result_handle, ResultDescription< DescriptionIntf >::getDetailedDescription(), and IErrorDescription::getFunctionName().

◆ getLine()

std::int32_t getLine ( ) const
inline

Get line in source file where the error was reported.

Returns
Line number.

Definition at line 168 of file result_type_impl.h.

References Result::_result_handle, ResultDescription< DescriptionIntf >::getDetailedDescription(), and IErrorDescription::getLine().

◆ operator bool()

operator bool ( ) const
inlineexplicitnoexcept

Convert result to bool.

Returns
If error code equals 0, true, otherwise false

Definition at line 195 of file result_type_impl.h.

◆ operator=() [1/4]

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

Definition at line 113 of file result_type_impl.h.

References Result::Result(), and Result::operator=().

◆ operator=() [2/4]

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

Definition at line 123 of file result_type_impl.h.

References Result::Result().

Referenced by Result::operator=().

◆ operator=() [3/4]

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

Definition at line 107 of file result_type_impl.h.

References Result::swap.

◆ operator=() [4/4]

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

Definition at line 118 of file result_type_impl.h.

References Result::Result(), and Result::operator=().