forked from htailor/cpp_progress_bar
-
Notifications
You must be signed in to change notification settings - Fork 3
/
progress_bar.hpp
53 lines (41 loc) · 1.14 KB
/
progress_bar.hpp
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
#ifndef _PROGRESS_BAR_
#define _PROGRESS_BAR_
#ifdef _WINDOWS
#include <windows.h>
#else
#include <sys/ioctl.h>
#endif
#include <iostream>
#include <string>
#include <mutex>
#include <atomic>
class ProgressBar {
public:
ProgressBar(uint64_t total,
const std::string &description = "",
std::ostream &out = std::cerr,
bool silent = false);
~ProgressBar();
void SetFrequencyUpdate(uint64_t frequency_update_);
void SetStyle(char unit_bar, char unit_space);
ProgressBar& operator++();
ProgressBar& operator+=(uint64_t delta);
private:
ProgressBar(const ProgressBar &) = delete;
ProgressBar& operator=(const ProgressBar &) = delete;
void ShowProgress(uint64_t progress) const;
int GetConsoleWidth() const;
int GetBarLength() const;
bool silent_;
bool logging_mode_;
uint64_t total_;
std::atomic<uint64_t> progress_ = {0};
uint64_t frequency_update;
std::ostream *out;
mutable std::mutex mu_;
mutable std::string buffer_;
std::string description_;
char unit_bar_ = '=';
char unit_space_ = ' ';
};
#endif // _PROGRESS_BAR_