| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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_ |
| OLD | NEW |