Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: mojo/public/cpp/bindings/interface_ptr.h

Issue 828373008: Allow constructing {Interface,Struct}Ptr from nullptr (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "mojo/public/cpp/bindings/error_handler.h" 10 #include "mojo/public/cpp/bindings/error_handler.h"
11 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" 11 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h"
12 #include "mojo/public/cpp/environment/environment.h" 12 #include "mojo/public/cpp/environment/environment.h"
13 #include "mojo/public/cpp/system/macros.h" 13 #include "mojo/public/cpp/system/macros.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 class ErrorHandler; 16 class ErrorHandler;
17 17
18 // InterfacePtr represents a proxy to a remote instance of an interface. 18 // InterfacePtr represents a proxy to a remote instance of an interface.
19 template <typename Interface> 19 template <typename Interface>
20 class InterfacePtr { 20 class InterfacePtr {
21 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InterfacePtr, RValue) 21 MOJO_MOVE_ONLY_TYPE(InterfacePtr)
22 public: 22 public:
23 InterfacePtr() {} 23 InterfacePtr() {}
24 InterfacePtr(decltype(nullptr)) {}
24 25
25 InterfacePtr(RValue other) { 26 InterfacePtr(InterfacePtr&& other) {
26 internal_state_.Swap(&other.object->internal_state_); 27 internal_state_.Swap(&other.internal_state_);
27 } 28 }
28 InterfacePtr& operator=(RValue other) { 29 InterfacePtr& operator=(InterfacePtr&& other) {
29 reset(); 30 reset();
30 internal_state_.Swap(&other.object->internal_state_); 31 internal_state_.Swap(&other.internal_state_);
31 return *this; 32 return *this;
32 } 33 }
33 34
35 InterfacePtr& operator=(decltype(nullptr)) {
36 reset();
37 return *this;
38 }
39
34 ~InterfacePtr() {} 40 ~InterfacePtr() {}
35 41
36 Interface* get() const { return internal_state_.instance(); } 42 Interface* get() const { return internal_state_.instance(); }
37 Interface* operator->() const { return get(); } 43 Interface* operator->() const { return get(); }
38 Interface& operator*() const { return *get(); } 44 Interface& operator*() const { return *get(); }
39 45
40 void reset() { 46 void reset() {
41 State doomed; 47 State doomed;
42 internal_state_.Swap(&doomed); 48 internal_state_.Swap(&doomed);
43 } 49 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { 131 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
126 InterfacePtr<Interface> ptr; 132 InterfacePtr<Interface> ptr;
127 if (handle.is_valid()) 133 if (handle.is_valid())
128 ptr.Bind(handle.Pass(), waiter); 134 ptr.Bind(handle.Pass(), waiter);
129 return ptr.Pass(); 135 return ptr.Pass();
130 } 136 }
131 137
132 } // namespace mojo 138 } // namespace mojo
133 139
134 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 140 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698