]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | #include <arrow/api.h> | |
23 | ||
24 | #include <arrow-glib/error.h> | |
25 | ||
26 | gboolean garrow_error_check(GError **error, | |
27 | const arrow::Status &status, | |
28 | const char *context); | |
29 | GArrowError garrow_error_from_status(const arrow::Status &status); | |
30 | arrow::StatusCode | |
31 | garrow_error_to_status_code(GError *error, | |
32 | arrow::StatusCode default_code); | |
33 | arrow::Status garrow_error_to_status(GError *error, | |
34 | arrow::StatusCode default_code, | |
35 | const char *context); | |
36 | ||
37 | namespace garrow { | |
38 | gboolean check(GError **error, | |
39 | const arrow::Status &status, | |
40 | const char *context); | |
41 | ||
42 | template <typename CONTEXT_FUNC> | |
43 | gboolean check(GError **error, | |
44 | const arrow::Status &status, | |
45 | CONTEXT_FUNC &&context_func) { | |
46 | if (status.ok()) { | |
47 | return TRUE; | |
48 | } else { | |
49 | std::string context = std::move(context_func()); | |
50 | g_set_error(error, | |
51 | GARROW_ERROR, | |
52 | garrow_error_from_status(status), | |
53 | "%s: %s", | |
54 | context.c_str(), | |
55 | status.ToString().c_str()); | |
56 | return FALSE; | |
57 | } | |
58 | } | |
59 | ||
60 | template <typename TYPE> | |
61 | gboolean check(GError **error, | |
62 | const arrow::Result<TYPE> &result, | |
63 | const char *context) { | |
64 | return check(error, result.status(), context); | |
65 | } | |
66 | ||
67 | template <typename TYPE, typename CONTEXT_FUNC> | |
68 | gboolean check(GError **error, | |
69 | const arrow::Result<TYPE> &result, | |
70 | CONTEXT_FUNC &&context_func) { | |
71 | return check(error, result.status(), context_func); | |
72 | } | |
73 | } |