Mantid
Loading...
Searching...
No Matches
AlgorithmFactoryObserver.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9namespace {
10template <typename Observer> void modifyObserver(const bool turnOn, bool &isObserving, Observer &observer) {
11 if (turnOn && !isObserving) {
12 Mantid::API::AlgorithmFactory::Instance().notificationCenter.addObserver(observer);
13 } else if (!turnOn && isObserving) {
14 Mantid::API::AlgorithmFactory::Instance().notificationCenter.removeObserver(observer);
15 }
16 isObserving = turnOn;
17}
18} // namespace
19
20namespace Mantid::API {
21
23 : m_updateObserver(*this, &AlgorithmFactoryObserver::_updateHandle) {}
24
26 // Turn off/remove all observers
27 this->observeUpdate(false);
28}
29
30// ------------------------------------------------------------
31// Observe Methods
32// ------------------------------------------------------------
33
42 modifyObserver(turnOn, m_observingUpdate, m_updateObserver);
43}
44
45// ------------------------------------------------------------
46// Virtual Methods
47// ------------------------------------------------------------
48
56
57// ------------------------------------------------------------
58// Private Methods
59// ------------------------------------------------------------
61 UNUSED_ARG(pNf)
62 this->updateHandle();
63}
64
65} // namespace Mantid::API
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
virtual void updateHandle()
If something subscribes to the AlgorithmFactory, then this function will trigger.
Poco::NObserver< AlgorithmFactoryObserver, AlgorithmFactoryUpdateNotification > m_updateObserver
Poco::NObserver for SubscribeNotification.
void _updateHandle(AlgorithmFactoryUpdateNotification_ptr pNf)
void observeUpdate(bool turnOn=true)
Function will add/remove the observer to the AlgorithmFactory when something is subscribed to it.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
const Poco::AutoPtr< Mantid::Kernel::DynamicFactory< Algorithm >::UpdateNotification > & AlgorithmFactoryUpdateNotification_ptr