blob: cb4459a7478bc956c5f262d29cff0731be89efd0 (
plain)
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
|
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <samples/console_progress.hpp>
/// @brief Responsible for progress bar handling within the dla_benchmark
class ProgressBar {
public:
explicit ProgressBar(size_t totalNum, bool streamOutput = false, bool progressEnabled = false) {
_bar.reset(new ConsoleProgress(totalNum, streamOutput));
_streamOutput = streamOutput;
_isFinished = true;
_progressEnabled = progressEnabled;
}
void addProgress(size_t num) {
_isFinished = false;
if (_progressEnabled) {
_bar->addProgress(num);
}
}
void finish(size_t num = 0) {
if (num > 0) {
addProgress(num);
}
_isFinished = true;
_bar->finish();
if (_progressEnabled) {
std::cout << std::endl;
}
}
void newBar(size_t totalNum) {
if (_isFinished) {
_bar.reset(new ConsoleProgress(totalNum, _streamOutput));
} else {
throw std::logic_error("Cannot create a new bar. Current bar is still in progress");
}
}
private:
std::unique_ptr<ConsoleProgress> _bar;
bool _streamOutput;
bool _isFinished;
bool _progressEnabled;
};
|