2022-01-20 12:27:56 -06:00
|
|
|
// This file Copyright © 2009-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// 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 15:04:45 +03:00
|
|
|
public:
|
2020-05-27 16:53:12 -05:00
|
|
|
Speed() = default;
|
2017-04-19 15:04:45 +03:00
|
|
|
|
2020-06-05 14:02:11 -05:00
|
|
|
double getKBps() const;
|
2017-04-19 15:04:45 +03:00
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] auto constexpr getBps() const noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return bytes_per_second_;
|
2017-04-19 15:04:45 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] auto constexpr isZero() const noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return bytes_per_second_ == 0;
|
2017-04-19 15:04:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Speed fromKBps(double KBps);
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] static constexpr Speed fromBps(int Bps) noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return Speed{ Bps };
|
2017-04-19 15:04:45 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
void constexpr setBps(int Bps) noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
bytes_per_second_ = Bps;
|
2017-04-19 15:04:45 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
constexpr Speed& operator+=(Speed const& that) noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
bytes_per_second_ += that.bytes_per_second_;
|
2017-04-19 15:04:45 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] auto constexpr operator+(Speed const& that) const noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return Speed{ getBps() + that.getBps() };
|
2017-04-19 15:04:45 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] auto constexpr operator<(Speed const& that) const noexcept
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return getBps() < that.getBps();
|
2017-04-19 15:04:45 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] auto constexpr operator==(Speed const& that) const noexcept
|
2020-05-19 18:42:17 -05:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return getBps() == that.getBps();
|
2020-05-19 18:42:17 -05:00
|
|
|
}
|
|
|
|
|
2022-06-12 22:59:30 -05:00
|
|
|
[[nodiscard]] auto constexpr operator!=(Speed const& that) const noexcept
|
2020-05-19 18:42:17 -05:00
|
|
|
{
|
2020-06-05 14:02:11 -05:00
|
|
|
return getBps() != that.getBps();
|
2020-05-19 18:42:17 -05:00
|
|
|
}
|
|
|
|
|
2017-04-19 15:04:45 +03:00
|
|
|
private:
|
2022-06-12 22:59:30 -05:00
|
|
|
explicit constexpr Speed(int bytes_per_second) noexcept
|
2021-08-15 12:41:48 +03:00
|
|
|
: bytes_per_second_{ bytes_per_second }
|
2017-04-19 15:04:45 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-05 14:02:11 -05:00
|
|
|
int bytes_per_second_ = {};
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|