BmnRoot
Loading...
Searching...
No Matches
BmnSimpleProgressBar.h
Go to the documentation of this file.
1
/*
2
BM@N alignment routine
3
BM@N experiment at NICA complex, JINR, 2025
4
5
Department: Math & Soft Group of HEP lab
6
Author: Igor Polev, polev@jinr.ru
7
8
BmnSimpleProgressBar class header-only implementation
9
Primitive progress bar with some thread-safety
10
*/
11
12
#ifndef BMNSIMPLEPROGRESSBAR_H
13
#define BMNSIMPLEPROGRESSBAR_H
14
15
#include <iostream>
16
#include <mutex>
17
#include <string>
18
19
class
BmnSimpleProgressBar
20
{
21
private
:
22
bool
show{
false
};
23
int
done{0};
24
std::string bar{
"\r [ ] "
};
// with 50 spaces
25
std::mutex mtx;
26
27
inline
void
Print() { std::cout << bar << done <<
"%\r"
<< std::flush; }
28
29
public
:
30
inline
BmnSimpleProgressBar
() =
default
;
31
inline
void
Init
();
32
inline
void
Tick
();
33
inline
void
Clear
();
34
};
35
36
inline
void
BmnSimpleProgressBar::Clear
()
37
{
38
show =
false
;
39
std::cout <<
"\r \r"
<< std::flush;
40
}
41
42
inline
void
BmnSimpleProgressBar::Init
()
43
{
44
done = 0;
45
for
(
int
i
= 3;
i
< 53;
i
++)
46
bar[
i
] =
' '
;
47
Clear
();
48
Print();
49
show =
true
;
50
}
51
52
inline
void
BmnSimpleProgressBar::Tick
()
53
{
54
if
(!show)
55
return
;
56
57
std::lock_guard<std::mutex> lock{mtx};
58
if
(done >= 100) {
59
show =
false
;
60
return
;
61
}
62
if
(done % 2)
63
bar[done / 2 + 3] =
'='
;
64
else
65
bar[done / 2 + 3] =
'-'
;
66
Print();
67
done++;
68
}
69
70
#endif
// BMNSIMPLEPROGRESSBAR_H
i
int i
Definition
P4_F32vec4.h:22
BmnSimpleProgressBar
Definition
BmnSimpleProgressBar.h:20
BmnSimpleProgressBar::Tick
void Tick()
Definition
BmnSimpleProgressBar.h:52
BmnSimpleProgressBar::Init
void Init()
Definition
BmnSimpleProgressBar.h:42
BmnSimpleProgressBar::BmnSimpleProgressBar
BmnSimpleProgressBar()=default
BmnSimpleProgressBar::Clear
void Clear()
Definition
BmnSimpleProgressBar.h:36
align_new
src
BmnSimpleProgressBar.h
Generated on Fri May 15 2026 10:40:50 for BmnRoot by
1.9.8