-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.cpp
More file actions
47 lines (41 loc) · 778 Bytes
/
progress.cpp
File metadata and controls
47 lines (41 loc) · 778 Bytes
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
#include <stdio.h>
#include <sstream>
#include <iostream>
#include "progress.h"
Progress::Progress(std::__cxx11::string title, int max_, bool shown_) :
current(0),
max(max_),
is_done(false),
shown(shown_)
{
if (shown) {
std::cout << title << " (0/" << max << ")" << std::endl;
}
}
Progress::~Progress() {
if (shown && !is_done) {
done();
}
}
void Progress::step_one() {
if (shown) {
std::cout << "." << std::flush;
current++;
if (current % 50 == 0) {
std::cout << " " << current << "/" << max << std::endl;
}
}
}
void Progress::step(int n) {
if (shown) {
for (int i = n; i; --i) {
step_one();
}
}
}
void Progress::done() {
if (shown) {
std::cout << " Done." << std::endl;
is_done = true;
}
}