Beatmup
progress_tracking.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 
21 namespace Beatmup {
22  /**
23  Progress tracking utility.
24  */
26  private:
27  unsigned int progress, maxProgress;
28  public:
30 
31  inline ProgressTracking() : progress(0), maxProgress(1) {}
32  inline ProgressTracking(unsigned int max) : progress(0), maxProgress(max) {}
33 
34  /**
35  Resets the progress to zero.
36  \param[in] max New maximum progress
37  */
38  inline void reset(unsigned int max) {
39  this->progress = 0;
40  this->maxProgress = max;
41  }
42 
43  /**
44  Increases progress by one step.
45  */
46  inline void operator()() { progress++; }
47 
48  /**
49  \return `true` when the tracked activity is over.
50  */
51  inline bool done() const { return progress >= maxProgress; }
52 
53  /**
54  Prints a fancy progress bar to standard output.
55  Designed to be called repeatedly: prints on the same line erasing the previously printed bar.
56  \param[in] barLength The length of the progress bar (number of characters)
57  */
58  void printOutProgressBar(const unsigned int barLength = 40) const;
59  };
60 
61 }
Progress tracking utility.
void operator()()
Increases progress by one step.
ProgressTracking(unsigned int max)
void printOutProgressBar(const unsigned int barLength=40) const
Prints a fancy progress bar to standard output.
void reset(unsigned int max)
Resets the progress to zero.
static ProgressTracking DEVNULL
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:728