2012-05-14 16:11:09 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-05-14 16:11:09 +10:00
|
|
|
*
|
|
|
|
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
2021-04-14 15:35:49 +10:00
|
|
|
#pragma once
|
2012-05-14 16:11:09 +10:00
|
|
|
|
2018-03-22 16:10:06 +11:00
|
|
|
#include <iosfwd>
|
2023-07-21 14:20:49 +10:00
|
|
|
#include <fmt/core.h>
|
2012-05-14 16:11:09 +10:00
|
|
|
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft {
|
2012-05-14 16:11:09 +10:00
|
|
|
namespace stats {
|
|
|
|
// Undefined until at least one value has been added.
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct accumulator {
|
|
|
|
accumulator ();
|
|
|
|
|
2012-08-07 18:34:36 +10:00
|
|
|
void reset (void);
|
|
|
|
|
2012-05-14 16:11:09 +10:00
|
|
|
void add (T);
|
|
|
|
void add (const accumulator<T> &);
|
|
|
|
|
2012-05-15 16:04:06 +10:00
|
|
|
size_t count;
|
|
|
|
|
2012-05-14 16:11:09 +10:00
|
|
|
T min;
|
|
|
|
T max;
|
2012-05-15 16:04:06 +10:00
|
|
|
T sum;
|
2012-05-14 16:11:09 +10:00
|
|
|
|
|
|
|
T range (void) const;
|
2012-05-15 16:04:06 +10:00
|
|
|
T mean (void) const;
|
2012-05-14 16:11:09 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2023-07-21 14:20:49 +10:00
|
|
|
std::ostream&
|
|
|
|
operator<< (std::ostream&, const accumulator<T>&);
|
2012-05-14 16:11:09 +10:00
|
|
|
}
|
2023-07-21 14:20:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct fmt::formatter<cruft::stats::accumulator<T>> {
|
|
|
|
constexpr format_parse_context::iterator
|
|
|
|
parse (format_parse_context &ctx)
|
|
|
|
{
|
|
|
|
return ctx.begin ();
|
|
|
|
}
|
|
|
|
|
|
|
|
format_context::iterator
|
2024-10-16 12:19:35 +11:00
|
|
|
format (cruft::stats::accumulator<T> const&, format_context &ctx) const;
|
2023-07-21 14:20:49 +10:00
|
|
|
};
|