SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
ProgressBar.hh
1 #ifndef PROGRESSBAR_HH
2 #define PROGRESSBAR_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <unistd.h>
7 #include <chrono>
8 #include <sys/ioctl.h>
9 
10 // Additional includes
11 #include "Pitch.hh"
12 
13 typedef std::chrono::time_point<std::chrono::system_clock> time_stamp;
14 
20 class ProgressBar {
21  public:
22 
24  ProgressBar(Pitch::errorLevel level=Pitch::info);
25 
27  ProgressBar(const ProgressBar& pbar);
28 
30  ProgressBar& operator=(const ProgressBar& pbar);
31 
33  ~ProgressBar();
34 
36  void SetStartTime(time_stamp start) { _start = start; }
37 
39  const time_stamp& GetStartTime() { return _start; }
40 
42  void SetCurrentTime(time_stamp current) { _current = current; }
43 
45  const time_stamp& GetCurrentTime() { return _current; }
46 
48  void SetTerminalWidth(size_t twidth) { _twidth = twidth; }
49 
51  const size_t& GetTerminalWidth() { return _twidth; }
52 
54  void SetVerbosityLevel(Pitch::errorLevel level) { _level = level; }
55 
58 
64  void GetProgress(const size_t n, const size_t N);
65 
66  private:
68  void FetchTerminalWidth();
69 
75  void PrintProgress(const size_t pc, const size_t n);
76 
77  time_stamp _start;
78  time_stamp _current;
79  size_t _twidth;
81 };
82 
83 #endif
const time_stamp & GetStartTime()
Gets the start of execution time.
Definition: ProgressBar.hh:39
void FetchTerminalWidth()
Fetch the terminal width from the OS.
Definition: ProgressBar.cc:41
~ProgressBar()
Destructor.
Definition: ProgressBar.cc:28
size_t _twidth
Terminal width.
Definition: ProgressBar.hh:79
void SetTerminalWidth(size_t twidth)
Sets the width of the terminal.
Definition: ProgressBar.hh:48
time_stamp _start
Start time.
Definition: ProgressBar.hh:77
Pitch::errorLevel _level
Verbosity level.
Definition: ProgressBar.hh:80
time_stamp _current
Current time.
Definition: ProgressBar.hh:78
ProgressBar(Pitch::errorLevel level=Pitch::info)
Default constructor, sets the output to Pitch::info.
Definition: ProgressBar.cc:3
void SetCurrentTime(time_stamp current)
Sets the current time.
Definition: ProgressBar.hh:42
void SetVerbosityLevel(Pitch::errorLevel level)
Sets the verbosity level.
Definition: ProgressBar.hh:54
void PrintProgress(const size_t pc, const size_t n)
Prints the bar for a given percentage of progress.
Definition: ProgressBar.cc:47
ProgressBar & operator=(const ProgressBar &pbar)
Equality operator.
Definition: ProgressBar.cc:16
const size_t & GetTerminalWidth()
Gets the width of the terminal.
Definition: ProgressBar.hh:51
const Pitch::errorLevel & GetVerbosityLevel()
Gets the verbosity level.
Definition: ProgressBar.hh:57
void SetStartTime(time_stamp start)
Sets the start of execution time.
Definition: ProgressBar.hh:36
void GetProgress(const size_t n, const size_t N)
Prints the current progress in the terminal.
Definition: ProgressBar.cc:30
const time_stamp & GetCurrentTime()
Gets the current time.
Definition: ProgressBar.hh:45
errorLevel
Error level that determines where the output goes.
Definition: Pitch.hh:43
Provides a progess bar to be included in a for loop.
Definition: ProgressBar.hh:20