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 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/utils/progresshandler.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_UTILS_PROGRESSHANDLER_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_UTILS_PROGRESSHANDLER_H
17 
18 #include "mvvm/model_export.h"
19 #include <functional>
20 #include <mutex>
21 
22 namespace ModelView {
23 
24 //! Maintain information about progress of a computation.
25 //! Initialized with callback function to report progress and retrieve interruption request status.
26 
27 class MVVM_MODEL_EXPORT ProgressHandler {
28 public:
29  using callback_t = std::function<bool(size_t)>;
30 
31  ProgressHandler() = default;
32  ProgressHandler(callback_t callback, size_t max_ticks_count);
33 
34  ProgressHandler(const ProgressHandler& other) = delete;
35  ProgressHandler& operator=(const ProgressHandler& other) = delete;
36 
37  void subscribe(callback_t callback);
38 
39  void setMaxTicksCount(size_t value);
40 
41  bool has_interrupt_request() const;
42 
43  void setCompletedTicks(size_t value);
44 
45  void reset();
46 
47 private:
48  std::mutex mutex;
50  size_t max_ticks_count{0};
51  size_t completed_ticks{0};
52  bool interrupt_request{false};
53 };
54 
55 } // namespace ModelView
56 
57 #endif // BORNAGAIN_MVVM_MODEL_MVVM_UTILS_PROGRESSHANDLER_H
Maintain information about progress of a computation.
ProgressHandler & operator=(const ProgressHandler &other)=delete
ProgressHandler(const ProgressHandler &other)=delete
std::function< bool(size_t)> callback_t
materialitems.h Collection of materials to populate MaterialModel.