| 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 bool | operator< (const AllocationSize &other) const
constexpr bool | operator> (const AllocationSize &other) const
constexpr bool | operator>= (const AllocationSize &other) const
constexpr bool | operator<= (const AllocationSize &other) const
constexpr bool | operator== (const AllocationSize &other) const
constexpr bool | operator!= (const AllocationSize &other) const
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 29 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< 1u >::operator+(), and impeller::AllocationSize< 1u >::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 43 of file allocation_size.h.

44 : 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 55 of file allocation_size.h.

56 : 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 65 of file allocation_size.h.

66 : 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 90 of file allocation_size.h.

90 {
91 return AllocationSize{GetByteSize(), FromBytesTag::kFromBytes};
92 }

## ◆ GetByteSize()

template<size_t Period>

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

Returns
  The byte size.

Definition at line 71 of file allocation_size.h.

71 { return bytes_; }

Referenced by impeller::AllocationSize< 1u >::ConvertTo(), impeller::CreateMappingWithCopy(), impeller::AllocationSize< 1u >::GetSize(), impeller::AllocationSize< 1u >::operator+(), impeller::AllocationSize< 1u >::operator+=(), impeller::AllocationSize< 1u >::operator-(), impeller::AllocationSize< 1u >::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 76 of file allocation_size.h.

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

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 123 of file allocation_size.h.

123 { return bytes_ != 0u; }

## ◆ operator!=()

template<size_t Period>

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

Definition at line 117 of file allocation_size.h.

117 {
118 return bytes_ != other.bytes_;
119 }

## ◆ operator+()

template<size_t Period>

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

Definition at line 127 of file allocation_size.h.

127 {
128 return AllocationSize(bytes_ + other.GetByteSize(),
129 FromBytesTag::kFromBytes);
130 }

## ◆ operator+=()

template<size_t Period>

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

Definition at line 137 of file allocation_size.h.

137 {
138 bytes_ += other.GetByteSize();
139 return *this;
140 }

## ◆ operator-()

template<size_t Period>

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

Definition at line 132 of file allocation_size.h.

132 {
133 return AllocationSize(bytes_ - other.GetByteSize(),
134 FromBytesTag::kFromBytes);
135 }

## ◆ operator-=()

template<size_t Period>

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

Definition at line 142 of file allocation_size.h.

142 {
143 bytes_ -= other.GetByteSize();
144 return *this;
145 }

## ◆ operator<()

template<size_t Period>

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

Definition at line 97 of file allocation_size.h.

97 {
98 return bytes_ < other.bytes_;
99 }

## ◆ operator<=()

template<size_t Period>

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

Definition at line 109 of file allocation_size.h.

109 {
110 return bytes_ <= other.bytes_;
111 }

## ◆ operator==()

template<size_t Period>

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

Definition at line 113 of file allocation_size.h.

113 {
114 return bytes_ == other.bytes_;
115 }

## ◆ operator>()

template<size_t Period>

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

Definition at line 101 of file allocation_size.h.

101 {
102 return bytes_ > other.bytes_;
103 }

## ◆ operator>=()

template<size_t Period>

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

Definition at line 105 of file allocation_size.h.

105 {
106 return bytes_ >= other.bytes_;
107 }

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

- impeller/base/allocation_size.h

impeller::FromBytesTag::kFromBytes
@ kFromBytes
impeller::AllocationSize::GetByteSize
constexpr uint64_t GetByteSize() const
Definition: allocation_size.h:71
impeller::AllocationSize::AllocationSize
constexpr AllocationSize()=default
Create a zero allocation size.