|
Porytiles
|
#include <expected>#include <memory>#include <string>#include <type_traits>#include "porytiles/utilities/panic/panic.hpp"#include "porytiles/utilities/result/error.hpp"Go to the source code of this file.
Classes | |
| class | porytiles::ChainableResult< T, E > |
| A result type that maintains a chainable sequence of errors for debugging and error reporting. More... | |
| class | porytiles::ChainableResult< void, E > |
| Template specialization of ChainableResult for void success type. More... | |
Namespaces | |
| namespace | porytiles |
| namespace | porytiles::detail |
Macros | |
| #define | PT_TRY_ASSIGN_CHAIN_ERR(var, expr, return_type, ...) |
| Unwraps a ChainableResult, chaining a new error message on failure. | |
| #define | PT_TRY_ASSIGN_PASS_ERR(var, expr, return_type) |
| Unwraps a ChainableResult, passing through the error chain with an empty FormattableError when types differ. | |
| #define | PT_TRY_ASSIGN_PASS_SAME_ERR(var, expr) |
| Unwraps a ChainableResult, passing through the error unchanged when types match. | |
| #define | PT_DETAIL_TRY_CALL_CHAIN_ERR_EXPAND(expr, return_type, counter, ...) |
| #define | PT_DETAIL_TRY_CALL_CHAIN_ERR_IMPL(expr, return_type, counter, ...) PT_DETAIL_TRY_CALL_CHAIN_ERR_EXPAND(expr, return_type, counter, __VA_ARGS__) |
| #define | PT_TRY_CALL_CHAIN_ERR(expr, return_type, ...) PT_DETAIL_TRY_CALL_CHAIN_ERR_IMPL(expr, return_type, __LINE__, __VA_ARGS__) |
| Unwraps a void ChainableResult, chaining a new error message on failure. | |
| #define | PT_DETAIL_TRY_CALL_PASS_ERR_EXPAND(expr, return_type, counter) |
| #define | PT_DETAIL_TRY_CALL_PASS_ERR_IMPL(expr, return_type, counter) PT_DETAIL_TRY_CALL_PASS_ERR_EXPAND(expr, return_type, counter) |
| #define | PT_TRY_CALL_PASS_ERR(expr, return_type) PT_DETAIL_TRY_CALL_PASS_ERR_IMPL(expr, return_type, __LINE__) |
| Unwraps a void ChainableResult, passing through the error chain with an empty FormattableError when types differ. | |
| #define | PT_DETAIL_TRY_CALL_PASS_SAME_ERR_EXPAND(expr, counter) |
| #define | PT_DETAIL_TRY_CALL_PASS_SAME_ERR_IMPL(expr, counter) PT_DETAIL_TRY_CALL_PASS_SAME_ERR_EXPAND(expr, counter) |
| #define | PT_TRY_CALL_PASS_SAME_ERR(expr) PT_DETAIL_TRY_CALL_PASS_SAME_ERR_IMPL(expr, __LINE__) |
| Unwraps a void ChainableResult, passing through the error unchanged when types match. | |
| #define PT_DETAIL_TRY_CALL_CHAIN_ERR_EXPAND | ( | expr, | |
| return_type, | |||
| counter, | |||
| ... | |||
| ) |
Definition at line 425 of file chainable_result.hpp.
| #define PT_DETAIL_TRY_CALL_CHAIN_ERR_IMPL | ( | expr, | |
| return_type, | |||
| counter, | |||
| ... | |||
| ) | PT_DETAIL_TRY_CALL_CHAIN_ERR_EXPAND(expr, return_type, counter, __VA_ARGS__) |
Definition at line 432 of file chainable_result.hpp.
| #define PT_DETAIL_TRY_CALL_PASS_ERR_EXPAND | ( | expr, | |
| return_type, | |||
| counter | |||
| ) |
Definition at line 463 of file chainable_result.hpp.
| #define PT_DETAIL_TRY_CALL_PASS_ERR_IMPL | ( | expr, | |
| return_type, | |||
| counter | |||
| ) | PT_DETAIL_TRY_CALL_PASS_ERR_EXPAND(expr, return_type, counter) |
Definition at line 470 of file chainable_result.hpp.
| #define PT_DETAIL_TRY_CALL_PASS_SAME_ERR_EXPAND | ( | expr, | |
| counter | |||
| ) |
Definition at line 497 of file chainable_result.hpp.
| #define PT_DETAIL_TRY_CALL_PASS_SAME_ERR_IMPL | ( | expr, | |
| counter | |||
| ) | PT_DETAIL_TRY_CALL_PASS_SAME_ERR_EXPAND(expr, counter) |
Definition at line 504 of file chainable_result.hpp.
| #define PT_TRY_ASSIGN_CHAIN_ERR | ( | var, | |
| expr, | |||
| return_type, | |||
| ... | |||
| ) |
Unwraps a ChainableResult, chaining a new error message on failure.
This macro provides a succinct way to handle ChainableResult unwrapping with error propagation. It evaluates the expression, checks if it contains a value, and either assigns the value to the variable or returns early with a new error chained to the existing error chain. This reduces the common 6-line error handling pattern to a single line.
If the result contains an error, the macro returns from the current function with a ChainableResult containing the original error chain plus the new error message provided.
The variadic args are forwarded directly to the FormattableError constructor, so you can pass a plain string or a format string with FormatParam arguments. When passing FormatParam inside the macro call, use parentheses instead of braces to avoid preprocessor comma-splitting: FormatParam(name, Style::bold) not FormatParam{name, Style::bold}.
| var | The variable name to assign the unwrapped value to |
| expr | The expression returning a ChainableResult |
| return_type | The success type of the ChainableResult to return on error |
| ... | Arguments forwarded to the FormattableError constructor (format string, optional FormatParams) |
Definition at line 370 of file chainable_result.hpp.
| #define PT_TRY_ASSIGN_PASS_ERR | ( | var, | |
| expr, | |||
| return_type | |||
| ) |
Unwraps a ChainableResult, passing through the error chain with an empty FormattableError when types differ.
This macro provides a succinct way to handle ChainableResult unwrapping with error passthrough when the inner result's success type differs from the outer function's return type. It evaluates the expression, checks if it contains a value, and either assigns the value to the variable or returns early with an empty FormattableError chained to the existing error chain. This is useful when the current layer doesn't need to add additional error context but the result types don't match (e.g., inner function returns ChainableResult<Foo, E> but outer returns ChainableResult<Bar, E>).
If the result contains an error, the macro returns from the current function with a new ChainableResult<return_type> containing an empty FormattableError chained to the original error chain.
| var | The variable name to assign the unwrapped value to |
| expr | The expression returning a ChainableResult |
| return_type | The success type of the ChainableResult to return on error (differs from expr's success type) |
Definition at line 395 of file chainable_result.hpp.
| #define PT_TRY_ASSIGN_PASS_SAME_ERR | ( | var, | |
| expr | |||
| ) |
Unwraps a ChainableResult, passing through the error unchanged when types match.
This macro provides a succinct way to handle ChainableResult unwrapping with error passthrough when the inner result's type matches the outer function's return type. It evaluates the expression, checks if it contains a value, and either assigns the value to the variable or returns early with the same error result unchanged. This is useful when the current layer doesn't need to add additional error context and the result types match exactly.
If the result contains an error, the macro returns from the current function with the same error result unchanged, preserving the existing error chain without any modifications.
| var | The variable name to assign the unwrapped value to |
| expr | The expression returning a ChainableResult with the same type as the outer function's return type |
Definition at line 417 of file chainable_result.hpp.
| #define PT_TRY_CALL_CHAIN_ERR | ( | expr, | |
| return_type, | |||
| ... | |||
| ) | PT_DETAIL_TRY_CALL_CHAIN_ERR_IMPL(expr, return_type, __LINE__, __VA_ARGS__) |
Unwraps a void ChainableResult, chaining a new error message on failure.
This macro provides a succinct way to handle void-returning ChainableResult unwrapping with error propagation. It evaluates the expression, checks if it contains a success value, and either continues execution or returns early with a new error chained to the existing error chain. This is the void equivalent of PT_TRY_ASSIGN_CHAIN_ERR.
If the result contains an error, the macro returns from the current function with a ChainableResult containing the original error chain plus the new error message provided.
The variadic args are forwarded directly to the FormattableError constructor, so you can pass a plain string or a format string with FormatParam arguments. When passing FormatParam inside the macro call, use parentheses instead of braces to avoid preprocessor comma-splitting: FormatParam(name, Style::bold) not FormatParam{name, Style::bold}.
Uses __LINE__ internally to generate unique variable names and avoid naming collisions between multiple expansions within the same scope. Because the uniqueness token is the source line number, this macro must not be invoked more than once on the same physical line — doing so would produce colliding local variable names.
| expr | The expression returning a ChainableResult<void, E> |
| return_type | The success type of the ChainableResult to return on error |
| ... | Arguments forwarded to the FormattableError constructor (format string, optional FormatParams) |
Definition at line 459 of file chainable_result.hpp.
| #define PT_TRY_CALL_PASS_ERR | ( | expr, | |
| return_type | |||
| ) | PT_DETAIL_TRY_CALL_PASS_ERR_IMPL(expr, return_type, __LINE__) |
Unwraps a void ChainableResult, passing through the error chain with an empty FormattableError when types differ.
This macro provides a succinct way to handle void-returning ChainableResult unwrapping with error passthrough when the inner result's success type differs from the outer function's return type. It evaluates the expression, checks if it contains a success value, and either continues execution or returns early with an empty FormattableError chained to the existing error chain. This is the void equivalent of PT_TRY_ASSIGN_PASS_ERR and is useful when the current layer doesn't need to add additional error context but the result types don't match.
If the result contains an error, the macro returns from the current function with a new ChainableResult<return_type> containing an empty FormattableError chained to the original error chain.
Uses __LINE__ internally to generate unique variable names and avoid naming collisions between multiple expansions within the same scope. Because the uniqueness token is the source line number, this macro must not be invoked more than once on the same physical line — doing so would produce colliding local variable names.
| expr | The expression returning a ChainableResult<void, E> |
| return_type | The success type of the ChainableResult to return on error (differs from expr's success type) |
Definition at line 494 of file chainable_result.hpp.
| #define PT_TRY_CALL_PASS_SAME_ERR | ( | expr | ) | PT_DETAIL_TRY_CALL_PASS_SAME_ERR_IMPL(expr, __LINE__) |
Unwraps a void ChainableResult, passing through the error unchanged when types match.
This macro provides a succinct way to handle void-returning ChainableResult unwrapping with error passthrough when the inner result's type matches the outer function's return type. It evaluates the expression, checks if it contains a success value, and either continues execution or returns early with the same error result unchanged. This is the void equivalent of PT_TRY_ASSIGN_PASS_SAME_ERR and is useful when the current layer doesn't need to add additional error context and the result types match exactly.
If the result contains an error, the macro returns from the current function with the same error result unchanged, preserving the existing error chain without any modifications.
Uses __LINE__ internally to generate unique variable names and avoid naming collisions between multiple expansions within the same scope. Because the uniqueness token is the source line number, this macro must not be invoked more than once on the same physical line — doing so would produce colliding local variable names.
| expr | The expression returning a ChainableResult<void, E> with the same type as the outer function's return type |
Definition at line 526 of file chainable_result.hpp.