1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00
transmission/qt/Speed.h
2022-08-08 13:05:39 -05:00

70 lines
1.6 KiB
C++

// This file Copyright © 2009-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
class Speed
{
public:
Speed() = default;
double getKBps() const;
[[nodiscard]] auto constexpr getBps() const noexcept
{
return bytes_per_second_;
}
[[nodiscard]] auto constexpr isZero() const noexcept
{
return bytes_per_second_ == 0;
}
static Speed fromKBps(double KBps);
[[nodiscard]] static constexpr Speed fromBps(int Bps) noexcept
{
return Speed{ Bps };
}
void constexpr setBps(int Bps) noexcept
{
bytes_per_second_ = Bps;
}
constexpr Speed& operator+=(Speed const& that) noexcept
{
bytes_per_second_ += that.bytes_per_second_;
return *this;
}
[[nodiscard]] auto constexpr operator+(Speed const& that) const noexcept
{
return Speed{ getBps() + that.getBps() };
}
[[nodiscard]] auto constexpr operator<(Speed const& that) const noexcept
{
return getBps() < that.getBps();
}
[[nodiscard]] auto constexpr operator==(Speed const& that) const noexcept
{
return getBps() == that.getBps();
}
[[nodiscard]] auto constexpr operator!=(Speed const& that) const noexcept
{
return getBps() != that.getBps();
}
private:
explicit constexpr Speed(int bytes_per_second) noexcept
: bytes_per_second_{ bytes_per_second }
{
}
int bytes_per_second_ = {};
};