Flutter Engine
 
Loading...
Searching...
No Matches
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.
 
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.
 
template<size_t OtherPeriod>
constexpr AllocationSize (const AllocationSize< OtherPeriod > &other)
 Create an allocation size from another instance with a different period.
 
constexpr AllocationSize (uint64_t byte_size, FromBytesTag)
 Create an allocation size with the amount directly specified in bytes.
 
constexpr uint64_t GetByteSize () const
 
constexpr double GetSize () const
 
template<class AllocationSize >
constexpr AllocationSize ConvertTo ()
 Convert the allocation size from one unit to another.
 
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 AllocationSizeoperator+= (const AllocationSize &other)
 
constexpr AllocationSizeoperator-= (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
PeriodThe 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 ( )
constexprdefault

◆ 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 ( size)
inlineexplicitconstexpr

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

Parameters
[in]sizeThe 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)
inlineexplicitconstexpr

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

Parameters
[in]otherThe other allocation size.
Template Parameters
OtherPeriodThe 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   
)
inlineconstexpr

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

Parameters
[in]byte_sizeThe byte size.
[in]tagA 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 ( )
inlineconstexpr

Convert the allocation size from one unit to another.

        Conversions are non-truncating.
Template Parameters
AllocationSizeThe allocation size to convert to.
Returns
The new allocation size.

Definition at line 91 of file allocation_size.h.

91 {
93 }
constexpr uint64_t GetByteSize() const
constexpr AllocationSize()=default
Create a zero allocation size.

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

◆ GetByteSize()

◆ GetSize()

template<size_t Period>
constexpr double impeller::AllocationSize< Period >::GetSize ( ) const
inlineconstexpr
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().

◆ operator bool()

template<size_t Period>
constexpr impeller::AllocationSize< Period >::operator bool ( ) const
inlineexplicitconstexpr

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
inlineconstexpr

◆ operator+=()

template<size_t Period>
constexpr AllocationSize & impeller::AllocationSize< Period >::operator+= ( const AllocationSize< Period > &  other)
inlineconstexpr

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
inlineconstexpr

◆ operator-=()

template<size_t Period>
constexpr AllocationSize & impeller::AllocationSize< Period >::operator-= ( const AllocationSize< Period > &  other)
inlineconstexpr

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
constexprdefault

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