blob: 855379ae1dff62e460df6f9765193d39dc4b501e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// boost/chrono/stopwatches/formatters/base_formatter.hpp ------------------------------------------------------------//
// Copyright 2011 Vicente J. Botet Escriba
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/chrono/stopwatches for documentation.
#ifndef BOOST_CHRONO_STOPWATCHES_FORMATTERS_BASE_FORMATTER_HPP
#define BOOST_CHRONO_STOPWATCHES_FORMATTERS_BASE_FORMATTER_HPP
#include <boost/chrono/io/duration_style.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/chrono/chrono_io.hpp>
#include <boost/cstdint.hpp>
#include <iostream>
#include <iomanip>
namespace boost
{
namespace chrono
{
template<typename CharT = char, typename Traits = std::char_traits<CharT> >
class base_formatter
{
base_formatter& operator=(base_formatter const& rhs) ;
public:
typedef std::basic_ostream<CharT, Traits> ostream_type;
base_formatter() :
precision_(3), os_(std::cout), duration_style_(duration_style::symbol)
{
}
base_formatter(ostream_type& os) :
precision_(3), os_(os), duration_style_(duration_style::symbol)
{
}
void set_precision(std::size_t precision)
{
precision_ = precision;
if (precision_ > 9)
precision_ = 9; // sanity check
}
void set_os(ostream_type& os)
{
os_ = os;
}
void set_duration_style(duration_style style)
{
duration_style_ = style;
}
protected:
std::size_t precision_;
ostream_type & os_;
duration_style duration_style_;
};
} // namespace chrono
} // namespace boost
#endif
|