From b7c80ec25658288217947e3d4aaf1e27826bb578 Mon Sep 17 00:00:00 2001 From: Andrew Morrow Date: Fri, 17 May 2013 11:18:55 -0400 Subject: SERVER-9757 Move Status inlines to inline header --- src/mongo/base/status-inl.h | 36 ++++++++++++++++++++++++++++++++ src/mongo/base/status.h | 51 +++++++++++++++------------------------------ 2 files changed, 53 insertions(+), 34 deletions(-) (limited to 'src/mongo') diff --git a/src/mongo/base/status-inl.h b/src/mongo/base/status-inl.h index 3d50308c176..22679707b6c 100644 --- a/src/mongo/base/status-inl.h +++ b/src/mongo/base/status-inl.h @@ -17,6 +17,10 @@ namespace mongo { + inline Status Status::OK() { + return Status(); + } + inline Status::Status(const Status& other) : _error(other._error) { ref(_error); @@ -33,6 +37,30 @@ namespace mongo { unref(_error); } + inline bool Status::isOK() const { + return code() == ErrorCodes::OK; + } + + inline ErrorCodes::Error Status::code() const { + return _error ? _error->code : ErrorCodes::OK; + } + + inline const char* Status::codeString() const { + return ErrorCodes::errorString(code()); + } + + inline std::string Status::reason() const { + return _error ? _error->reason : std::string(); + } + + inline int Status::location() const { + return _error ? _error->location : 0; + } + + inline AtomicUInt32::WordType Status::refCount() const { + return _error ? _error->refs.load() : 0; + } + inline Status::Status() : _error(NULL) { } @@ -47,4 +75,12 @@ namespace mongo { 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; + } + } // namespace mongo diff --git a/src/mongo/base/status.h b/src/mongo/base/status.h index 4454913e725..d4d0ba0f9bf 100644 --- a/src/mongo/base/status.h +++ b/src/mongo/base/status.h @@ -49,9 +49,7 @@ namespace mongo { class Status { public: // Short-hand for returning an OK status. - static Status OK() { - return Status(); - } + static inline Status OK(); /** * Builds an error status given the error code, a textual description of what @@ -60,9 +58,11 @@ namespace mongo { */ Status(ErrorCodes::Error code, const std::string& reason, int location = 0); Status(ErrorCodes::Error code, const char* reason, int location = 0); - Status(const Status& other); - Status& operator=(const Status& other); - ~Status(); + + inline Status(const Status& other); + inline Status& operator=(const Status& other); + + inline ~Status(); /** * Returns true if 'other's error code and location are equal/different to this @@ -84,25 +84,15 @@ namespace mongo { // accessors // - bool isOK() const { - return code() == ErrorCodes::OK; - } + inline bool isOK() const; - ErrorCodes::Error code() const { - return _error ? _error->code : ErrorCodes::OK; - } + inline ErrorCodes::Error code() const; - const char* codeString() const { - return ErrorCodes::errorString(code()); - } + inline const char* codeString() const; - std::string reason() const { - return _error ? _error->reason : std::string(); - } + inline std::string reason() const; - int location() const { - return _error ? _error->location : 0; - } + inline int location() const; std::string toString() const; @@ -110,12 +100,10 @@ namespace mongo { // Below interface used for testing code only. // - AtomicUInt32::WordType refCount() const { - return _error ? _error->refs.load() : 0; - } + inline AtomicUInt32::WordType refCount() const; private: - Status(); + inline Status(); struct ErrorInfo { AtomicUInt32 refs; // reference counter @@ -136,17 +124,13 @@ namespace mongo { * * @param error ErrorInfo to be incremented */ - static void ref(ErrorInfo* error); - static void unref(ErrorInfo* error); + static inline void ref(ErrorInfo* error); + static inline void unref(ErrorInfo* error); }; - inline bool operator==(const ErrorCodes::Error lhs, const Status& rhs) { - return rhs == lhs; - } + inline bool operator==(const ErrorCodes::Error lhs, const Status& rhs); - inline bool operator!=(const ErrorCodes::Error lhs, const Status& rhs) { - return rhs != lhs; - } + inline bool operator!=(const ErrorCodes::Error lhs, const Status& rhs); // // Convenience method for unittest code. Please use accessors otherwise. @@ -158,4 +142,3 @@ namespace mongo { } // namespace mongo #include "mongo/base/status-inl.h" - -- cgit v1.2.1