0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
progress_indicator.h
Go to the documentation of this file.
1/**
2 * @file src/common/generators/progress_indicator.h
3 *
4 * Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#pragma once
19
20#include <indicators/indicators.hpp>
21
22#include <map>
23#include <memory>
24#include <vector>
25
27
29public:
31 explicit progress_state(size_t i, size_t p, size_t m)
32 : index{i}
33 , progress{p}
34 , max{m}
35 {
36 }
37
38 size_t index;
39 size_t progress;
40 size_t max;
41 };
42
43 virtual ~progress_indicator_base() = default;
44
45 /**
46 * Add a new progress bar to the indicator set
47 *
48 * @param name Name (prefix) of the progress bar
49 * @param max Total number of steps in the progress bar
50 * @param color Color of the progress bar
51 */
52 virtual void add_progress_bar(
53 const std::string &name, size_t max, indicators::Color color) = 0;
54
55 /**
56 * Increment specified progress bar.
57 *
58 * @param name Name of the progress bar
59 */
60 virtual void increment(const std::string &name) = 0;
61
62 /**
63 * Stop all the progress bars.
64 */
65 virtual void stop() = 0;
66
67 /**
68 * Set specified progress bar as complete.
69 *
70 * @param name Name of the progress bar
71 */
72 virtual void complete(const std::string &name) = 0;
73
74 /**
75 * Set progress bar as failed.
76 *
77 * @param name Name of the progress bar
78 */
79 virtual void fail(const std::string &name) = 0;
80
81protected:
82 std::map<std::string, progress_state> progress_bar_index_;
84};
85
87public:
89
90 ~json_logger_progress_indicator() override = default;
91
93 const std::string &name, size_t max, indicators::Color color) override;
94
95 void increment(const std::string &name) override;
96
97 void stop() override { }
98
99 void complete(const std::string &name) override;
100
101 void fail(const std::string &name) override;
102};
103
104/**
105 * @brief Container for diagram generation progress indicators
106 */
108public:
110
111 progress_indicator(std::ostream &ostream);
112
113 ~progress_indicator() override = default;
114
115 void add_progress_bar(
116 const std::string &name, size_t max, indicators::Color color) override;
117
118 void increment(const std::string &name) override;
119
120 void stop() override;
121
122 void complete(const std::string &name) override;
123
124 void fail(const std::string &name) override;
125
126private:
127 indicators::DynamicProgress<indicators::ProgressBar> progress_bars_;
128 std::vector<std::shared_ptr<indicators::ProgressBar>> bars_;
129 std::ostream &ostream_;
130};
131} // namespace clanguml::common::generators