5 #ifndef FLUTTER_IMPELLER_BASE_ALLOCATION_SIZE_H_
6 #define FLUTTER_IMPELLER_BASE_ALLOCATION_SIZE_H_
12 #include <type_traits>
29 template <
size_t Period>
43 template <
class T,
class = std::enable_if_t<std::is_arithmetic_v<T>>>
45 : bytes_(
std::ceil(size) * Period) {}
55 template <
size_t OtherPeriod>
67 : bytes_(byte_size) {}
90 template <
class AllocationSize>
101 explicit constexpr
operator bool()
const {
return bytes_ != 0u; }
126 uint64_t bytes_ = {};
139 inline namespace allocation_size_literals {
142 constexpr
Bytes operator""_bytes(
unsigned long long int size) {
147 constexpr
KiloBytes operator""_kb(
unsigned long long int size) {
152 constexpr
MegaBytes operator""_mb(
unsigned long long int size) {
157 constexpr
GigaBytes operator""_gb(
unsigned long long int size) {
162 constexpr
KibiBytes operator""_kib(
unsigned long long int size) {
167 constexpr
MebiBytes operator""_mib(
unsigned long long int size) {
172 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 double GetSize() const
constexpr AllocationSize ConvertTo()
Convert the allocation size from one unit to another.
constexpr AllocationSize operator-(const AllocationSize &other) const
constexpr uint64_t GetByteSize() const
constexpr AllocationSize 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 AllocationSize(const AllocationSize< OtherPeriod > &other)
Create an allocation size from another instance with a different period.
constexpr auto operator<=>(const AllocationSize &other) const =default