Files
openvino/samples/cpp/benchmark_app/progress_bar.hpp

53 lines
1.3 KiB
C++
Raw Normal View History

// Copyright (C) 2018-2022 Intel Corporation
2019-04-12 18:25:53 +03:00
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include "samples/console_progress.hpp"
2019-04-12 18:25:53 +03:00
/// @brief Responsible for progress bar handling within the benchmark_app
class ProgressBar {
public:
2019-08-09 19:02:42 +03:00
explicit ProgressBar(size_t totalNum, bool streamOutput = false, bool progressEnabled = false) {
_bar.reset(new ConsoleProgress(totalNum, streamOutput));
_streamOutput = streamOutput;
2019-04-12 18:25:53 +03:00
_isFinished = true;
2019-08-09 19:02:42 +03:00
_progressEnabled = progressEnabled;
2019-04-12 18:25:53 +03:00
}
void add_progress(size_t num) {
2019-04-12 18:25:53 +03:00
_isFinished = false;
2019-08-09 19:02:42 +03:00
if (_progressEnabled) {
_bar->addProgress(num);
}
2019-04-12 18:25:53 +03:00
}
2019-08-09 19:02:42 +03:00
void finish(size_t num = 0) {
if (num > 0) {
add_progress(num);
2019-08-09 19:02:42 +03:00
}
2019-04-12 18:25:53 +03:00
_isFinished = true;
_bar->finish();
2019-08-09 19:02:42 +03:00
if (_progressEnabled) {
std::cout << std::endl;
}
2019-04-12 18:25:53 +03:00
}
void new_bar(size_t totalNum) {
2019-04-12 18:25:53 +03:00
if (_isFinished) {
2019-08-09 19:02:42 +03:00
_bar.reset(new ConsoleProgress(totalNum, _streamOutput));
2019-04-12 18:25:53 +03:00
} else {
2019-08-09 19:02:42 +03:00
throw std::logic_error("Cannot create a new bar. Current bar is still in progress");
2019-04-12 18:25:53 +03:00
}
}
private:
std::unique_ptr<ConsoleProgress> _bar;
2019-08-09 19:02:42 +03:00
bool _streamOutput;
2019-04-12 18:25:53 +03:00
bool _isFinished;
2019-08-09 19:02:42 +03:00
bool _progressEnabled;
};