iceberg-cpp
Loading...
Searching...
No Matches
iceberg
util
macros.h
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
17
* under the License.
18
*/
19
20
#pragma once
21
24
25
#include <cassert>
26
27
#include "
iceberg/exception.h
"
28
#include "
iceberg/result.h
"
29
30
#define ICEBERG_RETURN_UNEXPECTED(expr) \
31
if (auto&& result_name = expr; !result_name) [[unlikely]] { \
32
return std::unexpected<Error>(result_name.error()); \
33
}
34
35
#define ICEBERG_ASSIGN_OR_RAISE_IMPL(result_name, lhs, rexpr) \
36
auto&& result_name = (rexpr); \
37
ICEBERG_RETURN_UNEXPECTED(result_name) \
38
lhs = std::move(result_name.value());
39
40
#define ICEBERG_CONCAT(x, y) x##y
41
42
#define ICEBERG_ASSIGN_OR_RAISE_NAME(x, y) ICEBERG_CONCAT(x, y)
43
44
#define ICEBERG_ASSIGN_OR_RAISE(lhs, rexpr) \
45
ICEBERG_ASSIGN_OR_RAISE_IMPL(ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, \
46
rexpr)
47
48
// Macro for debug checks
49
#define ICEBERG_DCHECK(expr, message) assert((expr) && (message))
50
51
// Macro for precondition checks, usually used for function arguments
52
#define ICEBERG_PRECHECK(expr, ...) \
53
do { \
54
if (!(expr)) [[unlikely]] { \
55
return InvalidArgument(__VA_ARGS__); \
56
} \
57
} while (0)
58
59
// Macro for state checks, usually used for unexpected states
60
#define ICEBERG_CHECK(expr, ...) \
61
do { \
62
if (!(expr)) [[unlikely]] { \
63
return ValidationFailed(__VA_ARGS__); \
64
} \
65
} while (0)
66
67
#define ERROR_TO_EXCEPTION(error) \
68
if (error.kind == iceberg::ErrorKind::kInvalidExpression) { \
69
throw iceberg::ExpressionError(error.message); \
70
} else { \
71
throw iceberg::IcebergError(error.message); \
72
}
73
74
#define ICEBERG_THROW_NOT_OK(expr) \
75
if (auto&& result_name = expr; !result_name) [[unlikely]] { \
76
ERROR_TO_EXCEPTION(result_name.error()); \
77
}
78
79
#define ICEBERG_ASSIGN_OR_THROW_IMPL(result_name, lhs, rexpr) \
80
auto&& result_name = (rexpr); \
81
ICEBERG_THROW_NOT_OK(result_name); \
82
lhs = std::move(result_name.value());
83
84
#define ICEBERG_ASSIGN_OR_THROW(lhs, rexpr) \
85
ICEBERG_ASSIGN_OR_THROW_IMPL( \
86
ICEBERG_ASSIGN_OR_RAISE_NAME(_error_or_value, __COUNTER__), lhs, rexpr);
exception.h
result.h
Define Result, Status, and error helpers.
Generated by
1.9.8