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

Side by Side Diff: chromecast/public/time_delta.h

Issue 1257013003: Load CMA backend from shared library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test + android fixes Created 5 years, 4 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
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
gunsch 2015/07/27 17:14:49 no (c)
halliwell 2015/07/28 02:19:36 file removed.
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 CHROMECAST_PUBLIC_TIME_DELTA_H_
6 #define CHROMECAST_PUBLIC_TIME_DELTA_H_
7
8 #include <stdint.h>
9
10 #include <limits>
11
12 namespace chromecast {
13
14 class TimeDelta {
gunsch 2015/07/27 17:14:50 Could we just use |uint64_t microseconds| everywhe
byungchul 2015/07/27 18:22:23 +1
halliwell 2015/07/28 02:19:36 Done.
15 public:
16 TimeDelta() : delta_(0) {}
17
18 // Indicates an invalid or missing timestamp
19 static TimeDelta Invalid() {
20 return TimeDelta(std::numeric_limits<int64_t>::min());
21 }
22 // Maximum possible TimeDelta value
23 static TimeDelta Max() {
24 return TimeDelta(std::numeric_limits<int64_t>::max());
25 }
26
27 // Convert units of time to DeltaDelta
28 static TimeDelta FromMilliseconds(int64_t ms) {
29 if (ms == std::numeric_limits<int64_t>::max())
30 return Max();
31 return TimeDelta(ms * 1000);
32 }
33 static TimeDelta FromMicroseconds(int64_t us) { return TimeDelta(us); }
34
35 // Convert to units of time
36 int64_t InMicroseconds() const { return delta_; }
37 int64_t InMilliseconds() const {
38 if (delta_ == std::numeric_limits<int64_t>::max())
39 return std::numeric_limits<int64_t>::max();
40 return delta_ / 1000;
41 }
42 double InSecondsF() const {
43 if (delta_ == std::numeric_limits<int64_t>::max())
44 return std::numeric_limits<double>::infinity();
45 const int64_t kMicrosecondsPerSecond = 1000000;
46 return static_cast<double>(delta_) / kMicrosecondsPerSecond;
47 }
48
49 // Arithmetic operations. These prevent overflow and clamp to (+max, -max)
50 // when overflow would have occurred.
51 TimeDelta operator+(TimeDelta other) const {
gunsch 2015/07/27 17:14:49 Do we need/use the addition/subtraction operators?
halliwell 2015/07/28 02:19:36 we did use them (and no others, that's why I didn'
52 const int64_t max_int = std::numeric_limits<int64_t>::max();
53 const int64_t min_int = std::numeric_limits<int64_t>::min();
54 if (((other.delta_ > 0) && (delta_ > (max_int - other.delta_))))
55 return TimeDelta(max_int);
56 else if ((other.delta_ < 0) && (delta_ < (min_int - other.delta_)))
57 return TimeDelta(-max_int);
58 else
59 return TimeDelta(delta_ + other.delta_);
60 }
61
62 TimeDelta operator-(TimeDelta other) const {
63 const int64_t max_int = std::numeric_limits<int64_t>::max();
64 const int64_t min_int = std::numeric_limits<int64_t>::min();
65
66 if ((other.delta_ > 0) && (delta_ < (min_int + other.delta_)))
67 return TimeDelta(-max_int);
68 else if ((other.delta_ < 0) && (delta_ > (max_int + other.delta_)))
69 return TimeDelta(max_int);
70 else
71 return TimeDelta(delta_ - other.delta_);
72 }
73
74 // Comparisons
75 bool operator==(const TimeDelta& other) const {
76 return delta_ == other.delta_;
77 }
78 bool operator!=(const TimeDelta& other) const {
79 return delta_ != other.delta_;
80 }
81 bool operator<=(const TimeDelta& other) const {
82 return delta_ <= other.delta_;
83 }
84 bool operator<(const TimeDelta& other) const { return delta_ < other.delta_; }
85 bool operator>=(const TimeDelta& other) const {
86 return delta_ >= other.delta_;
87 }
88 bool operator>(const TimeDelta& other) const { return delta_ > other.delta_; }
89
90 private:
91 explicit TimeDelta(int64_t delta) : delta_(delta) {}
92
93 int64_t delta_;
94 };
95
96 } // namespace chromecast
97
98 #endif // CHROMECAST_PUBLIC_TIME_DELTA_H_
OLDNEW
« chromecast/public/task_runner.h ('K') | « chromecast/public/task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698