hej
is hosted by
Hepforge
,
IPPP Durham
HEJ 2
2.0
High energy resummation for hadron colliders
Loading...
Searching...
No Matches
include
HEJ
ProgressBar.hh
Go to the documentation of this file.
1
8
#pragma once
9
10
#include <ostream>
11
#include <functional>
12
#include <stdexcept>
13
14
namespace
HEJ
{
15
17
template
<
typename
T>
18
class
ProgressBar
{
19
public
:
21
27
ProgressBar
(std::ostream & out, T max) :
28
out_{out}, max_{max}
29
{
30
if
(max <= 0) {
31
throw
std::invalid_argument{
32
"Maximum in progress bar has to be positive"
33
};
34
}
35
print_bar();
36
}
37
39
46
ProgressBar
&
increment
(T count) {
47
counter_ += count;
48
update_progress();
49
return
*
this
;
50
}
51
53
58
ProgressBar
&
operator++
() {
59
++counter_;
60
update_progress();
61
return
*
this
;
62
}
63
64
private
:
65
void
update_progress() {
66
counter_ = std::min(counter_, max_);
67
const
int
ndots = (100*counter_)/max_;
68
const
int
new_dots = ndots - ndots_;
69
if
(new_dots > 0) {
70
for
(
int
dot = 0; dot < new_dots; ++dot) out_.get() <<
'.'
;
71
out_.get().flush();
72
ndots_ = ndots;
73
}
74
}
75
76
void
print_bar()
const
{
77
out_.get() <<
"0% "
;
78
for
(
int
i = 10; i <= 100; i+= 10){
79
out_.get() <<
" "
+ std::to_string(i) +
"%"
;
80
}
81
out_.get() <<
"\n|"
;
82
for
(
int
i = 10; i <= 100; i+= 10){
83
out_.get() <<
"---------|"
;
84
}
85
out_.get() <<
'\n'
;
86
}
87
88
std::reference_wrapper<std::ostream> out_;
89
T counter_ = 0;
90
T ndots_ = 0;
91
T max_;
92
};
93
}
HEJ::ProgressBar
Class representing (and printing) a progress bar.
Definition:
ProgressBar.hh:18
HEJ::ProgressBar::increment
ProgressBar & increment(T count)
Increment progress.
Definition:
ProgressBar.hh:46
HEJ::ProgressBar::ProgressBar
ProgressBar(std::ostream &out, T max)
Constructor.
Definition:
ProgressBar.hh:27
HEJ::ProgressBar::operator++
ProgressBar & operator++()
Increase progress by one unit.
Definition:
ProgressBar.hh:58
HEJ
Main HEJ 2 Namespace.
Definition:
mainpage.dox:1
Generated by
1.9.5