Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAPI/AlgorithmFactoryObserver.h"
namespace {
template <typename Observer>
void modifyObserver(const bool turnOn, bool &isObserving, Observer &observer) {
if (turnOn && !isObserving) {
AlgorithmFactory::Instance().notificationCenter.addObserver(observer);
} else if (!turnOn && isObserving) {
AlgorithmFactory::Instance().notificationCenter.removeObserver(observer);
}
isObserving = turnOn;
}
} // namespace
namespace Mantid {
namespace API {
AlgorithmFactoryObserver::AlgorithmFactoryObserver()
: m_updateObserver(*this, &AlgorithmFactoryObserver::_updateHandle) {
}
AlgorithmFactoryObserver::~AlgorithmFactoryObserver() {
// Turn off/remove all observers
this->observeUpdate(false);
}
// ------------------------------------------------------------
// Observe Methods
// ------------------------------------------------------------
/**
* @brief Function will add/remove the observer to the AlgorithmFactory when
* something is subscribed to it.
*
* @param turnOn bool; if this is True then, if not already present, the
* observer will be added else removed if it's false.
*/
void AlgorithmFactoryObserver::observeUpdate(bool turnOn) {
modifyObserver(turnOn, m_observingUpdate, m_updateObserver);
}
// ------------------------------------------------------------
// Virtual Methods
// ------------------------------------------------------------
/**
* @brief If something subscribes to the AlgorithmFactory,
* then this function will trigger.
* works by overloading this class and overriding this function.
*
*/
void AlgorithmFactoryObserver::updateHandle() {
}
// ------------------------------------------------------------
// Private Methods
// ------------------------------------------------------------
void AlgorithmFactoryObserver::_updateHandle(
const AlgorithmFactoryUpdateNotification_ptr pNf) {
UNUSED_ARG(pNf)
this->updateHandle();
}
} // namespace API
} // namespace Mantid