LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
bwf_std.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Apache Software Foundation 2019
7
8#pragma once
9
10#include <atomic>
11#include <chrono>
12#include <bitset>
13
14#include "swoc/swoc_version.h"
15#include "swoc/bwf_base.h"
16
17namespace swoc { inline namespace SWOC_VERSION_NS {
18using namespace literals;
19
21template <typename T>
22BufferWriter &
23bwformat(BufferWriter &w, bwf::Spec const &spec, std::atomic<T> const &v) {
24 return ::swoc::bwformat(w, spec, v.load());
25}
26
27BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, std::error_code const &ec);
28
29template <size_t N>
30BufferWriter &
31bwformat(BufferWriter &w, bwf::Spec const & /* spec */, std::bitset<N> const &bits) {
32 for (unsigned idx = 0; idx < N; ++idx) {
33 w.write(bits[idx] ? '1' : '0');
34 }
35 return w;
36}
37
38template <typename Rep, typename Period>
39BufferWriter &
40bwformat(BufferWriter &w, bwf::Spec const &spec, std::chrono::duration<Rep, Period> const &d) {
41 return bwformat(w, spec, d.count());
42}
43
44template <typename Clock, typename Duration>
45BufferWriter &
46bwformat(BufferWriter &w, bwf::Spec const &spec, std::chrono::time_point<Clock, Duration> const &t) {
47 return bwformat(w, spec, t.time_since_epoch());
48}
49
50inline BufferWriter &
51bwformat(BufferWriter &w, bwf::Spec const &spec, std::exception const &e) {
52 w.write("Exception - "_tv);
53 return bwformat(w, spec, e.what());
54}
55
56}} // namespace swoc::SWOC_VERSION_NS
virtual BufferWriter & write(char c)=0
For template deduction guides.
Definition ArenaWriter.cc:9
BufferWriter & bwformat(BufferWriter &w, bwf::Spec const &spec, std::string_view sv)
Definition bw_format.cc:649