2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
class Speed
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2020-05-27 21:53:12 +00:00
|
|
|
Speed() = default;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
double getKBps() const;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] auto constexpr getBps() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return bytes_per_second_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] auto constexpr isZero() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return bytes_per_second_ == 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Speed fromKBps(double KBps);
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] static constexpr Speed fromBps(int Bps) noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return Speed{ Bps };
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
void constexpr setBps(int Bps) noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
bytes_per_second_ = Bps;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
constexpr Speed& operator+=(Speed const& that) noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
bytes_per_second_ += that.bytes_per_second_;
|
2017-04-19 12:04:45 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] auto constexpr operator+(Speed const& that) const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return Speed{ getBps() + that.getBps() };
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] auto constexpr operator<(Speed const& that) const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return getBps() < that.getBps();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] auto constexpr operator==(Speed const& that) const noexcept
|
2020-05-19 23:42:17 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return getBps() == that.getBps();
|
2020-05-19 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] auto constexpr operator!=(Speed const& that) const noexcept
|
2020-05-19 23:42:17 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return getBps() != that.getBps();
|
2020-05-19 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2022-06-13 03:59:30 +00:00
|
|
|
explicit constexpr Speed(int bytes_per_second) noexcept
|
2021-08-15 09:41:48 +00:00
|
|
|
: bytes_per_second_{ bytes_per_second }
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
int bytes_per_second_ = {};
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|