2018-04-13 13:56:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-05-08 10:43:18 +02:00
|
|
|
#ifndef API_UNITS_DATA_SIZE_H_
|
|
|
|
|
#define API_UNITS_DATA_SIZE_H_
|
2018-04-13 13:56:17 +02:00
|
|
|
|
2024-08-14 07:29:04 -07:00
|
|
|
#include <cstdint>
|
2018-04-13 13:56:17 +02:00
|
|
|
#include <string>
|
2018-05-30 15:47:44 +02:00
|
|
|
#include <type_traits>
|
2018-04-13 13:56:17 +02:00
|
|
|
|
2024-10-03 11:45:27 +02:00
|
|
|
#include "rtc_base/system/rtc_export.h"
|
2022-10-31 15:16:50 +01:00
|
|
|
#include "rtc_base/units/unit_base.h" // IWYU pragma: export
|
2018-04-13 13:56:17 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2018-04-30 16:54:57 +02:00
|
|
|
// DataSize is a class represeting a count of bytes.
|
2018-11-19 11:17:12 +01:00
|
|
|
class DataSize final : public rtc_units_impl::RelativeUnit<DataSize> {
|
2018-04-13 13:56:17 +02:00
|
|
|
public:
|
2020-02-17 15:00:07 +01:00
|
|
|
template <typename T>
|
|
|
|
|
static constexpr DataSize Bytes(T value) {
|
|
|
|
|
static_assert(std::is_arithmetic<T>::value, "");
|
|
|
|
|
return FromValue(value);
|
|
|
|
|
}
|
2018-11-19 11:17:12 +01:00
|
|
|
static constexpr DataSize Infinity() { return PlusInfinity(); }
|
2020-02-17 15:00:07 +01:00
|
|
|
|
2024-11-26 16:51:18 +01:00
|
|
|
constexpr DataSize() = default;
|
2018-05-30 15:47:44 +02:00
|
|
|
|
2024-10-03 11:45:27 +02:00
|
|
|
template <typename Sink>
|
|
|
|
|
friend void AbslStringify(Sink& sink, DataSize value);
|
|
|
|
|
|
2018-05-30 15:47:44 +02:00
|
|
|
template <typename T = int64_t>
|
2020-01-29 10:44:51 +01:00
|
|
|
constexpr T bytes() const {
|
2018-11-19 11:17:12 +01:00
|
|
|
return ToValue<T>();
|
2018-08-07 15:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr int64_t bytes_or(int64_t fallback_value) const {
|
2018-11-19 11:17:12 +01:00
|
|
|
return ToValueOr(fallback_value);
|
2018-08-07 15:29:04 +02:00
|
|
|
}
|
2018-04-13 13:56:17 +02:00
|
|
|
|
|
|
|
|
private:
|
2018-11-19 11:17:12 +01:00
|
|
|
friend class rtc_units_impl::UnitBase<DataSize>;
|
|
|
|
|
using RelativeUnit::RelativeUnit;
|
|
|
|
|
static constexpr bool one_sided = true;
|
2018-04-13 13:56:17 +02:00
|
|
|
};
|
2018-05-30 15:47:44 +02:00
|
|
|
|
2024-10-03 11:45:27 +02:00
|
|
|
RTC_EXPORT std::string ToString(DataSize value);
|
2018-04-13 13:56:17 +02:00
|
|
|
|
2024-10-03 11:45:27 +02:00
|
|
|
template <typename Sink>
|
|
|
|
|
void AbslStringify(Sink& sink, DataSize value) {
|
|
|
|
|
sink.Append(ToString(value));
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 13:56:17 +02:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2018-05-08 10:43:18 +02:00
|
|
|
#endif // API_UNITS_DATA_SIZE_H_
|