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

Side by Side Diff: mojo/public/cpp/bindings/map.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/lib/template_util.h ('k') | mojo/public/cpp/bindings/struct_ptr.h » ('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_MAP_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "mojo/public/cpp/bindings/lib/map_internal.h" 10 #include "mojo/public/cpp/bindings/lib/map_internal.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Please note that calling this method will fail compilation if the value 110 // Please note that calling this method will fail compilation if the value
111 // type cannot be cloned (which usually means that it is a Mojo handle type or 111 // type cannot be cloned (which usually means that it is a Mojo handle type or
112 // a type contains Mojo handles). 112 // a type contains Mojo handles).
113 Map Clone() const { 113 Map Clone() const {
114 Map result; 114 Map result;
115 result.is_null_ = is_null_; 115 result.is_null_ = is_null_;
116 Traits::Clone(map_, &result.map_); 116 Traits::Clone(map_, &result.map_);
117 return result.Pass(); 117 return result.Pass();
118 } 118 }
119 119
120 bool Equals(const Map& other) const {
121 if (is_null() != other.is_null())
122 return false;
123 if (size() != other.size())
124 return false;
125 auto i = begin();
126 auto j = other.begin();
127 while (i != end()) {
128 if (i.GetKey() != j.GetKey())
129 return false;
130 if (!internal::ValueTraits<Value>::Equals(i.GetValue(), j.GetValue()))
131 return false;
132 ++i;
133 ++j;
134 }
135 return true;
136 }
137
120 class ConstMapIterator { 138 class ConstMapIterator {
121 public: 139 public:
122 ConstMapIterator( 140 ConstMapIterator(
123 const typename std::map<KeyStorageType, 141 const typename std::map<KeyStorageType,
124 ValueStorageType>::const_iterator& it) 142 ValueStorageType>::const_iterator& it)
125 : it_(it) {} 143 : it_(it) {}
126 144
127 KeyConstRefType GetKey() { return Traits::GetKey(it_); } 145 KeyConstRefType GetKey() { return Traits::GetKey(it_); }
128 ValueConstRefType GetValue() { return Traits::GetValue(it_); } 146 ValueConstRefType GetValue() { return Traits::GetValue(it_); }
129 147
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue()))); 216 TypeConverter<STLValue, MojoValue>::Convert(it.GetValue())));
199 } 217 }
200 } 218 }
201 return result; 219 return result;
202 } 220 }
203 }; 221 };
204 222
205 } // namespace mojo 223 } // namespace mojo
206 224
207 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 225 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/template_util.h ('k') | mojo/public/cpp/bindings/struct_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698