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 <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< std::uint8_t > >
 

Enumerations

enum  CCSDS::ErrorCode : std::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::TEMPLATE_SET_FAILURE = 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 197 of file CCSDSResult.h.

198 { \
199 auto&& _res = (result); \
200 if (!_res.has_value()) return; \
201} 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 171 of file CCSDSResult.h.

172 { \
173auto&& _res = (result); \
174if (!_res) return _res.error(); \
175var = _res.value(); \
176} 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 160 of file CCSDSResult.h.

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

◆ ASSIGN_OR_PRINT

#define ASSIGN_OR_PRINT (   var,
  result 
)
Value:
do { \
auto&& _res = (result); \
if (!_res) { \
printf("[ Error ]: Code [%u]: %s\n", static_cast<unsigned>(_res.error().code()), _res.error().message().c_str());; \
} else { \
var = std::move(_res.value()); \
} \
} while (0)

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

Definition at line 183 of file CCSDSResult.h.

184 { \
185 auto&& _res = (result); \
186 if (!_res) { \
187 printf("[ Error ]: Code [%u]: %s\n", static_cast<unsigned>(_res.error().code()), _res.error().message().c_str());; \
188 } else { \
189 var = std::move(_res.value()); \
190 } \
191} 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 207 of file CCSDSResult.h.

208 { \
209 auto&& _res = (result); \
210 if (!_res.has_value()) return _res; \
211} 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:44

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

Definition at line 149 of file CCSDSResult.h.

150 { \
151 if (condition) { \
152 return CCSDS::Error{errorCode,message}; \
153 } \
154} 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 142 of file CCSDSResult.h.

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