BornAgain  1.19.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 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 //! Owner is the computation, which periodically calls the thread-safe function incrementDone(..).
29 //! An application (GUI or script) may subscribe(..) to be informed about progress.
30 //! It is then periodically called back by inform(..).
31 //! The return value of inform(..) can be used to request termination of the computation.
32 //!
33 //! @ingroup algorithms_internal
34 
36 public:
37  typedef std::function<bool(size_t)> Callback_t;
38 
41  {
42  }
44  : m_inform(other.m_inform) // not clear whether we want multiple copies of this
47  {
48  }
50  void reset()
51  {
53  m_continuation_flag = true;
54  }
55  void setExpectedNTicks(size_t n) { m_expected_nticks = n; }
56  void incrementDone(size_t ticks_done);
57  bool alive() { return m_continuation_flag; }
58 
59 private:
64  bool defaultMonitorExec(int);
65 };
66 
67 #endif // BORNAGAIN_BASE_PROGRESS_PROGRESSHANDLER_H
68 #endif // USER_API
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:41
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