Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F8723696
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/include/RHEJ/ProgressBar.hh b/include/RHEJ/ProgressBar.hh
index 7bf6cb2..88f07e0 100644
--- a/include/RHEJ/ProgressBar.hh
+++ b/include/RHEJ/ProgressBar.hh
@@ -1,64 +1,64 @@
#pragma once
#include <ostream>
-#include <cassert>
+#include <functional>
#include <stdexcept>
namespace RHEJ {
template<typename T>
class ProgressBar {
public:
ProgressBar(std::ostream & out, T max) :
out_{out}, max_{max}
{
if(max <= 0) {
throw std::invalid_argument{
"Maximum in progress bar has to be positive"
};
}
print_bar();
}
ProgressBar & increment(T count) {
counter_ += count;
update_progress();
return *this;
}
ProgressBar & operator++() {
++counter_;
update_progress();
return *this;
}
private:
void update_progress() {
counter_ = std::min(counter_, max_);
const int ndots = (100*counter_)/max_;
const int new_dots = ndots - ndots_;
if(new_dots > 0) {
- for(int dot = 0; dot < new_dots; ++dot) out_ << '.';
- out_.flush();
+ for(int dot = 0; dot < new_dots; ++dot) out_.get() << '.';
+ out_.get().flush();
ndots_ = ndots;
}
}
void print_bar() const {
- out_ << "0% ";
+ out_.get() << "0% ";
for(int i = 10; i <= 100; i+= 10){
- out_ << " " + std::to_string(i) + "%";
+ out_.get() << " " + std::to_string(i) + "%";
}
- out_ << "\n|";
+ out_.get() << "\n|";
for(int i = 10; i <= 100; i+= 10){
- out_ << "---------|";
+ out_.get() << "---------|";
}
- out_ << '\n';
+ out_.get() << '\n';
}
- std::ostream & out_;
+ std::reference_wrapper<std::ostream> out_;
T counter_ = 0;
T ndots_ = 0;
T max_;
};
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jan 20, 9:12 PM (23 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4242408
Default Alt Text
(1 KB)
Attached To
rHEJ HEJ
Event Timeline
Log In to Comment