Minsky
progress.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2023
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef PROGRESS_H
21 #define PROGRESS_H
22 #include <string>
23 #include <atomic>
24 
25 namespace minsky
26 {
27  class Minsky;
28  struct BusyCursor
29  {
31  BusyCursor(Minsky& m);
32  ~BusyCursor();
33  };
34 
35  class Progress
36  {
37  double delta=100;
38  double progress=0;
39  bool updaterStack=false; // whether under updater control
40  friend class ProgressUpdater;
41  public:
42  std::string title;
43  std::shared_ptr<std::atomic<bool>> cancel=std::make_shared<std::atomic<bool>>(false);
44  void displayProgress(bool inDestruct=false);
48  void increment(bool inDestruct=false) {
49  if (progress+delta<=100)
50  {
51  progress+=delta;
52  displayProgress(inDestruct);
53  }
54  }
55  void operator++() {increment();}
56  };
57 
59  {
62  public:
63  ProgressUpdater(Progress& progress, const std::string& title, int numSteps):
64  savedProgress(progress), updatedProgress(progress)
65  {
66  updatedProgress.title=title;
68  {
69  updatedProgress.delta/=numSteps;
70  }
71  else
72  {
74  updatedProgress.delta=100.0/numSteps;
75  }
77  }
79  void setProgress(double fraction) {
82  }
86  updatedProgress.progress=0; // reset progress counter once last ProgressUpdater exits
87  else
89  }
90  };
91 }
92 
93 #endif
Progress savedProgress
Definition: progress.h:60
BusyCursor(Minsky &m)
Definition: minsky.cc:1787
double progress
Definition: progress.h:38
std::shared_ptr< std::atomic< bool > > cancel
set to true to cancel process in progreess displayProgress will throw if cancel is set...
Definition: progress.h:43
void increment(bool inDestruct=false)
Definition: progress.h:48
ProgressUpdater(Progress &progress, const std::string &title, int numSteps)
Definition: progress.h:63
void displayProgress(bool inDestruct=false)
Definition: minsky.cc:1794
void operator++()
Definition: progress.h:55
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
double delta
Definition: progress.h:37
void setProgress(double fraction)
Sets the progress to a given fraction of this stack&#39;s allocation.
Definition: progress.h:79
bool updaterStack
Definition: progress.h:39
std::string title
Definition: progress.h:42
Minsky & minsky
Definition: progress.h:30
Progress & updatedProgress
Definition: progress.h:61