Apollo 10.0
自动驾驶开放平台
apollo::common::Status类 参考

A general class to denote the return status of an API call. 更多...

#include <status.h>

apollo::common::Status 的协作图:

Public 成员函数

 Status (ErrorCode code=ErrorCode::OK, std::string_view msg="")
 Create a status with the specified error code and msg as a human-readable string containing more detailed information.
 
 ~Status ()=default
 
bool ok () const
 check whether the return status is OK.
 
ErrorCode code () const
 get the error code
 
bool operator== (const Status &rh) const
 defines the logic of testing if two Status are equal
 
bool operator!= (const Status &rh) const
 defines the logic of testing if two Status are unequal
 
const std::string & error_message () const
 returns the error message of the status, empty if the status is OK.
 
std::string ToString () const
 returns a string representation in a readable format.
 
void Save (StatusPb *status_pb)
 save the error_code and error message to protobuf
 

静态 Public 成员函数

static Status OK ()
 generate a success status.
 

详细描述

A general class to denote the return status of an API call.

It can either be an OK status for success, or a failure status with error message and error code enum.

在文件 status.h43 行定义.

构造及析构函数说明

◆ Status()

apollo::common::Status::Status ( ErrorCode  code = ErrorCode::OK,
std::string_view  msg = "" 
)
inlineexplicit

Create a status with the specified error code and msg as a human-readable string containing more detailed information.

参数
codethe error code.
msgthe message associated with the error.

在文件 status.h51 行定义.

52 : code_(code), msg_(msg.data()) {}
ErrorCode code() const
get the error code
Definition status.h:73

◆ ~Status()

apollo::common::Status::~Status ( )
default

成员函数说明

◆ code()

ErrorCode apollo::common::Status::code ( ) const
inline

get the error code

返回
the error code

在文件 status.h73 行定义.

73{ return code_; }

◆ error_message()

const std::string & apollo::common::Status::error_message ( ) const
inline

returns the error message of the status, empty if the status is OK.

返回
the error message

在文件 status.h91 行定义.

91{ return msg_; }

◆ OK()

static Status apollo::common::Status::OK ( )
inlinestatic

generate a success status.

返回
a success status

在文件 status.h60 行定义.

60{ return Status(); }
Status(ErrorCode code=ErrorCode::OK, std::string_view msg="")
Create a status with the specified error code and msg as a human-readable string containing more deta...
Definition status.h:51

◆ ok()

bool apollo::common::Status::ok ( ) const
inline

check whether the return status is OK.

返回
true if the code is ErrorCode::OK false otherwise

在文件 status.h67 行定义.

67{ return code_ == ErrorCode::OK; }

◆ operator!=()

bool apollo::common::Status::operator!= ( const Status rh) const
inline

defines the logic of testing if two Status are unequal

在文件 status.h85 行定义.

85{ return !(*this == rh); }

◆ operator==()

bool apollo::common::Status::operator== ( const Status rh) const
inline

defines the logic of testing if two Status are equal

在文件 status.h78 行定义.

78 {
79 return (this->code_ == rh.code_) && (this->msg_ == rh.msg_);
80 }

◆ Save()

void apollo::common::Status::Save ( StatusPb status_pb)
inline

save the error_code and error message to protobuf

参数
theStatus protobuf that will store the message.

在文件 status.h109 行定义.

109 {
110 if (!status_pb) {
111 return;
112 }
113 status_pb->set_error_code(code_);
114 if (!msg_.empty()) {
115 status_pb->set_msg(msg_);
116 }
117 }

◆ ToString()

std::string apollo::common::Status::ToString ( ) const
inline

returns a string representation in a readable format.

返回
the string "OK" if success. the internal error message otherwise.

在文件 status.h98 行定义.

98 {
99 if (ok()) {
100 return "OK";
101 }
102 return ErrorCode_Name(code_) + ": " + msg_;
103 }
bool ok() const
check whether the return status is OK.
Definition status.h:67

该类的文档由以下文件生成: