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

Side by Side Diff: ui/gfx/range/range.cc

Issue 1671403002: Switch gfx::Range to use uint32_t instead of size_t. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 10 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 | « ui/gfx/range/range.h ('k') | ui/gfx/render_text.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "ui/gfx/range/range.h" 5 #include "ui/gfx/range/range.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/format_macros.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 12
14 namespace gfx { 13 namespace gfx {
15 14
16 Range::Range() 15 Range::Range()
17 : start_(0), 16 : start_(0),
18 end_(0) { 17 end_(0) {
19 } 18 }
20 19
21 Range::Range(size_t start, size_t end) 20 Range::Range(uint32_t start, uint32_t end)
22 : start_(start), 21 : start_(start),
23 end_(end) { 22 end_(end) {
24 } 23 }
25 24
26 Range::Range(size_t position) 25 Range::Range(uint32_t position)
27 : start_(position), 26 : start_(position),
28 end_(position) { 27 end_(position) {
29 } 28 }
30 29
31 // static 30 // static
32 const Range Range::InvalidRange() { 31 const Range Range::InvalidRange() {
33 return Range(std::numeric_limits<size_t>::max()); 32 return Range(std::numeric_limits<uint32_t>::max());
34 } 33 }
35 34
36 bool Range::IsValid() const { 35 bool Range::IsValid() const {
37 return *this != InvalidRange(); 36 return *this != InvalidRange();
38 } 37 }
39 38
40 size_t Range::GetMin() const { 39 uint32_t Range::GetMin() const {
41 return std::min(start(), end()); 40 return std::min(start(), end());
42 } 41 }
43 42
44 size_t Range::GetMax() const { 43 uint32_t Range::GetMax() const {
45 return std::max(start(), end()); 44 return std::max(start(), end());
46 } 45 }
47 46
48 bool Range::operator==(const Range& other) const { 47 bool Range::operator==(const Range& other) const {
49 return start() == other.start() && end() == other.end(); 48 return start() == other.start() && end() == other.end();
50 } 49 }
51 50
52 bool Range::operator!=(const Range& other) const { 51 bool Range::operator!=(const Range& other) const {
53 return !(*this == other); 52 return !(*this == other);
54 } 53 }
55 54
56 bool Range::EqualsIgnoringDirection(const Range& other) const { 55 bool Range::EqualsIgnoringDirection(const Range& other) const {
57 return GetMin() == other.GetMin() && GetMax() == other.GetMax(); 56 return GetMin() == other.GetMin() && GetMax() == other.GetMax();
58 } 57 }
59 58
60 bool Range::Intersects(const Range& range) const { 59 bool Range::Intersects(const Range& range) const {
61 return IsValid() && range.IsValid() && 60 return IsValid() && range.IsValid() &&
62 !(range.GetMax() < GetMin() || range.GetMin() >= GetMax()); 61 !(range.GetMax() < GetMin() || range.GetMin() >= GetMax());
63 } 62 }
64 63
65 bool Range::Contains(const Range& range) const { 64 bool Range::Contains(const Range& range) const {
66 return IsValid() && range.IsValid() && 65 return IsValid() && range.IsValid() &&
67 GetMin() <= range.GetMin() && range.GetMax() <= GetMax(); 66 GetMin() <= range.GetMin() && range.GetMax() <= GetMax();
68 } 67 }
69 68
70 Range Range::Intersect(const Range& range) const { 69 Range Range::Intersect(const Range& range) const {
71 size_t min = std::max(GetMin(), range.GetMin()); 70 uint32_t min = std::max(GetMin(), range.GetMin());
72 size_t max = std::min(GetMax(), range.GetMax()); 71 uint32_t max = std::min(GetMax(), range.GetMax());
73 72
74 if (min >= max) // No intersection. 73 if (min >= max) // No intersection.
75 return InvalidRange(); 74 return InvalidRange();
76 75
77 return Range(min, max); 76 return Range(min, max);
78 } 77 }
79 78
80 std::string Range::ToString() const { 79 std::string Range::ToString() const {
81 return base::StringPrintf("{%" PRIuS ",%" PRIuS "}", start(), end()); 80 return base::StringPrintf("{%d,%d}", start(), end());
82 } 81 }
83 82
84 std::ostream& operator<<(std::ostream& os, const Range& range) { 83 std::ostream& operator<<(std::ostream& os, const Range& range) {
85 return os << range.ToString(); 84 return os << range.ToString();
86 } 85 }
87 86
88 } // namespace gfx 87 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/range/range.h ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698