• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_UTIL_STATUS_MACROS_H_
16 #define ICING_UTIL_STATUS_MACROS_H_
17 
18 #include "icing/text_classifier/lib3/utils/base/status_macros.h"
19 #include "icing/text_classifier/lib3/utils/base/statusor.h"
20 #include "icing/absl_ports/canonical_errors.h"
21 
22 #define ICING_RETURN_ERROR_IF_NULL(var)                             \
23   do {                                                              \
24     if ((var) == nullptr) {                                         \
25       return absl_ports::FailedPreconditionError(#var " is null."); \
26     }                                                               \
27   } while (false)
28 
29 #define ICING_RETURN_IF_ERROR(expr) TC3_RETURN_IF_ERROR(expr)
30 
31 #define ICING_ASSIGN_OR_RETURN(...)                            \
32   TC_STATUS_MACROS_IMPL_GET_VARIADIC_(                         \
33       (__VA_ARGS__, TC_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_3_, \
34        TC_STATUS_MACROS_IMPL_ASSIGN_OR_RETURN_2_))             \
35   (__VA_ARGS__)
36 
37 #endif  // ICING_UTIL_STATUS_MACROS_H_
38