Beatmup
Beatmup::ProgressTracking Class Reference

Progress tracking utility. More...

#include <progress_tracking.h>

Public Member Functions

 ProgressTracking ()
 
 ProgressTracking (unsigned int max)
 
void reset (unsigned int max)
 Resets the progress to zero. More...
 
void operator() ()
 Increases progress by one step. More...
 
bool done () const
 
void printOutProgressBar (const unsigned int barLength=40) const
 Prints a fancy progress bar to standard output. More...
 

Static Public Attributes

static ProgressTracking DEVNULL
 

Private Attributes

unsigned int progress
 
unsigned int maxProgress
 

Detailed Description

Progress tracking utility.

Definition at line 25 of file progress_tracking.h.

Constructor & Destructor Documentation

◆ ProgressTracking() [1/2]

Beatmup::ProgressTracking::ProgressTracking ( )
inline

Definition at line 31 of file progress_tracking.h.

◆ ProgressTracking() [2/2]

Beatmup::ProgressTracking::ProgressTracking ( unsigned int  max)
inline

Definition at line 32 of file progress_tracking.h.

32 : progress(0), maxProgress(max) {}
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:728

Member Function Documentation

◆ reset()

void Beatmup::ProgressTracking::reset ( unsigned int  max)
inline

Resets the progress to zero.

Parameters
[in]maxNew maximum progress

Definition at line 38 of file progress_tracking.h.

38  {
39  this->progress = 0;
40  this->maxProgress = max;
41  }

◆ operator()()

void Beatmup::ProgressTracking::operator() ( )
inline

Increases progress by one step.

Definition at line 46 of file progress_tracking.h.

46 { progress++; }

◆ done()

bool Beatmup::ProgressTracking::done ( ) const
inline
Returns
true when the tracked activity is over.

Definition at line 51 of file progress_tracking.h.

51 { return progress >= maxProgress; }

◆ printOutProgressBar()

void Beatmup::ProgressTracking::printOutProgressBar ( const unsigned int  barLength = 40) const

Prints a fancy progress bar to standard output.

Designed to be called repeatedly: prints on the same line erasing the previously printed bar.

Parameters
[in]barLengthThe length of the progress bar (number of characters)

Definition at line 27 of file progress_tracking.cpp.

27  {
28  printf("\r[");
29  const unsigned int val = std::min(barLength - 2, progress * (barLength - 2) / maxProgress);
30  for (unsigned int i = 0; i < val; ++i)
31  printf("*");
32  for (unsigned int i = val; i < barLength - 2; ++i)
33  printf(" ");
34  printf("]");
35  fflush(stdout);
36 }
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:724
return(jlong) new Beatmup jlong jstring jint val

Member Data Documentation

◆ progress

unsigned int Beatmup::ProgressTracking::progress
private

Definition at line 27 of file progress_tracking.h.

◆ maxProgress

unsigned int Beatmup::ProgressTracking::maxProgress
private

Definition at line 27 of file progress_tracking.h.

◆ DEVNULL

Beatmup::ProgressTracking Beatmup::ProgressTracking::DEVNULL
static

Definition at line 29 of file progress_tracking.h.


The documentation for this class was generated from the following files: