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

Unified Diff: mojo/public/cpp/bindings/map.h

Issue 2031823002: Mojo C++ bindings: more consistent Clone() and Equals(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/value_traits.h ('k') | mojo/public/cpp/bindings/tests/equals_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/map.h
diff --git a/mojo/public/cpp/bindings/map.h b/mojo/public/cpp/bindings/map.h
index 4f607009253a580cf638282155c32eb6083d1302..5771a82aac23357a76b06f780d39f5efe694c663 100644
--- a/mojo/public/cpp/bindings/map.h
+++ b/mojo/public/cpp/bindings/map.h
@@ -10,8 +10,11 @@
#include <utility>
#include "base/logging.h"
-#include "mojo/public/cpp/bindings/lib/map_internal.h"
-#include "mojo/public/cpp/bindings/lib/value_traits.h"
+#include "base/move.h"
+#include "mojo/public/cpp/bindings/array.h"
+#include "mojo/public/cpp/bindings/lib/map_data_internal.h"
+#include "mojo/public/cpp/bindings/lib/template_util.h"
+#include "mojo/public/cpp/bindings/type_converter.h"
namespace mojo {
@@ -184,25 +187,26 @@ class Map {
values->Swap(&value_vector);
}
- // Returns a new Map that contains a copy of the contents of this map. If the
- // values are of a type that is designated move-only, they will be cloned
- // using the Clone() method of the type. Please note that calling this method
- // will fail compilation if the value type cannot be cloned (which usually
- // means that it is a Mojo handle type or a type that contains Mojo handles).
+ // Returns a new Map that contains a copy of the contents of this map. If the
+ // key/value type defines a Clone() method, it will be used; otherwise copy
+ // constructor/assignment will be used.
+ //
+ // Please note that calling this method will fail compilation if the key/value
+ // type cannot be cloned (which usually means that it is a Mojo handle type or
+ // a type containing Mojo handles).
Map Clone() const {
Map result;
result.is_null_ = is_null_;
- Traits::Clone(map_, &result.map_);
+ for (auto it = map_.begin(); it != map_.end(); ++it) {
+ result.map_.insert(std::make_pair(internal::Clone(it->first),
+ internal::Clone(it->second)));
+ }
return result;
}
// Indicates whether the contents of this map are equal to those of another
- // Map (including nullness). Keys are compared by the != operator. Values are
- // compared as follows:
- // - Map, Array, Struct, or StructPtr values are compared by their Equals()
- // method.
- // - ScopedHandleBase-derived types are compared by their handles.
- // - Values of other types are compared by their "==" operator.
+ // Map (including nullness). If the key/value type defines an Equals() method,
+ // it will be used; otherwise == operator will be used.
bool Equals(const Map& other) const {
if (is_null() != other.is_null())
return false;
@@ -211,9 +215,9 @@ class Map {
auto i = begin();
auto j = other.begin();
while (i != end()) {
- if (i->first != j->first)
+ if (!internal::Equals(i->first, j->first))
return false;
- if (!internal::ValueTraits<Value>::Equals(i->second, j->second))
+ if (!internal::Equals(i->second, j->second))
return false;
++i;
++j;
@@ -244,11 +248,6 @@ class Map {
operator Testable() const { return is_null_ ? 0 : &Map::map_; }
private:
- using Traits =
- internal::MapCloneTraits<Key,
- Value,
- internal::IsMoveOnlyType<Value>::value>;
-
// Forbid the == and != operators explicitly, otherwise Map will be converted
// to Testable to do == or != comparison.
template <typename T, typename U>
« no previous file with comments | « mojo/public/cpp/bindings/lib/value_traits.h ('k') | mojo/public/cpp/bindings/tests/equals_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698