Flutter Impeller
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 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 29 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 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)
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 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   
)
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 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 ( )
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 90 of file allocation_size.h.

90  {
92  }
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 76 of file allocation_size.h.

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

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
inlineexplicitconstexpr

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
inlineconstexpr

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
inlineconstexpr

Definition at line 127 of file allocation_size.h.

127  {
128  return AllocationSize(bytes_ + other.GetByteSize(),
130  }

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)
inlineconstexpr

Definition at line 137 of file allocation_size.h.

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

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

◆ operator-()

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

Definition at line 132 of file allocation_size.h.

132  {
133  return AllocationSize(bytes_ - other.GetByteSize(),
135  }

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)
inlineconstexpr

Definition at line 142 of file allocation_size.h.

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

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

◆ operator<()

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

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
inlineconstexpr

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
inlineconstexpr

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
inlineconstexpr

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
inlineconstexpr

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: