Skip to content

Commit

Permalink
Implement arithmetic operators for issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
moshiba committed Jan 18, 2020
1 parent 8141542 commit 31b542d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pbar/pbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ std::string ProgressBar::format_meter() {
<< aesc::render::reset;
// Inject running-bar
int processed =
bar_width * this->n / this->total;
int processed = bar_width * this->n / this->total;
int remaining = bar_width - processed;
if (bar_width > 0) {
Expand Down Expand Up @@ -266,4 +265,26 @@ void ProgressBar::reset() {
this->display();
}
ProgressBar& ProgressBar::operator+=(const int n) {
this->update(n);
return *this;
}
ProgressBar& ProgressBar::operator-=(const int n) {
this->update(-n);
return *this;
}
// prefix
ProgressBar& ProgressBar::operator++() {
this->update(1);
return *this;
}
// prefix
ProgressBar& ProgressBar::operator--() {
this->update(-1);
return *this;
}
} // namespace pbar
6 changes: 6 additions & 0 deletions pbar/pbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class ProgressBar {
void update(const int n = 1);
void close();
void reset();

ProgressBar& operator+=(const int n);
ProgressBar& operator-=(const int n);
// prefix
ProgressBar& operator++();
ProgressBar& operator--();
};

} // namespace pbar
Expand Down

0 comments on commit 31b542d

Please sign in to comment.