|
@@ -23,43 +23,30 @@
|
|
|
|
|
|
namespace hdfs {
|
|
|
|
|
|
-class StatusHelper;
|
|
|
class Status {
|
|
|
public:
|
|
|
// Create a success status.
|
|
|
- Status() : state_(NULL) { }
|
|
|
- ~Status() { delete[] state_; }
|
|
|
- explicit Status(int code, const char *msg);
|
|
|
+ Status() : code_(0) {};
|
|
|
+ Status(int code, const char *msg);
|
|
|
+ Status(int code, const char *msg1, const char *msg2);
|
|
|
|
|
|
- // Copy the specified status.
|
|
|
- Status(const Status& s);
|
|
|
- void operator=(const Status& s);
|
|
|
+ // Factory methods
|
|
|
+ static Status OK();
|
|
|
+ static Status InvalidArgument(const char *msg);
|
|
|
+ static Status ResourceUnavailable(const char *msg);
|
|
|
+ static Status Unimplemented();
|
|
|
+ static Status Exception(const char *expception_class_name, const char *error_message);
|
|
|
+ static Status Error(const char *error_message);
|
|
|
+ static Status Canceled();
|
|
|
|
|
|
- // Return a success status.
|
|
|
- static Status OK() { return Status(); }
|
|
|
- static Status InvalidArgument(const char *msg)
|
|
|
- { return Status(kInvalidArgument, msg); }
|
|
|
- static Status ResourceUnavailable(const char *msg)
|
|
|
- { return Status(kResourceUnavailable, msg); }
|
|
|
- static Status Unimplemented()
|
|
|
- { return Status(kUnimplemented, ""); }
|
|
|
- static Status Exception(const char *expception_class_name, const char *error_message)
|
|
|
- { return Status(kException, expception_class_name, error_message); }
|
|
|
- static Status Error(const char *error_message)
|
|
|
- { return Exception("Exception", error_message); }
|
|
|
- static Status Canceled()
|
|
|
- { return Status(kOperationCanceled,""); }
|
|
|
+ // success
|
|
|
+ bool ok() const { return code_ == 0; }
|
|
|
|
|
|
- // Returns true iff the status indicates success.
|
|
|
- bool ok() const { return (state_ == NULL); }
|
|
|
-
|
|
|
- // Return a string representation of this status suitable for printing.
|
|
|
// Returns the string "OK" for success.
|
|
|
std::string ToString() const;
|
|
|
|
|
|
- int code() const {
|
|
|
- return (state_ == NULL) ? kOk : static_cast<int>(state_[4]);
|
|
|
- }
|
|
|
+ // get error code
|
|
|
+ int code() const { return code_; }
|
|
|
|
|
|
enum Code {
|
|
|
kOk = 0,
|
|
@@ -71,31 +58,10 @@ class Status {
|
|
|
};
|
|
|
|
|
|
private:
|
|
|
- // OK status has a NULL state_. Otherwise, state_ is a new[] array
|
|
|
- // of the following form:
|
|
|
- // state_[0..3] == length of message
|
|
|
- // state_[4] == code
|
|
|
- // state_[5..] == message
|
|
|
- const char* state_;
|
|
|
-
|
|
|
- explicit Status(int code, const char *msg1, const char *msg2);
|
|
|
- static const char *CopyState(const char* s);
|
|
|
- static const char *ConstructState(int code, const char *msg1, const char *msg2);
|
|
|
+ int code_;
|
|
|
+ std::string msg_;
|
|
|
};
|
|
|
|
|
|
-inline Status::Status(const Status& s) {
|
|
|
- state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
|
|
|
-}
|
|
|
-
|
|
|
-inline void Status::operator=(const Status& s) {
|
|
|
- // The following condition catches both aliasing (when this == &s),
|
|
|
- // and the common case where both s and *this are ok.
|
|
|
- if (state_ != s.state_) {
|
|
|
- delete[] state_;
|
|
|
- state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
#endif
|