MCPcopy Create free account
hub / github.com/HO-COOH/FastCopy / Size

Class Size

FastCopy/ReadableUnitConverter.h:6–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4namespace ReadableUnitConverter
5{
6 class Size
7 {
8 template<typename Char>
9 struct FormatString;
10
11 template<>
12 struct FormatString<char>
13 {
14 constexpr static auto B = "{} B";
15 constexpr static auto KB = "{:.2f} KB";
16 constexpr static auto MB = "{:.2f} MB";
17 constexpr static auto GB = "{:.2f} GB";
18 };
19
20 template<>
21 struct FormatString<wchar_t>
22 {
23 constexpr static auto B = L"{} B";
24 constexpr static auto KB = L"{:.2f} KB";
25 constexpr static auto MB = L"{:.2f} MB";
26 constexpr static auto GB = L"{:.2f} GB";
27 };
28
29 constexpr static size_t ToKB = 1024;
30 constexpr static size_t ToMB = ToKB * 1024;
31 constexpr static size_t ToGB = ToMB * 1024;
32 public:
33 template<typename Char>
34 static auto ToString(size_t bytes)
35 {
36 if (bytes <= ToKB)
37 return std::format(FormatString<Char>::B, bytes);
38 else if (bytes <= ToMB)
39 return std::format(FormatString<Char>::KB, static_cast<double>(bytes) / ToKB);
40 else if (bytes <= ToGB)
41 return std::format(FormatString<Char>::MB, static_cast<double>(bytes) / ToMB);
42 else return std::format(FormatString<Char>::GB, static_cast<double>(bytes) / ToGB);
43 }
44
45 };
46
47 struct Speed
48 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected