0
  std::string calculator_graph_config_contents; // name of string
  MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
      FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
  LOG(INFO) << "Get calculator graph config contents: "
            << calculator_graph_config_contents;
  mediapipe::CalculatorGraphConfig config =
      mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(
          calculator_graph_config_contents);

我有来自谷歌媒体管道的 demo_run_graph_main.cc 文件的这段代码。我无法理解 MP_RETURN_IF_ERROR 函数的作用。我也没有找到解释这一点的文档。有人可以向我解释它的作用吗?

宏观定义

#define MP_RETURN_IF_ERROR(expr)                                          \
  STATUS_MACROS_IMPL_ELSE_BLOCKER_                                        \
  if (::mediapipe::status_macro_internal::StatusAdaptorForMacros          \
          status_macro_internal_adaptor = {(expr), __FILE__, __LINE__}) { \
  } else /* NOLINT */                                                     \
    return status_macro_internal_adaptor.Consume()

// Executes an expression `rexpr` that returns a `::mediapipe::StatusOr<T>`. On
// OK, extracts its value into the variable defined by `lhs`, otherwise returns
// from the current function. By default the error status is returned
// unchanged, but it may be modified by an `error_expression`. If there is an
// error, `lhs` is not evaluated; thus any side effects that `lhs` may have
// only occur in the success case.
#define STATUS_MACROS_IMPL_ELSE_BLOCKER_ \
  switch (0)                             \
  case 0:                                \
  default:  // NOLINT
4

0 回答 0