OpenMEEG
Loading...
Searching...
No Matches
OpenMEEG
include
progressbar.h
Go to the documentation of this file.
1
// Project Name: OpenMEEG (http://openmeeg.github.io)
2
// © INRIA and ENPC under the French open source license CeCILL-B.
3
// See full copyright notice in the file LICENSE.txt
4
// If you make a copy of this file, you must either:
5
// - provide also LICENSE.txt and modify this header to refer to it.
6
// - replace this header by the LICENSE.txt content.
7
8
#pragma once
9
10
#ifndef USE_PROGRESSBAR
11
#include <cmath>
12
#include <
logger.h
>
13
#endif
14
15
namespace
OpenMEEG
{
16
#ifndef USE_PROGRESSBAR
17
class
ProgressBar
{
18
public
:
19
20
ProgressBar
(
const
unsigned
n,
const
unsigned
sz=20): max_iter(n),bar_size(sz) { }
21
22
void
operator++
() {
23
const
unsigned
p = std::min(
static_cast<
unsigned
>
(floor(
static_cast<
double
>
((bar_size+1)*iter++)/max_iter)),bar_size);
24
if
(p!=pprev && iter>1) {
25
log_stream
(
PROGRESS
) << std::string(bar_size+2,
'\b'
) <<
'['
<< std::string(p,
'*'
) << std::string(bar_size-p,
'.'
) <<
']'
;
26
pprev = p;
27
}
28
if
(iter>=max_iter)
29
log_stream
(
PROGRESS
) << std::endl;
30
log_stream
(
PROGRESS
).flush();
31
}
32
33
private
:
34
35
unsigned
iter = 0;
36
unsigned
pprev = -1;
37
const
unsigned
max_iter;
38
const
unsigned
bar_size;
39
};
40
#else
41
class
ProgressBar {
42
public
:
43
44
ProgressBar
(
const
unsigned
,
const
unsigned
=20) { }
45
void
operator++
() { }
46
};
47
#endif
48
}
OpenMEEG::ProgressBar
Definition
progressbar.h:17
OpenMEEG::ProgressBar::ProgressBar
ProgressBar(const unsigned n, const unsigned sz=20)
Definition
progressbar.h:20
OpenMEEG::ProgressBar::operator++
void operator++()
Definition
progressbar.h:22
logger.h
OpenMEEG
Definition
analytics.h:14
OpenMEEG::log_stream
std::ostream & log_stream(const InfoLevel level)
Definition
logger.h:39
OpenMEEG::PROGRESS
@ PROGRESS
Definition
logger.h:15
Generated by
1.12.0