-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProgressBar.h
86 lines (77 loc) · 3.11 KB
/
ProgressBar.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// The MIT License (MIT)
//
// Copyright (c) 2019 Luigi Pertoldi
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
// ============================================================================
// ___ ___ ___ __ ___ ____ __ __ ___ __ ___
// | |_) | |_) / / \ / /`_ | |_) | |_ ( (` ( (` | |_) / /\ | |_)
// |_| |_| \ \_\_/ \_\_/ |_| \ |_|__ _)_) _)_) |_|_) /_/--\ |_| \_
//
// Very simple progress bar for c++ loops with internal running variable
//
// Author: Luigi Pertoldi
// Created: 3 dic 2016
//
// Notes: The bar must be used when there's no other possible source of output
// inside the for loop
//
#ifndef __PROGRESSBAR_HPP
#define __PROGRESSBAR_HPP
#include <iostream>
#include <string>
#include <stdexcept>
class ProgressBar {
public:
// default destructor
~ProgressBar() = default;
// delete everything else
ProgressBar (ProgressBar const&) = delete;
ProgressBar& operator=(ProgressBar const&) = delete;
ProgressBar (ProgressBar&&) = delete;
ProgressBar& operator=(ProgressBar&&) = delete;
// default constructor, must call set_niter later
ProgressBar();
ProgressBar(int n, bool showbar=true);
// reset bar to use it again
void reset();
// set number of loop iterations
void set_niter(int iter);
// chose your style
void set_done_char(const std::string& sym) {done_char = sym;}
void set_todo_char(const std::string& sym) {todo_char = sym;}
void set_opening_bracket_char(const std::string& sym) {opening_bracket_char = sym;}
void set_closing_bracket_char(const std::string& sym) {closing_bracket_char = sym;}
// to show only the percentage
void show_bar(bool flag = true) {do_show_bar = flag;}
// main function
void update();
private:
int progress;
int n_cycles;
int last_perc;
bool do_show_bar;
bool update_is_called;
std::string done_char;
std::string todo_char;
std::string opening_bracket_char;
std::string closing_bracket_char;
};
#endif