-
Notifications
You must be signed in to change notification settings - Fork 1
/
gauge.h
executable file
·63 lines (51 loc) · 1.49 KB
/
gauge.h
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
56
57
58
59
60
61
62
63
#ifndef GAUGE_H
#define GAUGE_H
#include "common.h"
#include <iostream>
namespace aw {
struct gauge_exp {
unsigned int counter, modifier;
};
inline void gauge_init(gauge_exp * d) {
d->counter = 0;
d->modifier = 1;
}
inline void gauge_inc(gauge_exp * d) {
++d->counter;
if ((d->counter % d->modifier) == 0) {
MSG_nonewline(d->modifier << "..");
d->modifier *= 10;
}
}
inline void gauge_end(gauge_exp * d) {
MSG(d->counter);
gauge_init(d);
}
// -----------------------------------------------------------------------------------
struct gauge_percent {
unsigned int counter, last, max, steps;
};
inline void gauge_init(gauge_percent * d, unsigned int _max, unsigned int _steps = 10) {
d->counter = 0;
d->last = 0;
d->max = _max;
d->steps = _steps;
}
inline void gauge_inc(gauge_percent * d) {
if (d->counter == 0) MSG_nonewline("0%");
++d->counter;
if (d->last < d->counter) {
unsigned int v1 = (d->last * d->steps) / d->max;
unsigned int v2 = (d->counter * d->steps) / d->max;
if (v1 != v2) {
MSG_nonewline(".." << (v2 * 100 / d->steps) << '%');
}
d->last = d->counter;
}
}
inline void gauge_end(gauge_percent * d) {
MSG("");
gauge_init(d,d->max,d->steps);
}
} // end of namespace
#endif // GAUGE_H