2018-10-21 09:50:41 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_UTIL_PRETTY_H
|
|
|
|
|
2019-06-23 10:01:26 +02:00
|
|
|
namespace ircd {
|
|
|
|
inline namespace util
|
2018-10-21 09:50:41 +02:00
|
|
|
{
|
|
|
|
// Human readable space suite
|
|
|
|
using human_readable_size = std::tuple<uint64_t, long double, const string_view &>;
|
2018-11-28 22:49:14 +01:00
|
|
|
|
|
|
|
// Default format strings used for pretty(size).
|
2019-09-23 00:38:51 +02:00
|
|
|
extern const string_view pretty_fmt[];
|
2018-11-28 22:49:14 +01:00
|
|
|
|
|
|
|
// Process the value to be made pretty first with one of the following:
|
2018-10-21 09:50:41 +02:00
|
|
|
human_readable_size iec(const uint64_t &value);
|
|
|
|
human_readable_size si(const uint64_t &value);
|
2018-11-28 22:49:14 +01:00
|
|
|
|
|
|
|
// Generate a pretty string with a custom fmt string (low-level)
|
|
|
|
string_view pretty(const mutable_buffer &out, const string_view &fmt, const human_readable_size &);
|
|
|
|
std::string pretty(const human_readable_size &, const string_view &fmt);
|
|
|
|
|
|
|
|
// Generate a pretty string with the pretty_fmt_default implied.
|
2019-09-23 00:38:51 +02:00
|
|
|
string_view pretty(const mutable_buffer &out, const human_readable_size &, const uint &fmt = 0);
|
|
|
|
std::string pretty(const human_readable_size &, const uint &fmt = 0);
|
2018-10-21 09:50:41 +02:00
|
|
|
|
|
|
|
// Human readable time suite (for timers and counts; otherwise see date.h)
|
2020-09-28 02:53:18 +02:00
|
|
|
string_view pretty(const mutable_buffer &out, const nanoseconds &, const uint &fmt = 0);
|
|
|
|
string_view pretty(const mutable_buffer &out, const microseconds &, const uint &fmt = 0);
|
|
|
|
string_view pretty(const mutable_buffer &out, const milliseconds &, const uint &fmt = 0);
|
|
|
|
string_view pretty(const mutable_buffer &out, const seconds &, const uint &fmt = 0);
|
2018-12-30 22:38:14 +01:00
|
|
|
template<class r, class p> std::string pretty(const duration<r, p> &, const uint &fmt = 0);
|
2019-06-23 10:01:26 +02:00
|
|
|
}}
|
2018-10-21 09:50:41 +02:00
|
|
|
|
|
|
|
template<class rep,
|
|
|
|
class period>
|
2020-09-28 02:53:18 +02:00
|
|
|
inline std::string
|
2018-12-30 22:38:14 +01:00
|
|
|
ircd::util::pretty(const duration<rep, period> &d,
|
|
|
|
const uint &fmt)
|
2018-10-21 09:50:41 +02:00
|
|
|
{
|
2018-12-30 22:38:14 +01:00
|
|
|
return util::string(32, [&d, &fmt]
|
2018-10-21 09:50:41 +02:00
|
|
|
(const mutable_buffer &out)
|
|
|
|
{
|
2018-12-30 22:38:14 +01:00
|
|
|
return pretty(out, d, fmt);
|
2018-10-21 09:50:41 +02:00
|
|
|
});
|
|
|
|
}
|