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
27
28
#include <cassert>
29
30
#include "
iceberg/exception.h
"
31
#include "
iceberg/result.h
"
32
33
#define ICEBERG_RETURN_UNEXPECTED(expr) \
34
if (auto&& result_name = expr; !result_name) [[unlikely]] { \
35
return ::iceberg::unexpected<::iceberg::Error>(result_name.error()); \
36
}
37
38
#define ICEBERG_ASSIGN_OR_RAISE_IMPL(result_name, lhs, rexpr) \
39
auto&& result_name = (rexpr); \
40
ICEBERG_RETURN_UNEXPECTED(result_name) \
41
lhs = std::move(result_name.value());
42
43
#define ICEBERG_CONCAT(x, y) x##y
44
45
#define ICEBERG_ASSIGN_OR_RAISE_NAME(x, y) ICEBERG_CONCAT(x, y)
46
47
#define ICEBERG_ASSIGN_OR_RAISE(lhs, rexpr) \
48
ICEBERG_ASSIGN_OR_RAISE_IMPL(ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, \
49
rexpr)
50
51
// Macro for debug checks
52
#define ICEBERG_DCHECK(expr, message) assert((expr) && (message))
53
54
// Macro for precondition checks, usually used for function arguments
55
#define ICEBERG_PRECHECK(expr, ...) \
56
do { \
57
if (!(expr)) [[unlikely]] { \
58
return ::iceberg::InvalidArgument(__VA_ARGS__); \
59
} \
60
} while (0)
61
62
// Macro for state checks, usually used for unexpected states
63
#define ICEBERG_CHECK(expr, ...) \
64
do { \
65
if (!(expr)) [[unlikely]] { \
66
return ::iceberg::ValidationFailed(__VA_ARGS__); \
67
} \
68
} while (0)
69
70
#define ERROR_TO_EXCEPTION(error) \
71
if (error.kind == ::iceberg::ErrorKind::kInvalidExpression) { \
72
throw ::iceberg::ExpressionError(error.message); \
73
} else { \
74
throw ::iceberg::IcebergError(error.message); \
75
}
76
77
#define ICEBERG_THROW_NOT_OK(expr) \
78
if (auto&& result_name = expr; !result_name) [[unlikely]] { \
79
ERROR_TO_EXCEPTION(result_name.error()); \
80
}
81
82
#define ICEBERG_ASSIGN_OR_THROW_IMPL(result_name, lhs, rexpr) \
83
auto&& result_name = (rexpr); \
84
ICEBERG_THROW_NOT_OK(result_name); \
85
lhs = std::move(result_name.value());
86
87
#define ICEBERG_ASSIGN_OR_THROW(lhs, rexpr) \
88
ICEBERG_ASSIGN_OR_THROW_IMPL( \
89
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