BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ProgressHandler.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Computation/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 #ifndef BORNAGAIN_CORE_COMPUTATION_PROGRESSHANDLER_H
16 #define BORNAGAIN_CORE_COMPUTATION_PROGRESSHANDLER_H
17 
18 #include <functional>
19 
20 class MultiLayer;
21 
22 //! Maintains information about progress of a computation.
23 //! Owner is the computation, which periodically calls the thread-safe function incrementDone(..).
24 //! An application (GUI or script) may subscribe(..) to be informed about progress.
25 //! It is then periodically called back by inform(..).
26 //! The return value of inform(..) can be used to request termination of the computation.
27 //!
28 //! @ingroup algorithms_internal
29 
31 {
32 public:
33  typedef std::function<bool(size_t)> Callback_t;
34 
37  {
38  }
40  : m_inform(other.m_inform) // not clear whether we want multiple copies of this
41  ,
43  {
44  }
46  void reset()
47  {
49  m_continuation_flag = true;
50  }
51  void setExpectedNTicks(size_t n) { m_expected_nticks = n; }
52  void incrementDone(size_t ticks_done);
53  bool alive() { return m_continuation_flag; }
54 
55 private:
60  bool defaultMonitorExec(int);
61 };
62 
63 #endif // BORNAGAIN_CORE_COMPUTATION_PROGRESSHANDLER_H
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:42
Maintains information about progress of a computation.
size_t m_completed_nticks
void subscribe(ProgressHandler::Callback_t callback)
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).
std::function< bool(size_t)> Callback_t
size_t m_expected_nticks