]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/histogram/accumulators/ostream.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / histogram / accumulators / ostream.hpp
CommitLineData
92f5a8d4
TL
1// Copyright 2015-2017 Hans Dembinski
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt
5// or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#ifndef BOOST_HISTOGRAM_ACCUMULATORS_OSTREAM_HPP
8#define BOOST_HISTOGRAM_ACCUMULATORS_OSTREAM_HPP
9
10#include <boost/histogram/detail/counting_streambuf.hpp>
11#include <boost/histogram/fwd.hpp>
12#include <ios>
13
14/**
15 \file boost/histogram/accumulators/ostream.hpp
16 Simple streaming operators for the builtin accumulator types.
17
18 The text representation is not guaranteed to be stable between versions of
19 Boost.Histogram. This header is only included by
20 [boost/histogram/ostream.hpp](histogram/reference.html#header.boost.histogram.ostream_hpp).
20effc67 21 To use your own, include your own implementation instead of this header and do not
92f5a8d4
TL
22 include
23 [boost/histogram/ostream.hpp](histogram/reference.html#header.boost.histogram.ostream_hpp).
24 */
25
26#ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
27
28namespace boost {
29namespace histogram {
30
31namespace detail {
32
33template <class CharT, class Traits, class T>
34std::basic_ostream<CharT, Traits>& handle_nonzero_width(
35 std::basic_ostream<CharT, Traits>& os, const T& x) {
36 const auto w = os.width();
37 os.width(0);
20effc67
TL
38 std::streamsize count = 0;
39 {
40 auto g = make_count_guard(os, count);
41 os << x;
42 }
92f5a8d4
TL
43 if (os.flags() & std::ios::left) {
44 os << x;
20effc67 45 for (auto i = count; i < w; ++i) os << os.fill();
92f5a8d4 46 } else {
20effc67 47 for (auto i = count; i < w; ++i) os << os.fill();
92f5a8d4
TL
48 os << x;
49 }
50 return os;
51}
52
53} // namespace detail
54
55namespace accumulators {
f67539c2
TL
56
57template <class CharT, class Traits, class U>
58std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
59 const count<U>& x) {
60 return os << x.value();
61}
62
63template <class CharT, class Traits, class U>
92f5a8d4 64std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
f67539c2 65 const sum<U>& x) {
92f5a8d4
TL
66 if (os.width() == 0) return os << "sum(" << x.large() << " + " << x.small() << ")";
67 return detail::handle_nonzero_width(os, x);
68}
69
f67539c2 70template <class CharT, class Traits, class U>
92f5a8d4 71std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
f67539c2 72 const weighted_sum<U>& x) {
92f5a8d4
TL
73 if (os.width() == 0)
74 return os << "weighted_sum(" << x.value() << ", " << x.variance() << ")";
75 return detail::handle_nonzero_width(os, x);
76}
77
f67539c2 78template <class CharT, class Traits, class U>
92f5a8d4 79std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
f67539c2 80 const mean<U>& x) {
92f5a8d4
TL
81 if (os.width() == 0)
82 return os << "mean(" << x.count() << ", " << x.value() << ", " << x.variance() << ")";
83 return detail::handle_nonzero_width(os, x);
84}
85
f67539c2 86template <class CharT, class Traits, class U>
92f5a8d4 87std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
f67539c2 88 const weighted_mean<U>& x) {
92f5a8d4
TL
89 if (os.width() == 0)
90 return os << "weighted_mean(" << x.sum_of_weights() << ", " << x.value() << ", "
91 << x.variance() << ")";
92 return detail::handle_nonzero_width(os, x);
93}
94
95template <class CharT, class Traits, class T>
96std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
97 const thread_safe<T>& x) {
98 os << x.load();
99 return os;
100}
101} // namespace accumulators
102} // namespace histogram
103} // namespace boost
104
105#endif // BOOST_HISTOGRAM_DOXYGEN_INVOKED
106
107#endif