1 // Copyright (C) 2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
11 * @class ConsoleProgress
12 * @brief A ConsoleProgress class provides functionality for printing progress dynamics
14 class ConsoleProgress {
15 static const int DEFAULT_DETALIZATION = 20;
24 * @brief A constructor of ConsoleProgress class
25 * @param _total - maximum value that is correspondent to 100%
26 * @param _detalization - number of symbols(.) to use to represent progress
28 explicit ConsoleProgress(size_t _total, bool _stream_output = false, size_t _detalization = DEFAULT_DETALIZATION) :
29 total(_total), detalization(_detalization) {
30 stream_output = _stream_output;
37 * @brief Shows progress with current data. Progress is shown from the beginning of the current line.
40 void showProgress() const {
41 std::cout << "\rProgress: [";
43 for (; i < detalization * current / total; i++) {
46 for (; i < detalization; i++) {
49 std::cout << "] " << std::fixed << std::setprecision(2) << 100 * static_cast<float>(current) / total << "% done";
51 std::cout << std::endl;
53 std::flush(std::cout);
58 * @brief Updates current value and progressbar
59 * @param newProgress - new value to represent
61 void updateProgress(size_t newProgress) {
62 current = newProgress;
63 if (current > total) current = total;
68 * @brief Adds value to currently represented and redraw progressbar
69 * @param add - value to add
71 void addProgress(int add) {
72 if (add < 0 && -add > static_cast<int>(current)) {
73 add = -static_cast<int>(current);
75 updateProgress(current + add);
79 * @brief Output end line.