Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Progress_Bar.cpp
Go to the documentation of this file.
2
3#include <iostream>
4
5namespace joedb
6{
7 //////////////////////////////////////////////////////////////////////////
9 //////////////////////////////////////////////////////////////////////////
10 (
11 const int64_t total,
12 std::ostream * const out,
13 const int64_t threshold
14 ):
15 total(total),
16 out(out),
17 threshold(threshold),
18 current_display(0)
19 {
20 if (out)
21 {
22 *out << ": size = " << total << '\n';
23 if (total > threshold)
24 *out << std::string(length, '.') << '\r';
25
26 out->flush();
27 }
28 }
29
30 //////////////////////////////////////////////////////////////////////////
31 void Progress_Bar::print(const int64_t current)
32 //////////////////////////////////////////////////////////////////////////
33 {
34 if (out && total > threshold)
35 {
36 const int display = int((current * length) / total);
37
38 if (display > current_display)
39 {
40 *out << std::string(display - current_display, '#');
41 out->flush();
42
43 current_display = display;
44 }
45 }
46 }
47
48 //////////////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////////
51 {
52 try
53 {
54 if (out)
55 {
56 if (total > threshold)
57 *out << '\n';
58 out->flush();
59 }
60 }
61 catch(...)
62 {
63 }
64 }
65}
void print(int64_t current)
Progress_Bar(int64_t total, std::ostream *out, int64_t threshold=16384)
Definition Blob.h:7