MyraMath
ProgressMeter.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_JOBGRAPH_PROGRESSMETER_H
7 #define MYRAMATH_JOBGRAPH_PROGRESSMETER_H
8 
14 #include <stdint.h>
15 #include <string>
16 #include <myramath/utility/detail/LIBPUBLIC.h>
17 
18 namespace myra {
19 
20 // Forward declarations.
21 class ProgressMeterBase;
22 class ProgressMeter;
23 
25 class LIBPUBLIC ProgressMeterBase
26  {
27  public:
28 
30  virtual ~ProgressMeterBase();
31 
32  protected:
33 
34  // Called when a lengthy calculation is started.
35  virtual void begin(const std::string& name, uint64_t total) = 0;
36 
37  // Called repeatedly between begin() and end(), to regularly increment progress.
38  virtual void increment(uint64_t delta) = 0;
39 
40  // Called when a lengthy calculation is finished.
41  virtual void end() = 0;
42 
43  // Regularly polled while a JobGraph execute()'s, execution will halt if kill()==true.
44  virtual bool kill() = 0;
45 
46  // Virtual copy constructor.
47  virtual ProgressMeterBase* clone() const = 0;
48 
49  // Friendship for encapsulating ProgressMeter, to it can clone()/copy.
50  friend class ::myra::ProgressMeter;
51 
52  };
53 
55 class LIBPUBLIC ProgressMeter
56  {
57  public:
58 
59  // ------------------------------------ Value semantics.
60 
62  ProgressMeter();
63 
65  ProgressMeter(const ProgressMeterBase& that);
66 
68  ProgressMeter(const ProgressMeter& that);
69 
71  void swap(ProgressMeter& that);
72 
74  ProgressMeter& operator= (ProgressMeter that);
75 
77  ~ProgressMeter();
78 
79  // ------------------------------------ ProgressMeter API.
80 
82  // name = something human-readable that describes the operation
83  // total = how much "work" is required to complete the operation (e.g. #flops)
84  void begin(const std::string& name, uint64_t total);
85 
87  // delta = how much "work" has been completed, sum of all deltas eventually adds up to total
88  void increment(uint64_t delta);
89 
91  void end();
92 
94  bool kill();
95 
96  private:
97 
98  // Underlying polymorphic instance, a ProgressMeterBase.
99  ProgressMeterBase* base;
100 
101  // A "latch" bit for kill().
102  bool kill_latch;
103 
104  };
105 
106 } // namespace myra
107 
108 #endif
Definition: syntax.dox:1
Interface for measuring progress via callbacks. Wraps an underlying polymorphic ProgressMeterBase.
Definition: ProgressMeter.h:55
Base/contract class for all other ProgressMeter&#39;s.
Definition: ProgressMeter.h:25