Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
SimpleProgressBar Class Reference

Simple Progress Bar. More...

#include <ored/utilities/progressbar.hpp>

+ Inheritance diagram for SimpleProgressBar:
+ Collaboration diagram for SimpleProgressBar:

Public Member Functions

 SimpleProgressBar (const std::string &message, const QuantLib::Size messageWidth=40, const QuantLib::Size barWidth=40, const QuantLib::Size numberOfScreenUpdates=100)
 
void updateProgress (const unsigned long progress, const unsigned long total, const std::string &detail) override
 ProgressIndicator interface. More...
 
void reset () override
 
- Public Member Functions inherited from ProgressIndicator
 ProgressIndicator ()
 
virtual ~ProgressIndicator ()
 
virtual void updateProgress (const unsigned long progress, const unsigned long total, const std::string &detail)=0
 
virtual void reset ()=0
 

Private Attributes

std::string key_
 
unsigned int messageWidth_
 
unsigned int barWidth_
 
unsigned int numberOfScreenUpdates_
 
unsigned int updateCounter_
 
bool finalized_
 

Detailed Description

Simple Progress Bar.

Simple Progress Bar that writes a message followed by a status bar to std::cout, no other output should be written to std::cout during the bar from this instance is displayed

Definition at line 85 of file progressbar.hpp.

Constructor & Destructor Documentation

◆ SimpleProgressBar()

SimpleProgressBar ( const std::string &  message,
const QuantLib::Size  messageWidth = 40,
const QuantLib::Size  barWidth = 40,
const QuantLib::Size  numberOfScreenUpdates = 100 
)

Definition at line 47 of file progressbar.cpp.

49 : key_(message), messageWidth_(messageWidth), barWidth_(barWidth),
50 numberOfScreenUpdates_(numberOfScreenUpdates), updateCounter_(0), finalized_(false) {
51 updateProgress(0, 1, "");
53}
void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail) override
ProgressIndicator interface.
Definition: progressbar.cpp:55
unsigned int numberOfScreenUpdates_
Definition: progressbar.hpp:96
+ Here is the call graph for this function:

Member Function Documentation

◆ updateProgress()

void updateProgress ( const unsigned long  progress,
const unsigned long  total,
const std::string &  detail 
)
overridevirtual

ProgressIndicator interface.

Implements ProgressIndicator.

Definition at line 55 of file progressbar.cpp.

55 {
56 if (!ConsoleLog::instance().enabled())
57 return;
58 if (finalized_)
59 return;
60 double ratio = static_cast<double>(progress) / static_cast<double>(total);
61 if (progress >= total) {
62 std::cout << "\r" << std::setw(messageWidth_) << std::left << key_;
63 for (unsigned int i = 0; i < barWidth_; ++i)
64 std::cout << " ";
65 std::cout << " \r";
66 std::cout << std::setw(messageWidth_) << std::left << key_;
67 std::cout.flush();
68 finalized_ = true;
69 return;
70 }
71 if (updateCounter_ > 0 && progress * numberOfScreenUpdates_ < updateCounter_ * total) {
72 return;
73 }
74 std::cout << "\r" << std::setw(messageWidth_) << std::left << key_;
75 if (barWidth_ > 0)
76 std::cout << "[";
77 unsigned int pos = static_cast<unsigned int>(static_cast<double>(barWidth_) * ratio);
78 for (unsigned int i = 0; i < barWidth_; ++i) {
79 if (i < pos)
80 std::cout << "=";
81 else if (i == pos && pos != 0)
82 std::cout << ">";
83 else
84 std::cout << " ";
85 }
86 if (barWidth_ > 0)
87 std::cout << "] ";
88 std::cout << static_cast<int>(ratio * 100.0) << " %\r";
89 std::cout.flush();
91}
+ Here is the caller graph for this function:

◆ reset()

void reset ( )
overridevirtual

Implements ProgressIndicator.

Definition at line 93 of file progressbar.cpp.

93 {
95 finalized_ = false;
96}

Member Data Documentation

◆ key_

std::string key_
private

Definition at line 95 of file progressbar.hpp.

◆ messageWidth_

unsigned int messageWidth_
private

Definition at line 96 of file progressbar.hpp.

◆ barWidth_

unsigned int barWidth_
private

Definition at line 96 of file progressbar.hpp.

◆ numberOfScreenUpdates_

unsigned int numberOfScreenUpdates_
private

Definition at line 96 of file progressbar.hpp.

◆ updateCounter_

unsigned int updateCounter_
private

Definition at line 96 of file progressbar.hpp.

◆ finalized_

bool finalized_
private

Definition at line 97 of file progressbar.hpp.