CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Enumerations
CCSDSResult.h File Reference
#include <unordered_map>
#include <variant>
#include <vector>
#include <cstdint>
#include <iostream>
Include dependency graph for CCSDSResult.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CCSDS::Error
 Represents an error with both an error code and a message. More...
 
class  CCSDS::Result< T >
 Encapsulates a result that can hold either a value or an Error. More...
 

Namespaces

namespace  CCSDS
 Contains definitions and classes for handling CCSDS headers.
 

Macros

#define RETURN_IF_ERROR(condition, errorCode)   do { if (condition) return errorCode; } while (0)
 Macro to return an error code if a condition is met.
 
#define RET_IF_ERR_MSG(condition, errorCode, message)
 Macro to return an error with an error message if a condition is met.
 
#define ASSIGN_MV(var, result)
 Macro to assign a result value to a variable or return an error by moving.
 
#define ASSIGN_CP(var, result)
 Macro to assign a result value to a variable or return an error by copy.
 
#define ASSIGN_OR_PRINT(var, result)
 Macro to assign a result value or print an error message.
 
#define ASSERT_SUCCESS(result)
 Macro to return immediately if the result contains an error (for void functions).
 
#define FORWARD_RESULT(result)
 Macro to return a result as-is (for functions returning Result<T>).
 

Typedefs

using CCSDS::ResultBool = Result< bool >
 
using CCSDS::ResultBuffer = Result< std::vector< uint8_t > >
 

Enumerations

enum  CCSDS::ErrorCode : uint8_t {
  CCSDS::NONE = 0 , CCSDS::UNKNOWN_ERROR = 1 , CCSDS::NO_DATA = 2 , CCSDS::INVALID_DATA = 3 ,
  CCSDS::INVALID_HEADER_DATA = 4 , CCSDS::INVALID_SECONDARY_HEADER_DATA = 5 , CCSDS::INVALID_APPLICATION_DATA = 6 , CCSDS::NULL_POINTER = 7 ,
  CCSDS::INVALID_CHECKSUM = 8 , CCSDS::VALIDATION_FAILURE = 9 , CCSDS::SOMETHING_WENT_WRONG = 10 , CCSDS::FILE_READ_ERROR = 11 ,
  CCSDS::FILE_WRITE_ERROR = 12 , CCSDS::CONFIG_FILE_ERROR = 13
}
 Defines various error codes used in CCSDS packet handling. More...
 

Macro Definition Documentation

◆ ASSERT_SUCCESS

#define ASSERT_SUCCESS (   result)
Value:
do { \
auto&& _res = (result); \
if (!_res.has_value()) return; \
} while (0)

Macro to return immediately if the result contains an error (for void functions).

Definition at line 196 of file CCSDSResult.h.

197 { \
198 auto&& _res = (result); \
199 if (!_res.has_value()) return; \
200} while (0)

◆ ASSIGN_CP

#define ASSIGN_CP (   var,
  result 
)
Value:
do { \
auto&& _res = (result); \
if (!_res) return _res.error(); \
var = _res.value(); \
} while (0)

Macro to assign a result value to a variable or return an error by copy.

Definition at line 170 of file CCSDSResult.h.

171 { \
172auto&& _res = (result); \
173if (!_res) return _res.error(); \
174var = _res.value(); \
175} while (0)

◆ ASSIGN_MV

#define ASSIGN_MV (   var,
  result 
)
Value:
do { \
auto&& _res = (result); \
if (!_res) return _res.error(); \
var = std::move(_res.value()); \
} while (0)

Macro to assign a result value to a variable or return an error by moving.

Definition at line 159 of file CCSDSResult.h.

160 { \
161 auto&& _res = (result); \
162 if (!_res) return _res.error(); \
163 var = std::move(_res.value()); \
164} while (0)

◆ ASSIGN_OR_PRINT

#define ASSIGN_OR_PRINT (   var,
  result 
)
Value:
do { \
auto&& _res = (result); \
if (!_res) { \
std::cerr << "[ Error ]: Code [" << _res.error().code() << "]: "<< _res.error().message() << '\n'; \
} else { \
var = std::move(_res.value()); \
} \
} while (0)

Macro to assign a result value or print an error message.

Definition at line 182 of file CCSDSResult.h.

183 { \
184 auto&& _res = (result); \
185 if (!_res) { \
186 std::cerr << "[ Error ]: Code [" << _res.error().code() << "]: "<< _res.error().message() << '\n'; \
187 } else { \
188 var = std::move(_res.value()); \
189 } \
190} while (0)

◆ FORWARD_RESULT

#define FORWARD_RESULT (   result)
Value:
do { \
auto&& _res = (result); \
if (!_res.has_value()) return _res; \
} while (0)

Macro to return a result as-is (for functions returning Result<T>).

Definition at line 206 of file CCSDSResult.h.

207 { \
208 auto&& _res = (result); \
209 if (!_res.has_value()) return _res; \
210} while (0)

◆ RET_IF_ERR_MSG

#define RET_IF_ERR_MSG (   condition,
  errorCode,
  message 
)
Value:
do { \
if (condition) { \
return CCSDS::Error{errorCode,message}; \
} \
} while (0)
Represents an error with both an error code and a message.
Definition CCSDSResult.h:43

Macro to return an error with an error message if a condition is met.

Definition at line 148 of file CCSDSResult.h.

149 { \
150 if (condition) { \
151 return CCSDS::Error{errorCode,message}; \
152 } \
153} while (0)

◆ RETURN_IF_ERROR

#define RETURN_IF_ERROR (   condition,
  errorCode 
)    do { if (condition) return errorCode; } while (0)

Macro to return an error code if a condition is met.

Definition at line 141 of file CCSDSResult.h.

142 { if (condition) return errorCode; } while (0)