File indexing completed on 2025-01-31 10:12:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef GOOGLE_PROTOBUF_STUBS_STATUS_MACROS_H_
0011 #define GOOGLE_PROTOBUF_STUBS_STATUS_MACROS_H_
0012
0013 #include "absl/status/status.h"
0014 #include "absl/status/statusor.h"
0015 #include "google/protobuf/stubs/common.h"
0016
0017
0018 #include "google/protobuf/port_def.inc" // NOLINT
0019
0020 namespace google {
0021 namespace protobuf {
0022 namespace util {
0023
0024
0025
0026
0027
0028
0029 #define RETURN_IF_ERROR(expr) \
0030 do { \
0031 \
0032 const absl::Status _status = (expr); \
0033 if (PROTOBUF_PREDICT_FALSE(!_status.ok())) return _status; \
0034 } while (0)
0035
0036
0037 #define STATUS_MACROS_CONCAT_NAME_INNER(x, y) x##y
0038 #define STATUS_MACROS_CONCAT_NAME(x, y) STATUS_MACROS_CONCAT_NAME_INNER(x, y)
0039
0040 template <typename T>
0041 absl::Status DoAssignOrReturn(T& lhs, absl::StatusOr<T> result) {
0042 if (result.ok()) {
0043 lhs = result.value();
0044 }
0045 return result.status();
0046 }
0047
0048 #define ASSIGN_OR_RETURN_IMPL(status, lhs, rexpr) \
0049 absl::Status status = DoAssignOrReturn(lhs, (rexpr)); \
0050 if (PROTOBUF_PREDICT_FALSE(!status.ok())) return status;
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 #define ASSIGN_OR_RETURN(lhs, rexpr) \
0062 ASSIGN_OR_RETURN_IMPL( \
0063 STATUS_MACROS_CONCAT_NAME(_status_or_value, __COUNTER__), lhs, rexpr);
0064
0065 }
0066 }
0067 }
0068
0069 #include "google/protobuf/port_undef.inc" // NOLINT
0070
0071 #endif