File: progressbar.cpp

package info (click to toggle)
wsclean 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,196 kB
  • sloc: cpp: 34,504; ansic: 234; python: 174; makefile: 10
file content (55 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (2)
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
#include "progressbar.h"

#include "wsclean/logger.h"

#include <iostream>

ProgressBar::ProgressBar(const std::string& taskDescription) :
	_taskDescription(taskDescription),
	_displayedDots(-1)
{
}

ProgressBar::~ProgressBar()
{
	SetProgress(1,1);
}

ProgressBar& ProgressBar::operator=(ProgressBar&& rhs)
{
	SetProgress(1, 1);
	_displayedDots = rhs._displayedDots;
	_taskDescription = std::move(rhs._taskDescription);
	rhs._displayedDots = 50;
	return *this;
}

void ProgressBar::SetProgress(size_t taskIndex, size_t taskCount)
{
	if(_displayedDots==-1) {
		Logger::Info << _taskDescription << ":";
		if(_taskDescription.size() < 40)
			Logger::Info << " 0%";
		else
			Logger::Info << "\n 0%";
		_displayedDots=0;
		Logger::Info.Flush();
	}
	int progress = (taskIndex * 100 / taskCount);
	int dots = progress / 2;
	
	if(dots > _displayedDots)
	{
		while(dots != _displayedDots)
		{
			++_displayedDots;
			if(_displayedDots % 5 == 0)
				Logger::Info << ((_displayedDots/5)*10) << '%';
			else
				Logger::Info << '.';
		}
		if(progress == 100)
			Logger::Info << '\n';
		Logger::Info.Flush();
	}
}