mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
605c6bd031
* Store percents as integer, with 2 digits of precision * Fix GHA builds for Mac (missing pkg-config) * Fix percents formatting
40 lines
730 B
C++
40 lines
730 B
C++
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <string>
|
|
|
|
class Percents
|
|
{
|
|
public:
|
|
Percents() = default;
|
|
|
|
explicit Percents(int value) noexcept
|
|
: raw_value_(value * 100)
|
|
{
|
|
}
|
|
|
|
explicit Percents(float value) noexcept
|
|
: raw_value_(std::round(value * 10000))
|
|
{
|
|
}
|
|
|
|
[[nodiscard]] constexpr int to_int() const noexcept
|
|
{
|
|
return raw_value_ / 100;
|
|
}
|
|
|
|
[[nodiscard]] std::string to_string() const;
|
|
|
|
constexpr bool operator==(Percents const& rhs) const noexcept
|
|
{
|
|
return raw_value_ == rhs.raw_value_;
|
|
}
|
|
|
|
constexpr bool operator<(Percents const& rhs) const noexcept
|
|
{
|
|
return raw_value_ < rhs.raw_value_;
|
|
}
|
|
|
|
private:
|
|
int raw_value_ = 0;
|
|
};
|