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

Side by Side Diff: mojo/public/cpp/bindings/tests/rect_chromium.h

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Fix hash unit test on Windows Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_TESTS_RECT_CHROMIUM_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace mojo { 10 namespace mojo {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 int height() const { return height_; } 50 int height() const { return height_; }
51 void set_height(int height) { 51 void set_height(int height) {
52 DCHECK_GE(height, 0); 52 DCHECK_GE(height, 0);
53 height_ = height; 53 height_ = height;
54 } 54 }
55 55
56 int GetArea() const { return width_ * height_; } 56 int GetArea() const { return width_ * height_; }
57 57
58 bool operator==(const RectChromium& other) const {
59 return (x() == other.x() && y() == other.y() && width() == other.width() &&
60 height() == other.height());
61 }
62 bool operator!=(const RectChromium& other) const { return !(*this == other); }
63
58 private: 64 private:
59 int x_ = 0; 65 int x_ = 0;
60 int y_ = 0; 66 int y_ = 0;
61 int width_ = 0; 67 int width_ = 0;
62 int height_ = 0; 68 int height_ = 0;
63 }; 69 };
64 70
65 } // namespace test 71 } // namespace test
66 } // namespace mojo 72 } // namespace mojo
67 73
74 namespace std {
75
76 template <>
77 struct hash<mojo::test::RectChromium> {
78 size_t operator()(const mojo::test::RectChromium& value) {
79 // Terrible hash function:
80 return (std::hash<int>()(value.x()) ^ std::hash<int>()(value.y()) ^
81 std::hash<int>()(value.width()) ^ std::hash<int>()(value.height()));
82 }
83 };
84
85 } // namespace std
86
68 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ 87 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/rect_blink.typemap ('k') | mojo/public/cpp/bindings/tests/rect_chromium.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698