1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-03 21:45:49 +00:00
transmission/qt/Speed.h
Charles Kerr 7f147c65fb
refactor: fix more sonarcloud warnings (#1508)
* refactor: const correctness

* refactor: use getpwuid_r instead of getpwuid

* chore: simplify dict walking loop logic

* refactor: remove dead store assignment in announcer

* refactor: use std::make_shared
2020-11-05 16:46:21 -06:00

73 lines
1.3 KiB
C++

/*
* This file Copyright (C) 2009-2015 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#pragma once
class Speed
{
public:
Speed() = default;
double getKBps() const;
[[nodiscard]] int getBps() const
{
return bytes_per_second_;
}
[[nodiscard]] bool isZero() const
{
return bytes_per_second_ == 0;
}
static Speed fromKBps(double KBps);
static Speed fromBps(int Bps)
{
return Speed{ Bps };
}
void setBps(int Bps)
{
bytes_per_second_ = Bps;
}
Speed& operator +=(Speed const& that)
{
bytes_per_second_ += that.bytes_per_second_;
return *this;
}
[[nodiscard]] Speed operator +(Speed const& that) const
{
return Speed{ getBps() + that.getBps() };
}
[[nodiscard]] bool operator <(Speed const& that) const
{
return getBps() < that.getBps();
}
[[nodiscard]] bool operator ==(Speed const& that) const
{
return getBps() == that.getBps();
}
[[nodiscard]] bool operator !=(Speed const& that) const
{
return getBps() != that.getBps();
}
private:
explicit Speed(int bytes_per_second) :
bytes_per_second_{bytes_per_second}
{
}
int bytes_per_second_ = {};
};