5 #ifndef FLUTTER_IMPELLER_BASE_ALLOCATION_SIZE_H_
6 #define FLUTTER_IMPELLER_BASE_ALLOCATION_SIZE_H_
11 #include <type_traits>
28 template <
size_t Period>
42 template <
class T,
class = std::enable_if_t<std::is_arithmetic_v<T>>>
44 : bytes_(
std::ceil(size) * Period) {}
54 template <
size_t OtherPeriod>
66 : bytes_(byte_size) {}
89 template <
class AllocationSize>
98 return bytes_ < other.bytes_;
102 return bytes_ > other.bytes_;
106 return bytes_ >= other.bytes_;
110 return bytes_ <= other.bytes_;
114 return bytes_ == other.bytes_;
118 return bytes_ != other.bytes_;
123 explicit constexpr
operator bool()
const {
return bytes_ != 0u; }
148 uint64_t bytes_ = {};
161 inline namespace allocation_size_literals {
164 constexpr
Bytes operator"" _bytes(
unsigned long long int size) {
169 constexpr
KiloBytes operator"" _kb(
unsigned long long int size) {
174 constexpr
MegaBytes operator"" _mb(
unsigned long long int size) {
179 constexpr
GigaBytes operator"" _gb(
unsigned long long int size) {
184 constexpr
KibiBytes operator"" _kib(
unsigned long long int size) {
189 constexpr
MebiBytes operator"" _mib(
unsigned long long int size) {
194 constexpr
GibiBytes operator"" _gib(
unsigned long long int size) {
Represents the size of an allocation in different units.
constexpr AllocationSize(uint64_t byte_size, FromBytesTag)
Create an allocation size with the amount directly specified in bytes.
constexpr bool operator<=(const AllocationSize &other) const
constexpr double GetSize() const
constexpr AllocationSize ConvertTo()
Convert the allocation size from one unit to another.
constexpr bool operator==(const AllocationSize &other) const
constexpr AllocationSize operator-(const AllocationSize &other) const
constexpr uint64_t GetByteSize() const
constexpr AllocationSize operator+(const AllocationSize &other) const
constexpr bool operator<(const AllocationSize &other) const
constexpr AllocationSize & operator-=(const AllocationSize &other)
constexpr AllocationSize(T size)
Create an allocation size with the amount in the Period number of bytes.
constexpr AllocationSize()=default
Create a zero allocation size.
constexpr AllocationSize & operator+=(const AllocationSize &other)
constexpr bool operator>(const AllocationSize &other) const
constexpr AllocationSize(const AllocationSize< OtherPeriod > &other)
Create an allocation size from another instance with a different period.
constexpr bool operator>=(const AllocationSize &other) const
constexpr bool operator!=(const AllocationSize &other) const