0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
clanguml::common::generators::progress_indicator Class Reference

Container for diagram generation progress indicators. More...

Detailed Description

Container for diagram generation progress indicators.

Definition at line 107 of file progress_indicator.h.

#include <progress_indicator.h>

Public Member Functions

 progress_indicator ()
 
 progress_indicator (std::ostream &ostream)
 
 ~progress_indicator () override=default
 
void add_progress_bar (const std::string &name, size_t max, indicators::Color color) override
 
void increment (const std::string &name) override
 
void stop () override
 
void complete (const std::string &name) override
 
void fail (const std::string &name) override
 
- Public Member Functions inherited from clanguml::common::generators::progress_indicator_base
virtual ~progress_indicator_base ()=default
 
virtual void add_progress_bar (const std::string &name, size_t max, indicators::Color color)=0
 
virtual void increment (const std::string &name)=0
 
virtual void stop ()=0
 
virtual void complete (const std::string &name)=0
 
virtual void fail (const std::string &name)=0
 

Private Attributes

indicators::DynamicProgress< indicators::ProgressBar > progress_bars_
 
std::vector< std::shared_ptr< indicators::ProgressBar > > bars_
 
std::ostream & ostream_
 

Additional Inherited Members

- Protected Attributes inherited from clanguml::common::generators::progress_indicator_base
std::map< std::string, progress_stateprogress_bar_index_
 
std::mutex progress_bars_mutex_
 

Constructor & Destructor Documentation

◆ progress_indicator() [1/2]

clanguml::common::generators::progress_indicator::progress_indicator ( )

Definition at line 26 of file progress_indicator.cc.

27 : progress_indicator(std::cout)
28{
29}

◆ progress_indicator() [2/2]

clanguml::common::generators::progress_indicator::progress_indicator ( std::ostream &  ostream)

Definition at line 31 of file progress_indicator.cc.

32 : ostream_(ostream)
33{
34 progress_bars_.set_option(indicators::option::HideBarWhenComplete{false});
35}

◆ ~progress_indicator()

clanguml::common::generators::progress_indicator::~progress_indicator ( )
overridedefault

Member Function Documentation

◆ add_progress_bar()

void clanguml::common::generators::progress_indicator::add_progress_bar ( const std::string &  name,
size_t  max,
indicators::Color  color 
)
overridevirtual

Add a new progress bar to the indicator set

Parameters
nameName (prefix) of the progress bar
maxTotal number of steps in the progress bar
colorColor of the progress bar

Implements clanguml::common::generators::progress_indicator_base.

Definition at line 56 of file progress_indicator.cc.

58{
59 auto postfix_text = max > 0 ? fmt::format("{}/{}", 0, max) : std::string{};
60
61 const auto kBarWidth = 35U;
62 const auto kPrefixTextWidth = 25U;
63
64 auto bar = std::make_shared<indicators::ProgressBar>(
65 indicators::option::Stream{ostream_},
66 indicators::option::BarWidth{kBarWidth},
67 indicators::option::ForegroundColor{color},
68 indicators::option::ShowElapsedTime{true},
69#if _MSC_VER
70 indicators::option::Fill{"="}, indicators::option::Lead{">"},
71#else
72 indicators::option::Fill{"█"}, indicators::option::Lead{"█"},
73#endif
74 indicators::option::Remainder{"-"},
75 indicators::option::PrefixText{
76 fmt::format("{:<25}", util::abbreviate(name, kPrefixTextWidth))},
77 indicators::option::PostfixText{postfix_text});
78
80
81 progress_bars_.push_back(*bar);
82 bars_.push_back(bar);
83 auto bar_index = bars_.size() - 1;
84 progress_bar_index_.emplace(name, progress_state{bar_index, 0, max});
85
86 progress_bars_mutex_.unlock();
87}

◆ complete()

void clanguml::common::generators::progress_indicator::complete ( const std::string &  name)
overridevirtual

Set specified progress bar as complete.

Parameters
nameName of the progress bar

Implements clanguml::common::generators::progress_indicator_base.

Definition at line 175 of file progress_indicator.cc.

176{
177 const auto kCompleteProgressPercent = 100U;
178
180
181 if (progress_bar_index_.count(name) == 0) {
182 progress_bars_mutex_.unlock();
183 return;
184 }
185
186 auto &p = progress_bar_index_.at(name);
187 auto &bar = progress_bars_[p.index];
188
189 p.progress = p.max;
190
191 bar.set_progress(kCompleteProgressPercent);
192
193#if _MSC_VER
194 const auto postfix_text = fmt::format("{}/{} OK", p.progress, p.max);
195#else
196 const auto postfix_text = fmt::format("{}/{} ✔", p.progress, p.max);
197#endif
198 bar.set_option(indicators::option::PostfixText{postfix_text});
199 bar.set_option(
200 indicators::option::ForegroundColor{indicators::Color::green});
201 bar.mark_as_completed();
202
203 progress_bars_mutex_.unlock();
204}

◆ fail()

void clanguml::common::generators::progress_indicator::fail ( const std::string &  name)
overridevirtual

Set progress bar as failed.

Parameters
nameName of the progress bar

Implements clanguml::common::generators::progress_indicator_base.

Definition at line 229 of file progress_indicator.cc.

230{
232
233 if (progress_bar_index_.count(name) == 0) {
234 progress_bars_mutex_.unlock();
235 return;
236 }
237
238 auto &p = progress_bar_index_.at(name);
239 auto &bar = progress_bars_[p.index];
240
241#if _MSC_VER
242 const auto postfix_text = fmt::format("{}/{} FAILED", p.progress, p.max);
243#else
244 const auto postfix_text = fmt::format("{}/{} ✗", p.progress, p.max);
245#endif
246 bar.set_option(indicators::option::ForegroundColor{indicators::Color::red});
247 bar.set_option(indicators::option::PostfixText{postfix_text});
248 bar.mark_as_completed();
249
250 progress_bars_mutex_.unlock();
251}

◆ increment()

void clanguml::common::generators::progress_indicator::increment ( const std::string &  name)
overridevirtual

Increment specified progress bar.

Parameters
nameName of the progress bar

Implements clanguml::common::generators::progress_indicator_base.

Definition at line 115 of file progress_indicator.cc.

116{
117 const auto kASTTraverseProgressPercent = 95U;
118
120
121 if (progress_bar_index_.count(name) == 0) {
122 progress_bars_mutex_.unlock();
123 return;
124 }
125
126 auto &p = progress_bar_index_.at(name);
127 auto &bar = progress_bars_[p.index];
128
129 p.progress++;
130
131 bar.set_progress((p.progress * kASTTraverseProgressPercent) / p.max);
132 bar.set_option(indicators::option::PostfixText{
133 fmt::format("{}/{}", p.progress, p.max)});
134
135 progress_bars_mutex_.unlock();
136}

◆ stop()

void clanguml::common::generators::progress_indicator::stop ( )
overridevirtual

Stop all the progress bars.

Implements clanguml::common::generators::progress_indicator_base.

Definition at line 138 of file progress_indicator.cc.

139{
141
142 for (auto &[name, p] : progress_bar_index_) {
143 progress_bars_[p.index].mark_as_completed();
144 }
145
146 progress_bars_mutex_.unlock();
147}

Member Data Documentation

◆ bars_

std::vector<std::shared_ptr<indicators::ProgressBar> > clanguml::common::generators::progress_indicator::bars_
private

Definition at line 128 of file progress_indicator.h.

◆ ostream_

std::ostream& clanguml::common::generators::progress_indicator::ostream_
private

Definition at line 129 of file progress_indicator.h.

◆ progress_bars_

indicators::DynamicProgress<indicators::ProgressBar> clanguml::common::generators::progress_indicator::progress_bars_
private

Definition at line 127 of file progress_indicator.h.


The documentation for this class was generated from the following files: