iceberg-cpp
Loading...
Searching...
No Matches
Macros
macros.h File Reference

Define common Iceberg utility macros. More...

#include <cassert>
#include "iceberg/exception.h"
#include "iceberg/result.h"

Go to the source code of this file.

Macros

#define ICEBERG_RETURN_UNEXPECTED(expr)
 
#define ICEBERG_ASSIGN_OR_RAISE_IMPL(result_name, lhs, rexpr)
 
#define ICEBERG_CONCAT(x, y)   x##y
 
#define ICEBERG_ASSIGN_OR_RAISE_NAME(x, y)   ICEBERG_CONCAT(x, y)
 
#define ICEBERG_ASSIGN_OR_RAISE(lhs, rexpr)
 
#define ICEBERG_DCHECK(expr, message)   assert((expr) && (message))
 
#define ICEBERG_PRECHECK(expr, ...)
 
#define ICEBERG_CHECK(expr, ...)
 
#define ERROR_TO_EXCEPTION(error)
 
#define ICEBERG_THROW_NOT_OK(expr)
 
#define ICEBERG_ASSIGN_OR_THROW_IMPL(result_name, lhs, rexpr)
 
#define ICEBERG_ASSIGN_OR_THROW(lhs, rexpr)
 

Detailed Description

Define common Iceberg utility macros.

Macro Definition Documentation

◆ ERROR_TO_EXCEPTION

#define ERROR_TO_EXCEPTION (   error)
Value:
if (error.kind == iceberg::ErrorKind::kInvalidExpression) { \
throw iceberg::ExpressionError(error.message); \
} else { \
throw iceberg::IcebergError(error.message); \
}
Exception thrown when expression construction fails.
Definition exception.h:42
Base exception class for exceptions thrown by the Iceberg library.
Definition exception.h:36

◆ ICEBERG_ASSIGN_OR_RAISE

#define ICEBERG_ASSIGN_OR_RAISE (   lhs,
  rexpr 
)
Value:
ICEBERG_ASSIGN_OR_RAISE_IMPL(ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, \
rexpr)

◆ ICEBERG_ASSIGN_OR_RAISE_IMPL

#define ICEBERG_ASSIGN_OR_RAISE_IMPL (   result_name,
  lhs,
  rexpr 
)
Value:
auto&& result_name = (rexpr); \
ICEBERG_RETURN_UNEXPECTED(result_name) \
lhs = std::move(result_name.value());

◆ ICEBERG_ASSIGN_OR_THROW

#define ICEBERG_ASSIGN_OR_THROW (   lhs,
  rexpr 
)
Value:
ICEBERG_ASSIGN_OR_THROW_IMPL( \
ICEBERG_ASSIGN_OR_RAISE_NAME(_error_or_value, __COUNTER__), lhs, rexpr);

◆ ICEBERG_ASSIGN_OR_THROW_IMPL

#define ICEBERG_ASSIGN_OR_THROW_IMPL (   result_name,
  lhs,
  rexpr 
)
Value:
auto&& result_name = (rexpr); \
ICEBERG_THROW_NOT_OK(result_name); \
lhs = std::move(result_name.value());

◆ ICEBERG_CHECK

#define ICEBERG_CHECK (   expr,
  ... 
)
Value:
do { \
if (!(expr)) [[unlikely]] { \
return ValidationFailed(__VA_ARGS__); \
} \
} while (0)

◆ ICEBERG_PRECHECK

#define ICEBERG_PRECHECK (   expr,
  ... 
)
Value:
do { \
if (!(expr)) [[unlikely]] { \
return InvalidArgument(__VA_ARGS__); \
} \
} while (0)

◆ ICEBERG_RETURN_UNEXPECTED

#define ICEBERG_RETURN_UNEXPECTED (   expr)
Value:
if (auto&& result_name = expr; !result_name) [[unlikely]] { \
return std::unexpected<Error>(result_name.error()); \
}

◆ ICEBERG_THROW_NOT_OK

#define ICEBERG_THROW_NOT_OK (   expr)
Value:
if (auto&& result_name = expr; !result_name) [[unlikely]] { \
ERROR_TO_EXCEPTION(result_name.error()); \
}