diff options
Diffstat (limited to 'src/mongo/base/status.cpp')
-rw-r--r-- | src/mongo/base/status.cpp | 117 |
1 files changed, 56 insertions, 61 deletions
diff --git a/src/mongo/base/status.cpp b/src/mongo/base/status.cpp index 62466310ec6..c40d52f0d13 100644 --- a/src/mongo/base/status.cpp +++ b/src/mongo/base/status.cpp @@ -32,64 +32,59 @@ namespace mongo { - Status::ErrorInfo::ErrorInfo(ErrorCodes::Error aCode, std::string aReason, int aLocation) - : code(aCode), reason(std::move(aReason)), location(aLocation) { - } - - Status::ErrorInfo* Status::ErrorInfo::create(ErrorCodes::Error c, std::string r, int l) { - const bool needRep = ((c != ErrorCodes::OK) || - !r.empty() || - (l != 0)); - return needRep ? new ErrorInfo(c, std::move(r), l) : NULL; - } - - Status::Status(ErrorCodes::Error code, std::string reason, int location) - : _error(ErrorInfo::create(code, std::move(reason), location)) { - ref(_error); - } - - bool Status::compare(const Status& other) const { - return - code() == other.code() && - location() == other.location(); - } - - bool Status::operator==(const Status& other) const { - return compare(other); - } - - bool Status::operator!=(const Status& other) const { - return ! compare(other); - } - - bool Status::compareCode(const ErrorCodes::Error other) const { - return code() == other; - } - - bool Status::operator==(const ErrorCodes::Error other) const { - return compareCode(other); - } - - bool Status::operator!=(const ErrorCodes::Error other) const { - return ! compareCode(other); - } - - std::ostream& operator<<(std::ostream& os, const Status& status) { - return os << status.codeString() << " " << status.reason(); - } - - std::ostream& operator<<(std::ostream& os, ErrorCodes::Error code) { - return os << ErrorCodes::errorString(code); - } - - std::string Status::toString() const { - std::ostringstream ss; - ss << codeString(); - if ( !isOK() ) - ss << " " << reason(); - if ( location() != 0 ) - ss << " @ " << location(); - return ss.str(); - } - -} // namespace mongo +Status::ErrorInfo::ErrorInfo(ErrorCodes::Error aCode, std::string aReason, int aLocation) + : code(aCode), reason(std::move(aReason)), location(aLocation) {} + +Status::ErrorInfo* Status::ErrorInfo::create(ErrorCodes::Error c, std::string r, int l) { + const bool needRep = ((c != ErrorCodes::OK) || !r.empty() || (l != 0)); + return needRep ? new ErrorInfo(c, std::move(r), l) : NULL; +} + +Status::Status(ErrorCodes::Error code, std::string reason, int location) + : _error(ErrorInfo::create(code, std::move(reason), location)) { + ref(_error); +} + +bool Status::compare(const Status& other) const { + return code() == other.code() && location() == other.location(); +} + +bool Status::operator==(const Status& other) const { + return compare(other); +} + +bool Status::operator!=(const Status& other) const { + return !compare(other); +} + +bool Status::compareCode(const ErrorCodes::Error other) const { + return code() == other; +} + +bool Status::operator==(const ErrorCodes::Error other) const { + return compareCode(other); +} + +bool Status::operator!=(const ErrorCodes::Error other) const { + return !compareCode(other); +} + +std::ostream& operator<<(std::ostream& os, const Status& status) { + return os << status.codeString() << " " << status.reason(); +} + +std::ostream& operator<<(std::ostream& os, ErrorCodes::Error code) { + return os << ErrorCodes::errorString(code); +} + +std::string Status::toString() const { + std::ostringstream ss; + ss << codeString(); + if (!isOK()) + ss << " " << reason(); + if (location() != 0) + ss << " @ " << location(); + return ss.str(); +} + +} // namespace mongo |