|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
字节大小类 更多...
#include <byte_size.hpp>
Public 类型 | |
| enum class | unit { AUTO , B , KB , MB , GB , TB , PB , EB } |
| 字节大小单位枚举 更多... | |
Public 成员函数 | |
| constexpr | byte_size ()=default |
| 默认构造函数 | |
| constexpr | byte_size (uint64_t bytes) |
| 从字节数构造 | |
| byte_size (decimal_t value, unit u, bool binary=true) | |
| 从值和单位构造 | |
| NEFORCE_NODISCARD constexpr uint64_t | bytes () const |
| 获取字节数 | |
| NEFORCE_NODISCARD decimal_t | as (unit u, bool binary=true) const |
| 转换为指定单位的值 | |
| NEFORCE_NODISCARD string | to_string () const |
| 转换为可读字符串 | |
| NEFORCE_NODISCARD string | to_string (unit u, int precision=2, bool binary=true) const |
| 转换为指定单位的字符串 | |
| NEFORCE_NODISCARD constexpr bool | is_zero () const noexcept |
| 检查是否为零 | |
| NEFORCE_NODISCARD size_t | to_hash () const noexcept |
| 计算哈希值 | |
| Public 成员函数 继承自 iobject< byte_size > | |
| NEFORCE_CONSTEXPR20 bool | try_parse (const string_view str) noexcept |
| 尝试从字符串解析对象 | |
| Public 成员函数 继承自 istringify< byte_size > | |
| NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string | to_string () const |
| 转换为字符串 | |
| Public 成员函数 继承自 icomparable< byte_size > | |
| NEFORCE_NODISCARD constexpr bool | operator== (const byte_size &rhs) const noexcept(noexcept(derived()==rhs)) |
| 相等比较运算符 | |
| NEFORCE_NODISCARD constexpr bool | operator!= (const byte_size &rhs) const noexcept(noexcept(!(*this==rhs))) |
| 不等比较运算符 | |
| NEFORCE_NODISCARD constexpr bool | operator< (const byte_size &rhs) const noexcept(noexcept(derived()< rhs)) |
| 小于比较运算符 | |
| NEFORCE_NODISCARD constexpr bool | operator> (const byte_size &rhs) const noexcept(noexcept(rhs< derived())) |
| 大于比较运算符 | |
| NEFORCE_NODISCARD constexpr bool | operator<= (const byte_size &rhs) const noexcept(noexcept(!(derived() > rhs))) |
| 小于等于比较运算符 | |
| NEFORCE_NODISCARD constexpr bool | operator>= (const byte_size &rhs) const noexcept(noexcept(!(derived()< rhs))) |
| 大于等于比较运算符 | |
| Public 成员函数 继承自 ihashable< byte_size > | |
| NEFORCE_NODISCARD constexpr size_t | to_hash () const noexcept(noexcept(derived().to_hash())) |
| 获取对象的哈希值 | |
静态 Public 成员函数 | |
| static NEFORCE_NODISCARD byte_size | parse (string_view str) |
| 从字符串解析字节大小 | |
| static NEFORCE_NODISCARD byte_size | parse (string_view str, bool binary) |
| 从字符串解析字节大小(指定进制) | |
| 静态 Public 成员函数 继承自 iobject< byte_size > | |
| static NEFORCE_NODISCARD constexpr byte_size | parse (const string_view str) |
| 从字符串解析对象 | |
字节大小类
表示一个字节大小值,支持多种单位之间的转换和运算。 提供类型安全的字节大小操作,避免原始整数带来的单位混淆问题。
主要功能:
使用示例:
在文件 byte_size.hpp 第 145 行定义.
|
strong |
字节大小单位枚举
| 枚举值 | |
|---|---|
| AUTO | 自动选择合适单位 |
| B | 字节 |
| KB | 千字节 |
| MB | 兆字节 |
| GB | 吉字节 |
| TB | 太字节 |
| PB | 拍字节 |
| EB | 艾字节 |
在文件 byte_size.hpp 第 151 行定义.
|
inlineexplicitconstexpr |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
|
inlinestatic |
从字符串解析字节大小
| str | 字符串 |
| value_exception | 解析失败时抛出 |
支持的单位:B、KB/K、MB/M、GB/G、TB/T、PB/P、EB/E 示例:"1024", "1.5 MB", "2G", "500KB"
在文件 byte_size.hpp 第 198 行定义.
引用了 byte_size() , 以及 parse().
被这些函数引用 parse().
|
static |
|
inlinenoexcept |
|
inline |
| NEFORCE_NODISCARD string byte_size::to_string | ( | unit | u, |
| int | precision = 2, | ||
| bool | binary = true ) const |
转换为指定单位的字符串
| u | 目标单位 |
| precision | 小数精度 |
| binary | 是否使用二进制 |