提交 a6d4a31d 编写于 作者: Y Yu Yang

Follow comments

上级 5a15c70e
...@@ -79,33 +79,32 @@ namespace paddle { ...@@ -79,33 +79,32 @@ namespace paddle {
* use log(FATAL) or CHECK to make program exit before. When we clean all * use log(FATAL) or CHECK to make program exit before. When we clean all
* log(FATAL) and CHECK in Paddle, 'check' method will be removed. * log(FATAL) and CHECK in Paddle, 'check' method will be removed.
*/ */
class Error final { class Error {
public: public:
/** /**
* Default Status. OK * Construct an no-error value.
*/ */
inline Error() {} Error() {}
/** /**
* @brief Create an Error use printf syntax. * @brief Create an Error use printf syntax.
*/ */
inline explicit Error(const char* fmt, ...) { explicit Error(const char* fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
constexpr size_t kBufferSize = 1024; constexpr size_t kBufferSize = 1024;
this->errMsg_.reset(new std::string(kBufferSize, 0)); char buffer[kBufferSize];
auto sz = vsnprintf(&(*errMsg_)[0], kBufferSize, fmt, ap); vsnprintf(buffer, kBufferSize, fmt, ap);
this->errMsg_->resize(sz); this->msg_.reset(new std::string(buffer));
this->errMsg_->shrink_to_fit();
va_end(ap); va_end(ap);
} }
/** /**
* @brief what will return the error message. If no error, return nullptr. * @brief what will return the error message. If no error, return nullptr.
*/ */
inline const char* msg() const { const char* msg() const {
if (errMsg_) { if (msg_) {
return errMsg_->data(); return msg_->c_str();
} else { } else {
return nullptr; return nullptr;
} }
...@@ -114,16 +113,16 @@ public: ...@@ -114,16 +113,16 @@ public:
/** /**
* @brief operator bool, return True if there is no error. * @brief operator bool, return True if there is no error.
*/ */
inline operator bool() const { return !errMsg_; } operator bool() const { return !msg_; }
/** /**
* @brief check this status by glog. * @brief check this status by glog.
* @note It is a temp method used during cleaning Paddle code. It will be * @note It is a temp method used during cleaning Paddle code. It will be
* removed later. * removed later.
*/ */
inline void check() const { CHECK(*this) << msg(); } void check() const { CHECK(*this) << msg(); }
private: private:
std::shared_ptr<std::string> errMsg_; std::shared_ptr<std::string> msg_;
}; };
} // namespace paddle } // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册