HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0::Result< void > Class Reference

Result type for operations that don't return a value. More...

#include <tmc51x0_result.hpp>

Public Member Functions

 Result () noexcept
 Construct a successful result.
 
 Result (ErrorCode error) noexcept
 Construct an error result.
 
 operator bool () const noexcept
 Check if result is OK (bool operator for cleaner syntax)
 
bool IsOk () const noexcept
 Check if result is OK.
 
bool IsErr () const noexcept
 Check if result is an error.
 
ErrorCode Error () const noexcept
 Get the error code.
 
const char * ErrorMessage () const noexcept
 Get human-readable error message.
 

Private Attributes

ErrorCode error_
 

Detailed Description

Result type for operations that don't return a value.

Specialized version of Result<T> for void operations.

auto result = driver.Initialize(config);
if (!result) { // Bool operator
printf("Error: %s\n", result.ErrorMessage());
}

Constructor & Destructor Documentation

◆ Result() [1/2]

tmc51x0::Result< void >::Result ( )
inlinenoexcept

Construct a successful result.

◆ Result() [2/2]

tmc51x0::Result< void >::Result ( ErrorCode error)
inlineexplicitnoexcept

Construct an error result.

Member Function Documentation

◆ Error()

ErrorCode tmc51x0::Result< void >::Error ( ) const
inlinenoexcept

Get the error code.

Returns
Error code (OK if successful)

◆ ErrorMessage()

const char * tmc51x0::Result< void >::ErrorMessage ( ) const
inlinenoexcept

Get human-readable error message.

Returns
Error message string
Here is the call graph for this function:

◆ IsErr()

bool tmc51x0::Result< void >::IsErr ( ) const
inlinenoexcept

Check if result is an error.

Returns
true if operation failed

◆ IsOk()

bool tmc51x0::Result< void >::IsOk ( ) const
inlinenoexcept

Check if result is OK.

Returns
true if operation succeeded

◆ operator bool()

tmc51x0::Result< void >::operator bool ( ) const
inlineexplicitnoexcept

Check if result is OK (bool operator for cleaner syntax)

Returns
true if operation succeeded
if (result.IsOk()) { // success
// Operation succeeded, no value to retrieve
}
if (result.IsErr()) { // error
ErrorCode err = result.Error();
const char* msg = result.ErrorMessage();
}
ErrorCode
Error codes for TMC51x0 operations.
Definition tmc51x0_result.hpp:18

Member Data Documentation

◆ error_

ErrorCode tmc51x0::Result< void >::error_
private

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