| Flutter Impeller |

Public Member Functions | List of all members
impeller::AllocationSize< Period > Class Template Reference

Represents the size of an allocation in different units. More...

`#include <allocation_size.h>`

## Public Member Functions
constexpr | AllocationSize ()=default
| Create a zero allocation size. More...
template<class T , class = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr | AllocationSize (T size)
| Create an allocation size with the amount in the `Period` number of bytes. More...
template<size_t OtherPeriod>
constexpr | AllocationSize (const AllocationSize< OtherPeriod > &other)
| Create an allocation size from another instance with a different period. More...
constexpr | AllocationSize (uint64_t byte_size, FromBytesTag)
| Create an allocation size with the amount directly specified in bytes. More...
constexpr uint64_t | GetByteSize () const
constexpr double | GetSize () const
template<class AllocationSize >
constexpr AllocationSize | ConvertTo ()
| Convert the allocation size from one unit to another. More...
constexpr auto | operator<=> (const AllocationSize &other) const =default
constexpr | operator bool () const
constexpr AllocationSize | operator+ (const AllocationSize &other) const
constexpr AllocationSize | operator- (const AllocationSize &other) const
constexpr AllocationSize & | operator+= (const AllocationSize &other)
constexpr AllocationSize & | operator-= (const AllocationSize &other)

## Detailed Description

### template<size_t Period>
class impeller::AllocationSize< Period >

Represents the size of an allocation in different units.

            Refer to the typedefs for Bytes, KiloBytes, MegaBytes,
            Gigabytes, KibiBytes, MebiBytes, and GibiBytes below when using.

            Storage and all operations are always on unsigned units of
            bytes.

Template Parameters

  Period | The number of bytes in 1 unit of the allocation size.

Definition at line 30 of file allocation_size.h.

## Constructor & Destructor Documentation

## ◆ AllocationSize() [1/4]

template<size_t Period>

constexpr impeller::AllocationSize< Period >::AllocationSize | ( |  | ) |
| constexpr default

Create a zero allocation size.

Referenced by impeller::AllocationSize< Period >::operator+(), and impeller::AllocationSize< Period >::operator-().

## ◆ AllocationSize() [2/4]

template<size_t Period>
template<class T , class = std::enable_if_t<std::is_arithmetic_v<T>>>

constexpr impeller::AllocationSize< Period >::AllocationSize | ( | T | size | ) |
| inline explicit constexpr

Create an allocation size with the amount in the `Period` number of bytes.

Parameters

  [in] | size | The size in `Period` number of bytes.

Definition at line 44 of file allocation_size.h.

45 : bytes_(std::ceil(size) * Period) {}

## ◆ AllocationSize() [3/4]

template<size_t Period>
template<size_t OtherPeriod>

constexpr impeller::AllocationSize< Period >::AllocationSize | ( | const AllocationSize< OtherPeriod > & | other | ) |
| inline explicit constexpr

Create an allocation size from another instance with a different period.

Parameters

  [in] | other | The other allocation size.

Template Parameters

  OtherPeriod | The period of the other allocation.

Definition at line 56 of file allocation_size.h.

57 : bytes_(other.GetByteSize()) {}

## ◆ AllocationSize() [4/4]

template<size_t Period>

constexpr impeller::AllocationSize< Period >::AllocationSize | ( | uint64_t | byte_size,
|  | FromBytesTag |
| ) |  |
| inline constexpr

Create an allocation size with the amount directly specified in bytes.

Parameters

  [in] | byte_size | The byte size.
  [in] | tag | A tag for this constructor.

Definition at line 66 of file allocation_size.h.

67 : bytes_(byte_size) {}

## Member Function Documentation

## ◆ ConvertTo()

template<size_t Period>
template<class AllocationSize >

constexpr AllocationSize impeller::AllocationSize< Period >::ConvertTo | ( |  | ) |
| inline constexpr

Convert the allocation size from one unit to another.

            Conversions are non-truncating.

Template Parameters

  AllocationSize | The allocation size to convert to.

Returns
  The new allocation size.

Definition at line 91 of file allocation_size.h.

91 {
92 return AllocationSize{GetByteSize(), FromBytesTag::kFromBytes};
93 }
impeller::AllocationSize::GetByteSize
constexpr uint64_t GetByteSize() const
Definition: allocation_size.h:72
impeller::AllocationSize::AllocationSize
constexpr AllocationSize()=default
Create a zero allocation size.
impeller::FromBytesTag::kFromBytes
@ kFromBytes

References impeller::AllocationSize< Period >::GetByteSize(), and impeller::kFromBytes.

## ◆ GetByteSize()

template<size_t Period>

constexpr uint64_t impeller::AllocationSize< Period >::GetByteSize | ( |  | ) | const
| inline constexpr

Returns
  The byte size.

Definition at line 72 of file allocation_size.h.

72 { return bytes_; }

Referenced by impeller::AllocationSize< Period >::ConvertTo(), impeller::CreateMappingWithCopy(), impeller::AllocationSize< Period >::GetSize(), impeller::AllocationSize< Period >::operator+(), impeller::AllocationSize< Period >::operator+=(), impeller::AllocationSize< Period >::operator-(), impeller::AllocationSize< Period >::operator-=(), and impeller::testing::TEST().

## ◆ GetSize()

template<size_t Period>

constexpr double impeller::AllocationSize< Period >::GetSize | ( |  | ) | const
| inline constexpr

Returns
  The number of `Periods` of bytes.

Definition at line 77 of file allocation_size.h.

77 {
78 return GetByteSize() / static_cast<double>(Period);
79 }

References impeller::AllocationSize< Period >::GetByteSize().

Referenced by impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ operator bool()

template<size_t Period>

constexpr impeller::AllocationSize< Period >::operator bool | ( |  | ) | const
| inline explicit constexpr

Definition at line 101 of file allocation_size.h.

101 { return bytes_ != 0u; }

## ◆ operator+()

template<size_t Period>

constexpr AllocationSize impeller::AllocationSize< Period >::operator+ | ( | const AllocationSize< Period > & | other | ) | const
| inline constexpr

Definition at line 105 of file allocation_size.h.

105 {
106 return AllocationSize(bytes_ + other.GetByteSize(),
107 FromBytesTag::kFromBytes);
108 }

References impeller::AllocationSize< Period >::AllocationSize(), impeller::AllocationSize< Period >::GetByteSize(), and impeller::kFromBytes.

## ◆ operator+=()

template<size_t Period>

constexpr AllocationSize& impeller::AllocationSize< Period >::operator+= | ( | const AllocationSize< Period > & | other | ) |
| inline constexpr

Definition at line 115 of file allocation_size.h.

115 {
116 bytes_ += other.GetByteSize();
117 return *this;
118 }

References impeller::AllocationSize< Period >::GetByteSize().

## ◆ operator-()

template<size_t Period>

constexpr AllocationSize impeller::AllocationSize< Period >::operator- | ( | const AllocationSize< Period > & | other | ) | const
| inline constexpr

Definition at line 110 of file allocation_size.h.

110 {
111 return AllocationSize(bytes_ - other.GetByteSize(),
112 FromBytesTag::kFromBytes);
113 }

References impeller::AllocationSize< Period >::AllocationSize(), impeller::AllocationSize< Period >::GetByteSize(), and impeller::kFromBytes.

## ◆ operator-=()

template<size_t Period>

constexpr AllocationSize& impeller::AllocationSize< Period >::operator-= | ( | const AllocationSize< Period > & | other | ) |
| inline constexpr

Definition at line 120 of file allocation_size.h.

120 {
121 bytes_ -= other.GetByteSize();
122 return *this;
123 }

References impeller::AllocationSize< Period >::GetByteSize().

## ◆ operator<=>()

template<size_t Period>

constexpr auto impeller::AllocationSize< Period >::operator<=> | ( | const AllocationSize< Period > & | other | ) | const
| constexpr default

The documentation for this class was generated from the following file:

- impeller/base/allocation_size.h