4#include <unordered_map>
82 std::variant<T, Error>
data;
104 return std::holds_alternative<T>(
data);
120 return std::get<Error>(
data);
141#define RETURN_IF_ERROR(condition, errorCode) \
142do { if (condition) return errorCode; } while (0)
148#define RET_IF_ERR_MSG(condition, errorCode, message) \
151 return CCSDS::Error{errorCode,message}; \
159#define ASSIGN_MV(var, result) \
161 auto&& _res = (result); \
162 if (!_res) return _res.error(); \
163 var = std::move(_res.value()); \
170#define ASSIGN_CP(var, result) \
172auto&& _res = (result); \
173if (!_res) return _res.error(); \
182#define ASSIGN_OR_PRINT(var, result) \
184 auto&& _res = (result); \
186 std::cerr << "[ Error ]: Code [" << _res.error().code() << "]: "<< _res.error().message() << '\n'; \
188 var = std::move(_res.value()); \
196#define ASSERT_SUCCESS(result) \
198 auto&& _res = (result); \
199 if (!_res.has_value()) return; \
206#define FORWARD_RESULT(result) \
208 auto&& _res = (result); \
209 if (!_res.has_value()) return _res; \
Represents an error with both an error code and a message.
ErrorCode code() const
Retrieves the error code.
ErrorCode m_code
The error type.
Error(const ErrorCode code, std::string message)
Constructs an error with a given error code and message.
const std::string & message() const
Retrieves the error message.
std::string m_message
A detailed message describing the error.
Encapsulates a result that can hold either a value or an Error.
bool has_value() const
Checks if the result contains a valid value.
Result(Error error)
Constructor for failure case.
Result(T value)
Constructor for success case.
Error error() const
Retrieves the stored error.
T & value()
Retrieves the stored value.
std::variant< T, Error > data
Holds either a valid value or an Error.
Contains definitions and classes for handling CCSDS headers.
ErrorCode
Defines various error codes used in CCSDS packet handling.
@ NO_DATA
No data available.
@ FILE_READ_ERROR
Reading from file failure.
@ UNKNOWN_ERROR
Unknown error.
@ INVALID_CHECKSUM
Checksum validation failed.
@ INVALID_APPLICATION_DATA
Application data is invalid.
@ INVALID_DATA
Data is invalid.
@ INVALID_HEADER_DATA
Header data is invalid.
@ SOMETHING_WENT_WRONG
General failure.
@ VALIDATION_FAILURE
Validation Failure.
@ FILE_WRITE_ERROR
Writing to file failure.
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
@ NULL_POINTER
Null pointer encountered.