14 const std::string& a_base_size_unit =
"b",
16 uint16 a_precision = 1,
31 const char* units[] = {
43 int resolution = ones;
50 TRY_nomem(es =
"Could not generate size-string: \"");
54 for (tmp = 1; tmp < a_precision; ++tmp) {
57 while ((quotient >= a_kilo) && (resolution < yotta)) {
72 if (resolution > ones) {
101 std::string::size_type n;
104 TRY_nomem(es =
"Could not generate num-string: \"");
108 if (tstr.size() == 0) {
114 if (str.size() > 0) {
117 str = tstr[(n--)-1] + str;
if (n == 0)
break;
118 str = tstr[(n--)-1] + str;
if (n == 0)
break;
119 str = tstr[(n--)-1] + str;
137 const std::string& a_base_size_unit =
"b",
138 const std::string& a_base_time_unit =
"s",
140 uint16 a_precision = 1,
147 str =
size_to_string(a_t, a_base_size_unit, a_width-2, a_precision, a_kilo)
164 es =
"Could not calculate percentage";
165 if (a_complete == static_cast<T>(0)) {
166 percent =
static_cast<T
>(0);
168 else if (a_total == static_cast<T>(0)) {
174 percent = static_cast<double>(a_complete);
176 percent /=
static_cast<double>(a_total);
183 estr = percent.
value();
Safely manipulate numbers without worryiung about over/underflow error.
Basic types definitions and templates.
An extended string class.
const T value(void) const
Return the value.
std::string percent_string(const T &a_complete, const T &a_total)
Given a count complete and a count total, calculate a percentage.
std::string num_to_string(T a_t, uint16 a_width=0)
Given an integral number, return a string with the number formatted in a generic, human-readable form...
std::string throughput_to_string(T a_t, const std::string &a_base_size_unit="b", const std::string &a_base_time_unit="s", uint16 a_width=10, uint16 a_precision=1, uint16 a_kilo=1024)
Given an integral number, return a string with the number formated as a number of machine-type size p...
size_type precision(size_type a_p)
Set the precision used in converting to/from fractional types.
value_type fmt_str(void)
Generate a formatted string.
void fillchar(const char a_char)
Set the fill character used for padding both the left and right side of a formatted string...
size_type width(const size_type a_l)
Set the width of a formatted string.
std::string size_to_string(T a_t, const std::string &a_base_size_unit="b", uint16 a_width=8, uint16 a_precision=1, uint16 a_kilo=1024)
Given an integral number, return a string with the number formatted as a human-readable machine-type ...
alignment align(const alignment a_alignment)
Set the alignment used for formatted strings.