diff options
Diffstat (limited to 'src/mongo/rpc/unique_message.h')
-rw-r--r-- | src/mongo/rpc/unique_message.h | 85 |
1 files changed, 41 insertions, 44 deletions
diff --git a/src/mongo/rpc/unique_message.h b/src/mongo/rpc/unique_message.h index 32799d41919..a763a82ec25 100644 --- a/src/mongo/rpc/unique_message.h +++ b/src/mongo/rpc/unique_message.h @@ -36,62 +36,59 @@ #include "mongo/rpc/request_interface.h" namespace mongo { - class Message; +class Message; namespace rpc { - /** - * A wrapper around an owned message that includes access to an associated - * ReplyInterface or RequestInterface. - */ - template <typename MessageViewType> - class UniqueMessage { - MONGO_DISALLOW_COPYING(UniqueMessage); - public: - UniqueMessage(std::unique_ptr<Message> message, std::unique_ptr<MessageViewType> view) - : _message{std::move(message)} - , _view{std::move(view)} - {} +/** + * A wrapper around an owned message that includes access to an associated + * ReplyInterface or RequestInterface. + */ +template <typename MessageViewType> +class UniqueMessage { + MONGO_DISALLOW_COPYING(UniqueMessage); + +public: + UniqueMessage(std::unique_ptr<Message> message, std::unique_ptr<MessageViewType> view) + : _message{std::move(message)}, _view{std::move(view)} {} #if defined(_MSC_VER) && _MSC_VER < 1900 - UniqueMessage(UniqueMessage&& other) - : _message{std::move(other._message)} - , _view{std::move(other._view)} - {} + UniqueMessage(UniqueMessage&& other) + : _message{std::move(other._message)}, _view{std::move(other._view)} {} - UniqueMessage& operator=(UniqueMessage&& other) { - _message = std::move(other._message); - _view = std::move(other._view); - return *this; - } + UniqueMessage& operator=(UniqueMessage&& other) { + _message = std::move(other._message); + _view = std::move(other._view); + return *this; + } #else - UniqueMessage(UniqueMessage&&) = default; - UniqueMessage& operator=(UniqueMessage&&) = default; + UniqueMessage(UniqueMessage&&) = default; + UniqueMessage& operator=(UniqueMessage&&) = default; #endif - const MessageViewType* operator->() const { - return _view.get(); - } + const MessageViewType* operator->() const { + return _view.get(); + } - const MessageViewType& operator*() const { - return *_view; - } + const MessageViewType& operator*() const { + return *_view; + } - /** - * Releases ownership of the underlying message. The result of calling any other methods - * on the object afterward is undefined. - */ - std::unique_ptr<Message> releaseMessage() { - _view.reset(); - return std::move(_message); - } + /** + * Releases ownership of the underlying message. The result of calling any other methods + * on the object afterward is undefined. + */ + std::unique_ptr<Message> releaseMessage() { + _view.reset(); + return std::move(_message); + } - private: - std::unique_ptr<Message> _message; - std::unique_ptr<MessageViewType> _view; - }; +private: + std::unique_ptr<Message> _message; + std::unique_ptr<MessageViewType> _view; +}; - using UniqueReply = UniqueMessage<ReplyInterface>; - using UniqueRequest = UniqueMessage<RequestInterface>; +using UniqueReply = UniqueMessage<ReplyInterface>; +using UniqueRequest = UniqueMessage<RequestInterface>; } // namespace rpc } // namespace mongo |