![]() |
IRSOL
C++ code implementing socket server for interacting with Baumer camera.
|
Wrapper for the result of a protocol parsing attempt. More...
#include <parser_result.hpp>
Public Types | |
using | result_type = T |
using | error_type = std::string |
using | message_type = std::variant< result_type, error_type > |
Public Member Functions | |
ParserResult (result_type &&message) | |
Constructs a successful parser result. | |
ParserResult (error_type &&error) | |
Constructs a failed parser result with an error string. | |
ParserResult (const ParserResult &)=delete | |
ParserResult & | operator= (ParserResult &&) noexcept=delete |
ParserResult & | operator= (const ParserResult &)=delete |
operator bool () const | |
Checks whether this result contains a valid message. | |
bool | isMessage () const |
Returns true if the result contains a parsed message. | |
bool | isError () const |
Returns true if the result contains an error message. | |
result_type | getMessage () const |
Returns the contained message. | |
error_type | getError () const |
Returns the contained error string. | |
std::string | toString () const |
Returns a human-readable string representation of the result. | |
Private Attributes | |
message_type | _messageOrError |
Wrapper for the result of a protocol parsing attempt.
T | The message type expected from parsing, constrained to be a variant member of irsol::protocol::InMessage. |
This class represents the outcome of trying to parse a protocol input line into a specific message type. It holds either a successfully parsed message of type T
or an error message describing why parsing failed.
The interface allows:
operator bool()
, isMessage()
)getMessage()
)getError()
)toString()
)This class disables copying and move assignment to prevent accidental duplication of results.
Example:
Definition at line 61 of file parser_result.hpp.
using irsol::protocol::internal::ParserResult< T, >::error_type = std::string |
Definition at line 65 of file parser_result.hpp.
using irsol::protocol::internal::ParserResult< T, >::message_type = std::variant<result_type, error_type> |
Definition at line 66 of file parser_result.hpp.
using irsol::protocol::internal::ParserResult< T, >::result_type = T |
Definition at line 64 of file parser_result.hpp.
|
inline |
Constructs a successful parser result.
message | A valid parsed message. |
Definition at line 72 of file parser_result.hpp.
|
inline |
Constructs a failed parser result with an error string.
error | A descriptive error message. |
Definition at line 77 of file parser_result.hpp.
|
delete |
|
inline |
Returns the contained error string.
std::bad_variant_access | if no error is stored. |
Definition at line 118 of file parser_result.hpp.
|
inline |
Returns the contained message.
std::bad_variant_access | if no message is stored. |
Definition at line 110 of file parser_result.hpp.
|
inline |
Returns true if the result contains an error message.
Definition at line 101 of file parser_result.hpp.
|
inline |
Returns true if the result contains a parsed message.
Definition at line 94 of file parser_result.hpp.
|
inlineexplicit |
Checks whether this result contains a valid message.
Definition at line 87 of file parser_result.hpp.
|
delete |
|
deletenoexcept |
|
inline |
Returns a human-readable string representation of the result.
Definition at line 128 of file parser_result.hpp.
|
private |
Definition at line 148 of file parser_result.hpp.