summaryrefslogtreecommitdiff
path: root/src/mongo/base/status.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/base/status.h')
-rw-r--r--src/mongo/base/status.h68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/mongo/base/status.h b/src/mongo/base/status.h
index 61a155e98cf..52a46d0adb0 100644
--- a/src/mongo/base/status.h
+++ b/src/mongo/base/status.h
@@ -266,6 +266,70 @@ std::ostream& operator<<(std::ostream& os, const Status& status);
template <typename Allocator>
StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, const Status& status);
-} // namespace mongo
+inline Status Status::OK() {
+ return Status();
+}
+
+inline Status::Status(const Status& other) : _error(other._error) {
+ ref(_error);
+}
+
+inline Status& Status::operator=(const Status& other) {
+ ref(other._error);
+ unref(_error);
+ _error = other._error;
+ return *this;
+}
+
+inline Status::Status(Status&& other) noexcept : _error(other._error) {
+ other._error = nullptr;
+}
+
+inline Status& Status::operator=(Status&& other) noexcept {
+ unref(_error);
+ _error = other._error;
+ other._error = nullptr;
+ return *this;
+}
+
+inline Status::~Status() {
+ unref(_error);
+}
+
+inline bool Status::isOK() const {
+ return !_error;
+}
+
+inline ErrorCodes::Error Status::code() const {
+ return _error ? _error->code : ErrorCodes::OK;
+}
+
+inline std::string Status::codeString() const {
+ return ErrorCodes::errorString(code());
+}
+
+inline unsigned Status::refCount() const {
+ return _error ? _error->refs.load() : 0;
+}
+
+inline Status::Status() : _error(NULL) {}
+
+inline void Status::ref(ErrorInfo* error) {
+ if (error)
+ error->refs.fetchAndAdd(1);
+}
+
+inline void Status::unref(ErrorInfo* error) {
+ if (error && (error->refs.subtractAndFetch(1) == 0))
+ delete error;
+}
+
+inline bool operator==(const ErrorCodes::Error lhs, const Status& rhs) {
+ return rhs == lhs;
+}
+
+inline bool operator!=(const ErrorCodes::Error lhs, const Status& rhs) {
+ return rhs != lhs;
+}
-#include "mongo/base/status-inl.h"
+} // namespace mongo