MyraMath
UserProgressMeter.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_USERPROGRESSMETER_H
7 #define MYRAMATH_JOBGRAPH_USERPROGRESSMETER_H
8 
15 
16 namespace myra {
17 
18 // Implementation detail.
19 template<class UserClass> class UserProgressMeter : public ProgressMeterBase
20  {
21  public:
22 
23  // Constructor, requires a copy constructible UserClass.
24  UserProgressMeter(const UserClass& in_u)
25  : u(in_u) { }
26 
27  protected:
28 
29  // Called when a lengthy calculation is started.
30  virtual void begin(const std::string& name, uint64_t total)
31  { u.begin(name,total); }
32 
33  // Called repeatedly between begin() and end(), to regularly increment progress.
34  virtual void increment(uint64_t delta)
35  { u.increment(delta); }
36 
37  // Called when a lengthy calculation is finished.
38  virtual void end()
39  { u.end(); }
40 
41  // Regularly polled while a JobGraph execute()'s, execution will halt if kill()==true.
42  virtual bool kill()
43  { return u.kill(); }
44 
45  // Virtual copy constructor.
46  ProgressMeterBase* clone() const
47  { return new UserProgressMeter(u); }
48 
49  private:
50 
51  // Deep copy of user's class.
52  UserClass u;
53 
54  };
55 
57 template<class UserClass> ProgressMeter make_UserProgressMeter(const UserClass& u)
58  { return UserProgressMeter<UserClass>(u); }
59 
60 } // namespace myra
61 
62 #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
Definition: UserProgressMeter.h:19
ProgressMeter make_UserProgressMeter(const UserClass &u)
Helper function to adapt some user code (encapsulated in a class) into a ProgressMeter.
Definition: UserProgressMeter.h:57
Interface type for progress measurement and control within JobGraph&#39;s.