微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MP_RETURN_IF_ERROR在Google的媒体管道代码中起什么作用?

如何解决MP_RETURN_IF_ERROR在Google的媒体管道代码中起什么作用?

  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);

我从Google的mediapipe的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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。