-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcprogressbar.cpp
More file actions
27 lines (23 loc) · 900 Bytes
/
cprogressbar.cpp
File metadata and controls
27 lines (23 loc) · 900 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
#include <iostream>
#include <iomanip>
#include <string>
#include "cprogressbar.h"
CProgressbar::CProgressbar(int max, int incrementStepSize, int showPercentageStepSize): m_max(max), m_incrementStepSize(incrementStepSize), m_showPercentageStepSize(showPercentageStepSize){
m_current = 0;
};
void CProgressbar::increment(){
m_current += m_incrementStepSize;
}
void CProgressbar::show(std::string message) const {
int currentPercentage = static_cast<int>(m_current * 100 / m_max);
std::cout << "\r" << std::setw(3) << currentPercentage << "% [" << std::flush;
int charNum = m_max / m_showPercentageStepSize;
for(int i=0; i<charNum; i++){
if(currentPercentage >= (i+1)*m_showPercentageStepSize){
std::cout << "#" << std::flush;
}else{
std::cout << "-" << std::flush;
}
}
std::cout << "] " << message << std::flush;
}