Learning Curve Plus Plus (LCPP)
progress.h
Go to the documentation of this file.
1 /**
2  * @file progress.h
3  * @author Ozgur Taylan Turan
4  *
5  * Simple Progress thread safe progress bar for Learning Curve Generation
6  * tracking
7  */
8 
9 #ifndef __PROGRESS_H
10 #define __PROGRESS_H
11 namespace utils {
12 //-----------------------------------------------------------------------------
13 // ProgresssBar : A Simple Progress Bar that shows the perc. of your loop
14 //-----------------------------------------------------------------------------
16 {
17 public:
18  ProgressBar(int total) : tot_(total), curr_(0), what_("Loop")
19  { }
20  ProgressBar(std::string what, int total) : tot_(total), curr_(0), what_(what)
21  { }
22 
23  void Update()
24  {
25  #pragma omp critical
26  {
27  ++curr_;
28  Show();
29  }
30  }
31 
32 private:
33  int tot_;
34  int curr_;
35  std::string what_;
36 
37  void Show()
38  {
39  double prog = static_cast<double>(curr_) / tot_;
40  int perc = static_cast<int>(prog * 100.0);
41  std::cout << "\r" << std::setw(3) << perc << " %"
42  << " : " << what_ << std::flush;
43  if (curr_ == tot_)
44  std::cout << "\n\n" ;
45 
46  }
47 };
48 } // namespace utils
49 
50 #endif