0.5.5
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Classes | 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 31 of file progress_indicator.h.

#include <progress_indicator.h>

Classes

struct  progress_state
 

Public Member Functions

 progress_indicator ()
 
 progress_indicator (std::ostream &ostream)
 
void add_progress_bar (const std::string &name, size_t max, indicators::Color color)
 
void increment (const std::string &name)
 
void stop ()
 
void complete (const std::string &name)
 
void fail (const std::string &name)
 

Private Attributes

indicators::DynamicProgress< indicators::ProgressBar > progress_bars_
 
std::vector< std::shared_ptr< indicators::ProgressBar > > bars_
 
std::map< std::string, progress_stateprogress_bar_index_
 
std::mutex progress_bars_mutex_
 
std::ostream & ostream_
 

Constructor & Destructor Documentation

◆ progress_indicator() [1/2]

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

Definition at line 25 of file progress_indicator.cc.

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

◆ progress_indicator() [2/2]

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

Definition at line 30 of file progress_indicator.cc.

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

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 
)

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

Definition at line 36 of file progress_indicator.cc.

38{
39 auto postfix_text = max > 0 ? fmt::format("{}/{}", 0, max) : std::string{};
40
41 const auto kBarWidth = 35U;
42 const auto kPrefixTextWidth = 25U;
43
44 auto bar = std::make_shared<indicators::ProgressBar>(
45 indicators::option::Stream{ostream_},
46 indicators::option::BarWidth{kBarWidth},
47 indicators::option::ForegroundColor{color},
48 indicators::option::ShowElapsedTime{true},
49#if _MSC_VER
50 indicators::option::Fill{"="}, indicators::option::Lead{">"},
51#else
52 indicators::option::Fill{"█"}, indicators::option::Lead{"█"},
53#endif
54 indicators::option::Remainder{"-"},
55 indicators::option::PrefixText{
56 fmt::format("{:<25}", util::abbreviate(name, kPrefixTextWidth))},
57 indicators::option::PostfixText{postfix_text});
58
60
61 progress_bars_.push_back(*bar);
62 bars_.push_back(bar);
63 auto bar_index = bars_.size() - 1;
64 progress_bar_index_.emplace(name, progress_state{bar_index, 0, max});
65
66 progress_bars_mutex_.unlock();
67}

◆ complete()

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

Set specified progress bar as complete.

Parameters
nameName of the progress bar

Definition at line 103 of file progress_indicator.cc.

104{
105 const auto kCompleteProgressPercent = 100U;
106
108
109 if (progress_bar_index_.count(name) == 0) {
110 progress_bars_mutex_.unlock();
111 return;
112 }
113
114 auto &p = progress_bar_index_.at(name);
115 auto &bar = progress_bars_[p.index];
116
117 p.progress = p.max;
118
119 bar.set_progress(kCompleteProgressPercent);
120
121#if _MSC_VER
122 const auto postfix_text = fmt::format("{}/{} OK", p.progress, p.max);
123#else
124 const auto postfix_text = fmt::format("{}/{} ✔", p.progress, p.max);
125#endif
126 bar.set_option(indicators::option::PostfixText{postfix_text});
127 bar.set_option(
128 indicators::option::ForegroundColor{indicators::Color::green});
129 bar.mark_as_completed();
130
131 progress_bars_mutex_.unlock();
132}

◆ fail()

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

Set progress bar as failed.

Parameters
nameName of the progress bar

Definition at line 134 of file progress_indicator.cc.

135{
137
138 if (progress_bar_index_.count(name) == 0) {
139 progress_bars_mutex_.unlock();
140 return;
141 }
142
143 auto &p = progress_bar_index_.at(name);
144 auto &bar = progress_bars_[p.index];
145
146#if _MSC_VER
147 const auto postfix_text = fmt::format("{}/{} FAILED", p.progress, p.max);
148#else
149 const auto postfix_text = fmt::format("{}/{} ✗", p.progress, p.max);
150#endif
151 bar.set_option(indicators::option::ForegroundColor{indicators::Color::red});
152 bar.set_option(indicators::option::PostfixText{postfix_text});
153 bar.mark_as_completed();
154
155 progress_bars_mutex_.unlock();
156}

◆ increment()

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

Increment specified progress bar.

Parameters
nameName of the progress bar

Definition at line 69 of file progress_indicator.cc.

70{
71 const auto kASTTraverseProgressPercent = 95U;
72
74
75 if (progress_bar_index_.count(name) == 0) {
76 progress_bars_mutex_.unlock();
77 return;
78 }
79
80 auto &p = progress_bar_index_.at(name);
81 auto &bar = progress_bars_[p.index];
82
83 p.progress++;
84
85 bar.set_progress((p.progress * kASTTraverseProgressPercent) / p.max);
86 bar.set_option(indicators::option::PostfixText{
87 fmt::format("{}/{}", p.progress, p.max)});
88
89 progress_bars_mutex_.unlock();
90}

◆ stop()

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

Stop all the progress bars.

Definition at line 92 of file progress_indicator.cc.

93{
95
96 for (auto &[name, p] : progress_bar_index_) {
97 progress_bars_[p.index].mark_as_completed();
98 }
99
100 progress_bars_mutex_.unlock();
101}

Member Data Documentation

◆ bars_

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

Definition at line 88 of file progress_indicator.h.

◆ ostream_

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

Definition at line 91 of file progress_indicator.h.

◆ progress_bar_index_

std::map<std::string, progress_state> clanguml::common::generators::progress_indicator::progress_bar_index_
private

Definition at line 89 of file progress_indicator.h.

◆ progress_bars_

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

Definition at line 87 of file progress_indicator.h.

◆ progress_bars_mutex_

std::mutex clanguml::common::generators::progress_indicator::progress_bars_mutex_
private

Definition at line 90 of file progress_indicator.h.


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