StormByte 2.0.0
C++26 foundation of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::ByteSize Class Referencefinal

Count of octets (uint64_t storage). More...

#include <StormByte/byte_size.hxx>

Collaboration diagram for StormByte::ByteSize:

Classes

struct  Unit
 One-octet scale used by the named factories. More...
 

Public Member Functions

constexpr ByteSize () noexcept
 Zero octets.
 
template<Type::Integral T>
constexpr ByteSize (T value) noexcept
 From an integer octet count.
 
constexpr ByteSize (Size count) noexcept
 From an abstract unit count interpreted as octets.
 
constexpr ByteSize (const ByteSize &other) noexcept=default
 Copy constructor.
 
constexpr ByteSize (ByteSize &&other) noexcept=default
 Move constructor.
 
constexpr ~ByteSize () noexcept=default
 Destructor.
 
constexpr ByteSize & operator= (const ByteSize &other) noexcept=default
 Copy assignment.
 
constexpr ByteSize & operator= (ByteSize &&other) noexcept=default
 Move assignment.
 
template<Type::Integral T>
constexpr ByteSize & operator= (T value) noexcept
 Assign an integer octet count.
 
constexpr operator std::size_t () const noexcept
 Implicit host size_t (clamped).
 
template<Type::Integral T>
requires (!Type::SameAs<T, std::size_t>)
constexpr operator T () const noexcept
 Explicit conversion to an integral other than std::size_t.
 
 operator CString () const noexcept
 IEC human-readable text owned by Base.
 
 operator WCString () const noexcept
 IEC human-readable wide text owned by Base.
 
STORMBYTE_FORCE_INLINE operator std::string () const
 IEC human-readable text on the caller heap.
 
constexpr ByteSize & operator++ () noexcept
 Prefix increment.
 
constexpr ByteSize operator++ (int) noexcept
 Postfix increment.
 
constexpr ByteSize & operator-- () noexcept
 Prefix decrement.
 
constexpr ByteSize operator-- (int) noexcept
 Postfix decrement.
 
ByteSize operator* (ByteSize) const =delete
 
ByteSize & operator*= (ByteSize)=delete
 
ByteSize operator/ (ByteSize) const =delete
 
ByteSize & operator/= (ByteSize)=delete
 
ByteSize operator% (ByteSize) const =delete
 
ByteSize & operator%= (ByteSize)=delete
 
constexpr ByteSize & operator+= (ByteSize other) noexcept
 Add other octets.
 
constexpr ByteSize & operator-= (ByteSize other) noexcept
 Subtract other octets.
 
constexpr ByteSize & operator*= (Size other) noexcept
 Scale by a unit count.
 
constexpr ByteSize & operator/= (Size other) noexcept
 Divide by a unit count.
 
constexpr ByteSize & operator%= (Size other) noexcept
 Remainder with a unit count.
 
template<Type::Integral T>
constexpr ByteSize & operator+= (T value) noexcept
 Add an integer octet count.
 
template<Type::Integral T>
constexpr ByteSize & operator-= (T value) noexcept
 Subtract an integer octet count.
 
template<Type::Integral T>
constexpr ByteSize & operator*= (T value) noexcept
 Scale by an integer.
 
template<Type::Integral T>
constexpr ByteSize & operator/= (T value) noexcept
 Divide by an integer.
 
template<Type::Integral T>
constexpr ByteSize & operator%= (T value) noexcept
 Remainder with an integer.
 

Static Public Attributes

static constexpr Unit B {1ull}
 2^0 octets
 
static constexpr Unit KiB {1024ull}
 2^10 octets
 
static constexpr Unit MiB {1024ull * 1024}
 2^20 octets
 
static constexpr Unit GiB {1024ull * 1024 * 1024}
 2^30 octets
 
static constexpr Unit TiB {1024ull * 1024 * 1024 * 1024}
 2^40 octets
 
static constexpr Unit PiB {1024ull * 1024 * 1024 * 1024 * 1024}
 2^50 octets
 
static constexpr Unit EiB {1024ull * 1024 * 1024 * 1024 * 1024 * 1024}
 2^60 octets
 
static constexpr Unit KB {1000ull}
 10^3 octets
 
static constexpr Unit MB {1000ull * 1000}
 10^6 octets
 
static constexpr Unit GB {1000ull * 1000 * 1000}
 10^9 octets
 
static constexpr Unit TB {1000ull * 1000 * 1000 * 1000}
 10^12 octets
 
static constexpr Unit PB {1000ull * 1000 * 1000 * 1000 * 1000}
 10^15 octets
 
static constexpr Unit EB {1000ull * 1000 * 1000 * 1000 * 1000 * 1000}
 10^18 octets
 

Friends

constexpr bool operator== (ByteSize lhs, ByteSize rhs) noexcept
 Numeric equality.
 
template<Type::Integral T>
constexpr bool operator== (ByteSize lhs, T rhs) noexcept
 Mixed equality with an integer.
 
template<Type::Integral T>
constexpr bool operator== (T lhs, ByteSize rhs) noexcept
 Mixed equality with an integer.
 
constexpr bool operator== (ByteSize lhs, Size rhs) noexcept
 Mixed equality with Size.
 
constexpr bool operator== (Size lhs, ByteSize rhs) noexcept
 Mixed equality with Size.
 
constexpr std::strong_ordering operator<=> (ByteSize lhs, ByteSize rhs) noexcept
 Numeric order.
 
template<Type::Integral T>
constexpr std::strong_ordering operator<=> (ByteSize lhs, T rhs) noexcept
 Mixed order with an integer.
 
template<Type::Integral T>
constexpr std::strong_ordering operator<=> (T lhs, ByteSize rhs) noexcept
 Mixed order with an integer.
 
constexpr std::strong_ordering operator<=> (ByteSize lhs, Size rhs) noexcept
 Mixed order with Size.
 
constexpr std::strong_ordering operator<=> (Size lhs, ByteSize rhs) noexcept
 Mixed order with Size.
 
constexpr ByteSize operator+ (ByteSize lhs, ByteSize rhs) noexcept
 Sum of lengths.
 
constexpr ByteSize operator- (ByteSize lhs, ByteSize rhs) noexcept
 Difference of lengths.
 
constexpr ByteSize operator* (ByteSize lhs, Size rhs) noexcept
 Scale by a unit count.
 
constexpr ByteSize operator* (Size lhs, ByteSize rhs) noexcept
 Scale by a unit count.
 
constexpr ByteSize operator/ (ByteSize lhs, Size rhs) noexcept
 Divide by a unit count.
 
constexpr ByteSize operator% (ByteSize lhs, Size rhs) noexcept
 Remainder with a unit count.
 
template<Type::Integral T>
constexpr ByteSize operator+ (ByteSize lhs, T rhs) noexcept
 Mixed sum.
 
template<Type::Integral T>
constexpr ByteSize operator+ (T lhs, ByteSize rhs) noexcept
 Mixed sum.
 
template<Type::Integral T>
constexpr ByteSize operator- (ByteSize lhs, T rhs) noexcept
 Mixed difference.
 
template<Type::Integral T>
constexpr ByteSize operator- (T lhs, ByteSize rhs) noexcept
 Mixed difference.
 
template<Type::Integral T>
constexpr ByteSize operator* (ByteSize lhs, T rhs) noexcept
 Mixed product.
 
template<Type::Integral T>
constexpr ByteSize operator* (T lhs, ByteSize rhs) noexcept
 Mixed product.
 
template<Type::Integral T>
constexpr ByteSize operator/ (ByteSize lhs, T rhs) noexcept
 Mixed quotient.
 
template<Type::Integral T>
constexpr ByteSize operator% (ByteSize lhs, T rhs) noexcept
 Mixed remainder.
 

Detailed Description

Count of octets (uint64_t storage).

This is the byte-length type. Size is an abstract unit count. The value that crosses a DLL is always 64-bit unsigned.

Implicit conversion exists only to std::size_t (clamp to size_t::max). Every other integral destination is explicit and clamps to T::max. There is no operator bool and no Value().

On hosts where std::size_t is unsigned long or unsigned long long, that conversion is the implicit operator std::size_t. Those two names are not given a second extern template of operator T().

Area products (ByteSize * ByteSize) are deleted. Scaling by Size or by an integer is allowed and yields ByteSize.

Mixed comparison with any Type::Integral is a hidden friend so n == 5, 5u == n and ASSERT_EQUAL are not ambiguous with the built-in candidates. Comparison with Size is also a hidden friend and compares the numeric counts.

1 * KiB uses the free StormByte::KiB constant (a ByteSize of 1024 octets). ByteSize::KiB(n) is the same scale via Unit.

Overflow of uint64_t and a negative result: assert when assertions are on; wrap modulo 2⁶⁴ when they are not. Division by zero: assert when assertions are on; undefined otherwise.

operator CString / operator WCString print an IEC human-readable length (1.50 KiB). B/KiB/MiB/GiB/TiB/PiB/EiB are IEC. KB/MB/GB/TB/PB/EB are SI (10³).

Constructor & Destructor Documentation

◆ ByteSize() [1/5]

constexpr StormByte::ByteSize::ByteSize ( )
inlineconstexprnoexcept

Zero octets.

◆ ByteSize() [2/5]

template<Type::Integral T>
constexpr StormByte::ByteSize::ByteSize ( T  value)
inlineconstexprnoexcept

From an integer octet count.

Template Parameters
TIntegral type.
Parameters
valueOctets. Negative is undefined (assert when on).

◆ ByteSize() [3/5]

constexpr StormByte::ByteSize::ByteSize ( Size  count)
inlineexplicitconstexprnoexcept

From an abstract unit count interpreted as octets.

Parameters
countUnit count used as an octet count.

◆ ByteSize() [4/5]

constexpr StormByte::ByteSize::ByteSize ( const ByteSize &  other)
constexprdefaultnoexcept

Copy constructor.

Parameters
otherLength to copy.

◆ ByteSize() [5/5]

constexpr StormByte::ByteSize::ByteSize ( ByteSize &&  other)
constexprdefaultnoexcept

Move constructor.

Parameters
otherLength to take.

◆ ~ByteSize()

constexpr StormByte::ByteSize::~ByteSize ( )
constexprdefaultnoexcept

Destructor.

Member Function Documentation

◆ operator CString()

StormByte::ByteSize::operator CString ( ) const
explicitnoexcept

IEC human-readable text owned by Base.

Returns
Formatted length.

◆ operator std::size_t()

constexpr StormByte::ByteSize::operator std::size_t ( ) const
inlineconstexprnoexcept

Implicit host size_t (clamped).

Returns
Octets as std::size_t.

◆ operator std::string()

STORMBYTE_FORCE_INLINE StormByte::ByteSize::operator std::string ( ) const
inline

IEC human-readable text on the caller heap.

Returns
Formatted length.

◆ operator T()

template<Type::Integral T>
requires (!Type::SameAs<T, std::size_t>)
constexpr StormByte::ByteSize::operator T ( ) const
inlineexplicitconstexprnoexcept

Explicit conversion to an integral other than std::size_t.

Template Parameters
TIntegral type, not std::size_t.
Returns
Octets clamped to std::numeric_limits<T>::max().

◆ operator WCString()

StormByte::ByteSize::operator WCString ( ) const
explicitnoexcept

IEC human-readable wide text owned by Base.

Returns
Formatted length.

◆ operator%()

ByteSize StormByte::ByteSize::operator% ( ByteSize  ) const
delete

◆ operator%=() [1/3]

ByteSize & StormByte::ByteSize::operator%= ( ByteSize  )
delete

◆ operator%=() [2/3]

constexpr ByteSize & StormByte::ByteSize::operator%= ( Size  other)
inlineconstexprnoexcept

Remainder with a unit count.

Parameters
otherDivisor.
Returns
*this.

◆ operator%=() [3/3]

template<Type::Integral T>
constexpr ByteSize & StormByte::ByteSize::operator%= ( T  value)
inlineconstexprnoexcept

Remainder with an integer.

Template Parameters
TIntegral type.
Parameters
valueDivisor.
Returns
*this.

◆ operator*()

ByteSize StormByte::ByteSize::operator* ( ByteSize  ) const
delete

◆ operator*=() [1/3]

ByteSize & StormByte::ByteSize::operator*= ( ByteSize  )
delete

◆ operator*=() [2/3]

constexpr ByteSize & StormByte::ByteSize::operator*= ( Size  other)
inlineconstexprnoexcept

Scale by a unit count.

Parameters
otherFactor.
Returns
*this.

◆ operator*=() [3/3]

template<Type::Integral T>
constexpr ByteSize & StormByte::ByteSize::operator*= ( T  value)
inlineconstexprnoexcept

Scale by an integer.

Template Parameters
TIntegral type.
Parameters
valueFactor.
Returns
*this.

◆ operator++() [1/2]

constexpr ByteSize & StormByte::ByteSize::operator++ ( )
inlineconstexprnoexcept

Prefix increment.

Returns
*this after adding one octet.

◆ operator++() [2/2]

constexpr ByteSize StormByte::ByteSize::operator++ ( int  )
inlineconstexprnoexcept

Postfix increment.

Returns
Copy before adding one octet.

◆ operator+=() [1/2]

constexpr ByteSize & StormByte::ByteSize::operator+= ( ByteSize  other)
inlineconstexprnoexcept

Add other octets.

Parameters
otherAddend.
Returns
*this.

◆ operator+=() [2/2]

template<Type::Integral T>
constexpr ByteSize & StormByte::ByteSize::operator+= ( T  value)
inlineconstexprnoexcept

Add an integer octet count.

Template Parameters
TIntegral type.
Parameters
valueAddend.
Returns
*this.

◆ operator--() [1/2]

constexpr ByteSize & StormByte::ByteSize::operator-- ( )
inlineconstexprnoexcept

Prefix decrement.

Returns
*this after subtracting one octet.

◆ operator--() [2/2]

constexpr ByteSize StormByte::ByteSize::operator-- ( int  )
inlineconstexprnoexcept

Postfix decrement.

Returns
Copy before subtracting one octet.

◆ operator-=() [1/2]

constexpr ByteSize & StormByte::ByteSize::operator-= ( ByteSize  other)
inlineconstexprnoexcept

Subtract other octets.

Parameters
otherSubtrahend.
Returns
*this.

◆ operator-=() [2/2]

template<Type::Integral T>
constexpr ByteSize & StormByte::ByteSize::operator-= ( T  value)
inlineconstexprnoexcept

Subtract an integer octet count.

Template Parameters
TIntegral type.
Parameters
valueSubtrahend.
Returns
*this.

◆ operator/()

ByteSize StormByte::ByteSize::operator/ ( ByteSize  ) const
delete

◆ operator/=() [1/3]

ByteSize & StormByte::ByteSize::operator/= ( ByteSize  )
delete

◆ operator/=() [2/3]

constexpr ByteSize & StormByte::ByteSize::operator/= ( Size  other)
inlineconstexprnoexcept

Divide by a unit count.

Parameters
otherDivisor.
Returns
*this.

◆ operator/=() [3/3]

template<Type::Integral T>
constexpr ByteSize & StormByte::ByteSize::operator/= ( T  value)
inlineconstexprnoexcept

Divide by an integer.

Template Parameters
TIntegral type.
Parameters
valueDivisor.
Returns
*this.

◆ operator=() [1/3]

constexpr ByteSize & StormByte::ByteSize::operator= ( ByteSize &&  other)
constexprdefaultnoexcept

Move assignment.

Parameters
otherLength to take.
Returns
*this.

◆ operator=() [2/3]

constexpr ByteSize & StormByte::ByteSize::operator= ( const ByteSize &  other)
constexprdefaultnoexcept

Copy assignment.

Parameters
otherLength to copy.
Returns
*this.

◆ operator=() [3/3]

template<Type::Integral T>
constexpr ByteSize & StormByte::ByteSize::operator= ( T  value)
inlineconstexprnoexcept

Assign an integer octet count.

Template Parameters
TIntegral type.
Parameters
valueOctets. Negative is undefined (assert when on).
Returns
*this.

Friends And Related Symbol Documentation

◆ operator% [1/2]

constexpr ByteSize operator% ( ByteSize  lhs,
Size  rhs 
)
friend

Remainder with a unit count.

Parameters
lhsLength.
rhsDivisor.
Returns
Remainder as ByteSize.

◆ operator% [2/2]

template<Type::Integral T>
constexpr ByteSize operator% ( ByteSize  lhs,
T  rhs 
)
friend

Mixed remainder.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsDividend.
rhsDivisor.
Returns
Remainder as ByteSize.

◆ operator* [1/4]

constexpr ByteSize operator* ( ByteSize  lhs,
Size  rhs 
)
friend

Scale by a unit count.

Parameters
lhsLength.
rhsFactor.
Returns
Product as ByteSize.

◆ operator* [2/4]

template<Type::Integral T>
constexpr ByteSize operator* ( ByteSize  lhs,
T  rhs 
)
friend

Mixed product.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft factor.
rhsRight factor.
Returns
Product as ByteSize.

◆ operator* [3/4]

constexpr ByteSize operator* ( Size  lhs,
ByteSize  rhs 
)
friend

Scale by a unit count.

Parameters
lhsFactor.
rhsLength.
Returns
Product as ByteSize.

◆ operator* [4/4]

template<Type::Integral T>
constexpr ByteSize operator* ( T  lhs,
ByteSize  rhs 
)
friend

Mixed product.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft factor.
rhsRight factor.
Returns
Product as ByteSize.

◆ operator+ [1/3]

constexpr ByteSize operator+ ( ByteSize  lhs,
ByteSize  rhs 
)
friend

Sum of lengths.

Parameters
lhsLeft addend.
rhsRight addend.
Returns
Sum as ByteSize.

◆ operator+ [2/3]

template<Type::Integral T>
constexpr ByteSize operator+ ( ByteSize  lhs,
T  rhs 
)
friend

Mixed sum.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft addend.
rhsRight addend.
Returns
Sum as ByteSize.

◆ operator+ [3/3]

template<Type::Integral T>
constexpr ByteSize operator+ ( T  lhs,
ByteSize  rhs 
)
friend

Mixed sum.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft addend.
rhsRight addend.
Returns
Sum as ByteSize.

◆ operator- [1/3]

constexpr ByteSize operator- ( ByteSize  lhs,
ByteSize  rhs 
)
friend

Difference of lengths.

Parameters
lhsMinuend.
rhsSubtrahend.
Returns
Difference as ByteSize.

◆ operator- [2/3]

template<Type::Integral T>
constexpr ByteSize operator- ( ByteSize  lhs,
T  rhs 
)
friend

Mixed difference.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsMinuend.
rhsSubtrahend.
Returns
Difference as ByteSize.

◆ operator- [3/3]

template<Type::Integral T>
constexpr ByteSize operator- ( T  lhs,
ByteSize  rhs 
)
friend

Mixed difference.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsMinuend.
rhsSubtrahend.
Returns
Difference as ByteSize.

◆ operator/ [1/2]

constexpr ByteSize operator/ ( ByteSize  lhs,
Size  rhs 
)
friend

Divide by a unit count.

Parameters
lhsLength.
rhsDivisor.
Returns
Quotient as ByteSize.

◆ operator/ [2/2]

template<Type::Integral T>
constexpr ByteSize operator/ ( ByteSize  lhs,
T  rhs 
)
friend

Mixed quotient.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsDividend.
rhsDivisor.
Returns
Quotient as ByteSize.

◆ operator<=> [1/5]

constexpr std::strong_ordering operator<=> ( ByteSize  lhs,
ByteSize  rhs 
)
friend

Numeric order.

Parameters
lhsLeft length.
rhsRight length.
Returns
Ordering.

◆ operator<=> [2/5]

constexpr std::strong_ordering operator<=> ( ByteSize  lhs,
Size  rhs 
)
friend

Mixed order with Size.

Parameters
lhsLeft length.
rhsRight unit count.
Returns
Ordering.

◆ operator<=> [3/5]

template<Type::Integral T>
constexpr std::strong_ordering operator<=> ( ByteSize  lhs,
T  rhs 
)
friend

Mixed order with an integer.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft length.
rhsRight integer.
Returns
Ordering.

◆ operator<=> [4/5]

constexpr std::strong_ordering operator<=> ( Size  lhs,
ByteSize  rhs 
)
friend

Mixed order with Size.

Parameters
lhsLeft unit count.
rhsRight length.
Returns
Ordering.

◆ operator<=> [5/5]

template<Type::Integral T>
constexpr std::strong_ordering operator<=> ( T  lhs,
ByteSize  rhs 
)
friend

Mixed order with an integer.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft integer.
rhsRight length.
Returns
Ordering.

◆ operator== [1/5]

constexpr bool operator== ( ByteSize  lhs,
ByteSize  rhs 
)
friend

Numeric equality.

Parameters
lhsLeft length.
rhsRight length.
Returns
Whether the lengths are equal.

◆ operator== [2/5]

constexpr bool operator== ( ByteSize  lhs,
Size  rhs 
)
friend

Mixed equality with Size.

Parameters
lhsLeft length.
rhsRight unit count.
Returns
Whether the numeric values match.

◆ operator== [3/5]

template<Type::Integral T>
constexpr bool operator== ( ByteSize  lhs,
T  rhs 
)
friend

Mixed equality with an integer.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft length.
rhsRight integer.
Returns
Whether the numeric values match.

◆ operator== [4/5]

constexpr bool operator== ( Size  lhs,
ByteSize  rhs 
)
friend

Mixed equality with Size.

Parameters
lhsLeft unit count.
rhsRight length.
Returns
Whether the numeric values match.

◆ operator== [5/5]

template<Type::Integral T>
constexpr bool operator== ( T  lhs,
ByteSize  rhs 
)
friend

Mixed equality with an integer.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft integer.
rhsRight length.
Returns
Whether the numeric values match.

Member Data Documentation

◆ B

constexpr Unit StormByte::ByteSize::B {1ull}
staticconstexpr

2^0 octets

◆ EB

constexpr Unit StormByte::ByteSize::EB {1000ull * 1000 * 1000 * 1000 * 1000 * 1000}
staticconstexpr

10^18 octets

◆ EiB

constexpr Unit StormByte::ByteSize::EiB {1024ull * 1024 * 1024 * 1024 * 1024 * 1024}
staticconstexpr

2^60 octets

◆ GB

constexpr Unit StormByte::ByteSize::GB {1000ull * 1000 * 1000}
staticconstexpr

10^9 octets

◆ GiB

constexpr Unit StormByte::ByteSize::GiB {1024ull * 1024 * 1024}
staticconstexpr

2^30 octets

◆ KB

constexpr Unit StormByte::ByteSize::KB {1000ull}
staticconstexpr

10^3 octets

◆ KiB

constexpr Unit StormByte::ByteSize::KiB {1024ull}
staticconstexpr

2^10 octets

◆ MB

constexpr Unit StormByte::ByteSize::MB {1000ull * 1000}
staticconstexpr

10^6 octets

◆ MiB

constexpr Unit StormByte::ByteSize::MiB {1024ull * 1024}
staticconstexpr

2^20 octets

◆ PB

constexpr Unit StormByte::ByteSize::PB {1000ull * 1000 * 1000 * 1000 * 1000}
staticconstexpr

10^15 octets

◆ PiB

constexpr Unit StormByte::ByteSize::PiB {1024ull * 1024 * 1024 * 1024 * 1024}
staticconstexpr

2^50 octets

◆ TB

constexpr Unit StormByte::ByteSize::TB {1000ull * 1000 * 1000 * 1000}
staticconstexpr

10^12 octets

◆ TiB

constexpr Unit StormByte::ByteSize::TiB {1024ull * 1024 * 1024 * 1024}
staticconstexpr

2^40 octets


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