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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ 7 8 #include "base/logging.h" 9 10 namespace mojo { 11 namespace test { 12 13 // An implementation of a hypothetical Rect type specifically for consumers in 14 // in Chromium. 15 class RectChromium { 16 public: RectChromium()17 RectChromium() {} RectChromium(const RectChromium & other)18 RectChromium(const RectChromium& other) 19 : x_(other.x_), 20 y_(other.y_), 21 width_(other.width_), 22 height_(other.height_) {} RectChromium(int x,int y,int width,int height)23 RectChromium(int x, int y, int width, int height) : 24 x_(x), y_(y), width_(width), height_(height) { 25 DCHECK_GE(width_, 0); 26 DCHECK_GE(height_, 0); 27 } ~RectChromium()28 ~RectChromium() {} 29 30 RectChromium& operator=(const RectChromium& other) { 31 x_ = other.x_; 32 y_ = other.y_; 33 width_ = other.width_; 34 height_ = other.height_; 35 return *this; 36 } 37 x()38 int x() const { return x_; } set_x(int x)39 void set_x(int x) { x_ = x; } 40 y()41 int y() const { return y_; } set_y(int y)42 void set_y(int y) { y_ = y; } 43 width()44 int width() const { return width_; } set_width(int width)45 void set_width(int width) { 46 DCHECK_GE(width, 0); 47 width_ = width; 48 } 49 height()50 int height() const { return height_; } set_height(int height)51 void set_height(int height) { 52 DCHECK_GE(height, 0); 53 height_ = height; 54 } 55 GetArea()56 int GetArea() const { return width_ * height_; } 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 64 private: 65 int x_ = 0; 66 int y_ = 0; 67 int width_ = 0; 68 int height_ = 0; 69 }; 70 71 } // namespace test 72 } // namespace mojo 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 87 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ 88