|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
字节大小类 更多...
#include <byte_size.hpp>
Public 类型 | |
| enum class | unit { B , KB , MB , GB , TB , PB , EB , AUTO } |
| 字节大小单位枚举 更多... | |
Public 成员函数 | |
| constexpr | byte_size () noexcept=default |
| 默认构造函数 | |
| constexpr | byte_size (uint64_t bytes) noexcept |
| 从字节数构造 | |
| byte_size (decimal_t value, unit u, bool binary=true) | |
| 从值和单位构造 | |
| constexpr uint64_t | bytes () const noexcept |
| 获取字节数 | |
| decimal_t | as (unit u, bool binary=true) const |
| 转换为指定单位的值 | |
| string | to_string () const |
| 转换为可读字符串 | |
| string | to_string (unit u, int precision=2, bool binary=true) const |
| 转换为指定单位的字符串 | |
| constexpr bool | is_zero () const noexcept |
| 检查是否为零 | |
| size_t | to_hash () const noexcept |
| 计算哈希值 | |
| Public 成员函数 继承自 iobject< byte_size > | |
| constexpr bool | try_parse (const string_view str) noexcept |
| 尝试从字符串解析对象 | |
| Public 成员函数 继承自 istringify< byte_size > | |
| constexpr string | to_string () const |
| 转换为字符串 | |
| Public 成员函数 继承自 icomparable< byte_size > | |
| constexpr bool | operator== (const byte_size &rhs) const noexcept(noexcept(derived().equal_to(rhs))) |
| 相等比较运算符 | |
| constexpr bool | operator!= (const byte_size &rhs) const noexcept(noexcept(!(derived().equal_to(rhs)))) |
| 不等比较运算符 | |
| constexpr bool | operator< (const byte_size &rhs) const noexcept(noexcept(derived().less_than(rhs))) |
| 小于比较运算符 | |
| constexpr bool | operator> (const byte_size &rhs) const noexcept(noexcept(rhs.less_than(derived()))) |
| 大于比较运算符 | |
| constexpr bool | operator<= (const byte_size &rhs) const noexcept(noexcept(!(rhs.less_than(derived())))) |
| 小于等于比较运算符 | |
| constexpr bool | operator>= (const byte_size &rhs) const noexcept(noexcept(!(derived().less_than(rhs)))) |
| 大于等于比较运算符 | |
| Public 成员函数 继承自 ihashable< byte_size > | |
| constexpr size_t | to_ihash () const noexcept(noexcept(derived().to_hash())) |
| 获取对象的哈希值 | |
静态 Public 成员函数 | |
| static byte_size | parse (string_view str) |
| 从字符串解析字节大小 | |
| static byte_size | parse (string_view str, bool binary) |
| 从字符串解析字节大小(指定进制) | |
| 静态 Public 成员函数 继承自 iobject< byte_size > | |
| static constexpr byte_size | parse (const string_view str) |
| 从字符串解析对象 | |
字节大小类
表示一个字节大小值,支持多种单位之间的转换和运算。 提供类型安全的字节大小操作,避免原始整数带来的单位混淆问题。
主要功能:
使用示例:
TODO: All operations for optimizing byte_size are constexpr
在文件 byte_size.hpp 第 145 行定义.
|
strong |
字节大小单位枚举
| 枚举值 | |
|---|---|
| B | 字节 |
| KB | 千字节 |
| MB | 兆字节 |
| GB | 吉字节 |
| TB | 太字节 |
| PB | 拍字节 |
| EB | 艾字节 |
| AUTO | 自动选择合适单位 |
在文件 byte_size.hpp 第 151 行定义.
|
constexprdefaultnoexcept |
|
inlineexplicitconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
|
inlinestaticnodiscard |
从字符串解析字节大小
| 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().
|
staticnodiscard |
|
inlinenodiscardnoexcept |
|
inlinenodiscard |
转换为指定单位的字符串
| u | 目标单位 |
| precision | 小数精度 |
| binary | 是否使用二进制 |