Merge pull request #70 from phdussud/master
limit the progressBar update rate to 5 per second. This speeds up loa…
This commit is contained in:
commit
4ed01ae9ee
|
|
@ -23,10 +23,16 @@
|
||||||
ProgressBar::ProgressBar(std::string mess, int maxValue, int progressLen):
|
ProgressBar::ProgressBar(std::string mess, int maxValue, int progressLen):
|
||||||
_mess(mess), _maxValue(maxValue), _progressLen(progressLen)
|
_mess(mess), _maxValue(maxValue), _progressLen(progressLen)
|
||||||
{
|
{
|
||||||
|
last_time = clock();
|
||||||
}
|
}
|
||||||
|
void ProgressBar::display(int value, char force)
|
||||||
void ProgressBar::display(int value)
|
|
||||||
{
|
{
|
||||||
|
clock_t this_time = clock();
|
||||||
|
if (!force && ((((float)(this_time - last_time))/CLOCKS_PER_SEC) < 0.2))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
last_time = this_time;
|
||||||
float percent = ((float)value * 100.0f)/(float)_maxValue;
|
float percent = ((float)value * 100.0f)/(float)_maxValue;
|
||||||
float nbEq = (percent * (float) _progressLen)/100.0f;
|
float nbEq = (percent * (float) _progressLen)/100.0f;
|
||||||
|
|
||||||
|
|
@ -41,13 +47,13 @@ void ProgressBar::display(int value)
|
||||||
}
|
}
|
||||||
void ProgressBar::done()
|
void ProgressBar::done()
|
||||||
{
|
{
|
||||||
display(_maxValue);
|
display(_maxValue, true);
|
||||||
//fprintf(stderr, "\nDone\n");
|
//fprintf(stderr, "\nDone\n");
|
||||||
printSuccess("\nDone");
|
printSuccess("\nDone");
|
||||||
}
|
}
|
||||||
void ProgressBar::fail()
|
void ProgressBar::fail()
|
||||||
{
|
{
|
||||||
display(_maxValue);
|
display(_maxValue, true);
|
||||||
//fprintf(stderr, "\nDone\n");
|
//fprintf(stderr, "\nDone\n");
|
||||||
printError("\nFail");
|
printError("\nFail");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,20 @@
|
||||||
|
|
||||||
#ifndef PROGRESSBARE_HPP
|
#ifndef PROGRESSBARE_HPP
|
||||||
#define PROGRESSBARE_HPP
|
#define PROGRESSBARE_HPP
|
||||||
|
#include <time.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class ProgressBar {
|
class ProgressBar {
|
||||||
public:
|
public:
|
||||||
ProgressBar(std::string mess, int maxValue, int progressLen);
|
ProgressBar(std::string mess, int maxValue, int progressLen);
|
||||||
void display(int value);
|
void display(int value, char force = 0);
|
||||||
void done();
|
void done();
|
||||||
void fail();
|
void fail();
|
||||||
private:
|
private:
|
||||||
std::string _mess;
|
std::string _mess;
|
||||||
int _maxValue;
|
int _maxValue;
|
||||||
int _progressLen;
|
int _progressLen;
|
||||||
|
clock_t last_time; //records the time of last progress bar update
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue