BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ProgressHandler.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Progress/ProgressHandler.h
6 //! @brief Defines class ProgressHandler.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_BASE_PROGRESS_PROGRESSHANDLER_H
21 #define BORNAGAIN_BASE_PROGRESS_PROGRESSHANDLER_H
22 
23 #include <functional>
24 
25 class MultiLayer;
26 
27 //! Maintains information about progress of a computation.
28 //!
29 //! Owner is the computation, which periodically calls the thread-safe function incrementDone(..).
30 //! An application (GUI or script) may subscribe(..) to be informed about progress.
31 //! It is then periodically called back by inform(..).
32 //! The return value of inform(..) can be used to request termination of the computation.
33 
35 public:
36  using Callback_t = std::function<bool(size_t)>;
37 
39  : m_inform(nullptr)
40  {
41  }
43  : m_inform(other.m_inform) // not clear whether we want multiple copies of this
46  {
47  }
49  void reset()
50  {
52  m_continuation_flag = true;
53  }
54  void setExpectedNTicks(size_t n) { m_expected_nticks = n; }
55  void incrementDone(size_t ticks_done);
56  bool alive() { return m_continuation_flag; }
57 
58 private:
60  size_t m_expected_nticks{0};
61  size_t m_completed_nticks{0};
62  bool m_continuation_flag{true};
63  bool defaultMonitorExec(int);
64 };
65 
66 #endif // BORNAGAIN_BASE_PROGRESS_PROGRESSHANDLER_H
67 #endif // USER_API
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:43
Maintains information about progress of a computation.
size_t m_completed_nticks
std::function< bool(size_t)> Callback_t
void subscribe(ProgressHandler::Callback_t inform)
Callback_t m_inform
ProgressHandler(const ProgressHandler &other)
bool defaultMonitorExec(int)
void setExpectedNTicks(size_t n)
void incrementDone(size_t ticks_done)
Increments number of completed computation steps (ticks). Performs callback (method m_inform) to info...
size_t m_expected_nticks