Chromium Code Reviews| Index: webrtc/rtc_base/time_interval.h |
| diff --git a/webrtc/rtc_base/time_interval.h b/webrtc/rtc_base/time_interval.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb6f36f7b948d4b9645b0fe921184ba2a14803bd |
| --- /dev/null |
| +++ b/webrtc/rtc_base/time_interval.h |
| @@ -0,0 +1,64 @@ |
| +/* |
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_RTC_BASE_TIME_INTERVAL_H_ |
|
ossu
2017/07/14 11:13:15
I'm not sure if this class belongs in rtc_base jus
saza WebRTC
2017/07/17 14:27:29
Done.
|
| +#define WEBRTC_RTC_BASE_TIME_INTERVAL_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include "webrtc/rtc_base/optional.h" |
| + |
| +namespace rtc { |
| + |
| +// This class logs the first and last time its Extend() function is called. |
| +// Extend(...) takes arbitrary times. |
| +// |
| +// This class is not thread-safe; Extend() should only be used when only one |
| +// thread may access it, such as within a lock or destructor. |
| +// |
| +// Example usage: |
| +// // let x < y < z < u < v |
| +// rtc::TimeInterval interval; |
| +// ... // interval.Extend(); // at time x |
| +// ... |
| +// interval.Extend(); // at time y |
| +// ... |
| +// interval.Extend(); // at time u |
| +// ... |
| +// interval.Extend(z); // at time v |
| +// ... |
| +// rtc::Optional<int64_t> first = interval.First(); |
| +// rtc::Optional<int64_t> last = interval.Last(); |
| +// if (first) { |
| +// int64_t active_time = *last - *first; // returns (u - x) |
| +// } |
| +class TimeInterval { |
| + public: |
| + TimeInterval(); |
| + ~TimeInterval(); |
| + // Extend the interval with the current time. |
| + void Extend(); |
| + // Extend the interval with a given time. |
| + void Extend(int64_t time); |
|
pbos-webrtc
2017/07/14 17:04:01
Should Extend not be able to take another time int
saza WebRTC
2017/07/17 14:27:29
Done.
|
| + // True iff Extend has never been called. |
| + bool Empty() const; |
| + // Returns the time of the first tick in milliseconds. |
| + Optional<int64_t> First() const; |
| + // Returns the time of the last tick in milliseconds. |
| + Optional<int64_t> Last() const; |
| + |
| + private: |
| + Optional<int64_t> first_; |
| + Optional<int64_t> last_; |
| +}; |
| + |
| +} // namespace rtc |
| + |
| +#endif // WEBRTC_RTC_BASE_TIME_INTERVAL_H_ |