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

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

Issue 649633003: Add Equals() to mojom structs and related types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reorder Created 6 years, 2 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
« no previous file with comments | « mojo/public/cpp/bindings/map.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_STRUCT_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
7 7
8 #include <new> 8 #include <new>
9 9
10 #include "mojo/public/cpp/bindings/type_converter.h" 10 #include "mojo/public/cpp/bindings/type_converter.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 Struct* get() const { return ptr_; } 65 Struct* get() const { return ptr_; }
66 66
67 void Swap(StructPtr* other) { std::swap(ptr_, other->ptr_); } 67 void Swap(StructPtr* other) { std::swap(ptr_, other->ptr_); }
68 68
69 // Please note that calling this method will fail compilation if the value 69 // Please note that calling this method will fail compilation if the value
70 // type |Struct| doesn't have a Clone() method defined (which usually means 70 // type |Struct| doesn't have a Clone() method defined (which usually means
71 // that it contains Mojo handles). 71 // that it contains Mojo handles).
72 StructPtr Clone() const { return is_null() ? StructPtr() : ptr_->Clone(); } 72 StructPtr Clone() const { return is_null() ? StructPtr() : ptr_->Clone(); }
73 73
74 bool Equals(const StructPtr& other) const {
75 if (is_null() || other.is_null())
76 return is_null() && other.is_null();
77 return ptr_->Equals(*other.ptr_);
78 }
79
74 private: 80 private:
75 typedef Struct* StructPtr::*Testable; 81 typedef Struct* StructPtr::*Testable;
76 82
77 public: 83 public:
78 operator Testable() const { return ptr_ ? &StructPtr::ptr_ : 0; } 84 operator Testable() const { return ptr_ ? &StructPtr::ptr_ : 0; }
79 85
80 private: 86 private:
81 friend class internal::StructHelper<Struct>; 87 friend class internal::StructHelper<Struct>;
82 void Initialize() { 88 void Initialize() {
83 MOJO_DCHECK(!ptr_); 89 MOJO_DCHECK(!ptr_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 Struct* get() const { return &value_; } 138 Struct* get() const { return &value_; }
133 139
134 void Swap(InlinedStructPtr* other) { 140 void Swap(InlinedStructPtr* other) {
135 std::swap(value_, other->value_); 141 std::swap(value_, other->value_);
136 std::swap(is_null_, other->is_null_); 142 std::swap(is_null_, other->is_null_);
137 } 143 }
138 144
139 InlinedStructPtr Clone() const { 145 InlinedStructPtr Clone() const {
140 return is_null() ? InlinedStructPtr() : value_.Clone(); 146 return is_null() ? InlinedStructPtr() : value_.Clone();
141 } 147 }
148 bool Equals(const InlinedStructPtr& other) const {
149 if (is_null() || other.is_null())
150 return is_null() && other.is_null();
151 return value_.Equals(other.value_);
152 }
142 153
143 private: 154 private:
144 typedef Struct InlinedStructPtr::*Testable; 155 typedef Struct InlinedStructPtr::*Testable;
145 156
146 public: 157 public:
147 operator Testable() const { return is_null_ ? 0 : &InlinedStructPtr::value_; } 158 operator Testable() const { return is_null_ ? 0 : &InlinedStructPtr::value_; }
148 159
149 private: 160 private:
150 friend class internal::StructHelper<Struct>; 161 friend class internal::StructHelper<Struct>;
151 void Initialize() { is_null_ = false; } 162 void Initialize() { is_null_ = false; }
152 163
153 void Take(InlinedStructPtr* other) { 164 void Take(InlinedStructPtr* other) {
154 reset(); 165 reset();
155 Swap(other); 166 Swap(other);
156 } 167 }
157 168
158 mutable Struct value_; 169 mutable Struct value_;
159 bool is_null_; 170 bool is_null_;
160 }; 171 };
161 172
162 } // namespace mojo 173 } // namespace mojo
163 174
164 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 175 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/map.h ('k') | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698