BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IObserver.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Fitting/IObserver.h
6 //! @brief Defines classes IObserver and IObservable (Observer pattern).
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_FITTING_IOBSERVER_H
16 #define BORNAGAIN_CORE_FITTING_IOBSERVER_H
17 
18 #include <list>
19 #include <memory>
20 
21 class IObservable;
22 
23 //! Observer interface from %Observer pattern.
24 //! @ingroup tools_internal
25 
26 class IObserver
27 {
28 public:
29  virtual ~IObserver();
30 
31  //! method which is used by observable subject to notify change in status
32  virtual void notify(IObservable* subject) = 0;
33 };
34 
35 //! Observable interface from %Observer pattern
36 //! @ingroup tools_internal
37 
39 {
40 public:
41  //! Shared pointer is used when passing these objects from Python to C++
42  typedef std::shared_ptr<IObserver> observer_t;
43 
44  virtual ~IObservable();
45 
46  //! attach observer to the list of observers
47  virtual void attachObserver(observer_t obj);
48 
49  //! notify observers about change in status
50  virtual void notifyObservers();
51 
52 private:
53  std::list<observer_t> m_observers;
54 };
55 
56 #endif // BORNAGAIN_CORE_FITTING_IOBSERVER_H
Observable interface from Observer pattern.
Definition: IObserver.h:39
std::shared_ptr< IObserver > observer_t
Shared pointer is used when passing these objects from Python to C++.
Definition: IObserver.h:42
virtual void attachObserver(observer_t obj)
attach observer to the list of observers
Definition: IObserver.cpp:17
virtual ~IObservable()
virtual void notifyObservers()
notify observers about change in status
Definition: IObserver.cpp:22
std::list< observer_t > m_observers
Definition: IObserver.h:53
Observer interface from Observer pattern.
Definition: IObserver.h:27
virtual void notify(IObservable *subject)=0
method which is used by observable subject to notify change in status
virtual ~IObserver()