Mantid
Loading...
Searching...
No Matches
AnalysisDataServiceObserver.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 AnalysisDataService::Instance().notificationCenter.addObserver(observer);
13 } else if (!turnOn && isObserving) {
14 AnalysisDataService::Instance().notificationCenter.removeObserver(observer);
15 }
16 isObserving = turnOn;
17}
18} // namespace
19
20namespace Mantid::API {
21
23 : m_addObserver(*this, &AnalysisDataServiceObserver::_addHandle),
24 m_replaceObserver(*this, &AnalysisDataServiceObserver::_replaceHandle),
25 m_deleteObserver(*this, &AnalysisDataServiceObserver::_deleteHandle),
26 m_clearObserver(*this, &AnalysisDataServiceObserver::_clearHandle),
27 m_renameObserver(*this, &AnalysisDataServiceObserver::_renameHandle),
28 m_groupObserver(*this, &AnalysisDataServiceObserver::_groupHandle),
29 m_unGroupObserver(*this, &AnalysisDataServiceObserver::_unGroupHandle),
30 m_groupUpdatedObserver(*this, &AnalysisDataServiceObserver::_groupUpdateHandle) {}
31
33 // Turn off/remove all observers
34 this->observeAll(false);
35}
36
37// ------------------------------------------------------------
38// Observe Methods
39// ------------------------------------------------------------
40
48 this->observeAdd(turnOn);
49 this->observeReplace(turnOn);
50 this->observeDelete(turnOn);
51 this->observeClear(turnOn);
52 this->observeRename(turnOn);
53 this->observeGroup(turnOn);
54 this->observeUnGroup(turnOn);
55 this->observeGroupUpdate(turnOn);
56}
57
65void AnalysisDataServiceObserver::observeAdd(bool turnOn) { modifyObserver(turnOn, m_observingAdd, m_addObserver); }
66
75 modifyObserver(turnOn, m_observingReplace, m_replaceObserver);
76}
77
86 modifyObserver(turnOn, m_observingDelete, m_deleteObserver);
87}
88
97 modifyObserver(turnOn, m_observingClear, m_clearObserver);
98}
99
108 modifyObserver(turnOn, m_observingRename, m_renameObserver);
109}
110
119 modifyObserver(turnOn, m_observingGroup, m_groupObserver);
120}
121
130 modifyObserver(turnOn, m_observingUnGroup, m_unGroupObserver);
131}
132
141 modifyObserver(turnOn, m_observingGroupUpdate, m_groupUpdatedObserver);
142}
143
144// ------------------------------------------------------------
145// Virtual Methods
146// ------------------------------------------------------------
152
160void AnalysisDataServiceObserver::addHandle(const std::string &wsName, const Mantid::API::Workspace_sptr &ws) {
161 UNUSED_ARG(wsName)
162 UNUSED_ARG(ws)
163}
164
173 UNUSED_ARG(wsName)
174 UNUSED_ARG(ws)
175}
176
185 UNUSED_ARG(wsName)
186 UNUSED_ARG(ws)
187}
188
194
202void AnalysisDataServiceObserver::renameHandle(const std::string &wsName, const std::string &newName) {
203 UNUSED_ARG(wsName)
204 UNUSED_ARG(newName)
205}
206
214void AnalysisDataServiceObserver::groupHandle(const std::string &wsName, const Workspace_sptr &ws) {
215 UNUSED_ARG(wsName)
216 UNUSED_ARG(ws)
217}
218
226void AnalysisDataServiceObserver::unGroupHandle(const std::string &wsName, const Workspace_sptr &ws) {
227 UNUSED_ARG(wsName)
228 UNUSED_ARG(ws)
229}
230
239void AnalysisDataServiceObserver::groupUpdateHandle(const std::string &wsName, const Workspace_sptr &ws) {
240 UNUSED_ARG(wsName)
241 UNUSED_ARG(ws)
242}
243
244// ------------------------------------------------------------
245// Private Methods
246// ------------------------------------------------------------
247void AnalysisDataServiceObserver::_addHandle(const Poco::AutoPtr<AnalysisDataServiceImpl::AddNotification> &pNf) {
248 this->anyChangeHandle();
249 this->addHandle(pNf->objectName(), pNf->object());
250}
251
253 const Poco::AutoPtr<AnalysisDataServiceImpl::AfterReplaceNotification> &pNf) {
254 this->anyChangeHandle();
255 this->replaceHandle(pNf->objectName(), pNf->object());
256}
257
259 const Poco::AutoPtr<AnalysisDataServiceImpl::PreDeleteNotification> &pNf) {
260 this->anyChangeHandle();
261 this->deleteHandle(pNf->objectName(), pNf->object());
262}
263
264void AnalysisDataServiceObserver::_clearHandle(const Poco::AutoPtr<AnalysisDataServiceImpl::ClearNotification> &pNf) {
265 UNUSED_ARG(pNf)
266 this->anyChangeHandle();
267 this->clearHandle();
268}
269
270void AnalysisDataServiceObserver::_renameHandle(const Poco::AutoPtr<AnalysisDataServiceImpl::RenameNotification> &pNf) {
271 this->anyChangeHandle();
272 this->renameHandle(pNf->objectName(), pNf->newObjectName());
273}
274
276 const Poco::AutoPtr<AnalysisDataServiceImpl::GroupWorkspacesNotification> &pNf) {
277 this->anyChangeHandle();
278 this->groupHandle(pNf->objectName(), pNf->object());
279}
280
282 const Poco::AutoPtr<AnalysisDataServiceImpl::UnGroupingWorkspaceNotification> &pNf) {
283 this->anyChangeHandle();
284 this->unGroupHandle(pNf->objectName(), pNf->object());
285}
286
288 const Poco::AutoPtr<AnalysisDataServiceImpl::GroupUpdatedNotification> &pNf) {
289 this->anyChangeHandle();
290 this->groupUpdateHandle(pNf->objectName(), pNf->object());
291}
292
293} // namespace Mantid::API
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
void _unGroupHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::UnGroupingWorkspaceNotification > &pNf)
virtual void unGroupHandle(const std::string &wsName, const Workspace_sptr &ws)
If a group is removed from the ADS, then this function will trigger, works by overloading this class ...
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::AddNotification > m_addObserver
Poco::NObserver for AddNotification.
void _renameHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::RenameNotification > &pNf)
void _groupHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::GroupWorkspacesNotification > &pNf)
void observeGroup(bool turnOn=true)
Function will add/remove the observer to the ADS for when a group is added/created in the ADS.
virtual void addHandle(const std::string &wsName, const Workspace_sptr &ws)
If a workspace is added to the ADS, then this function will trigger, works by overloading this class ...
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::ClearNotification > m_clearObserver
Poco::NObserver for ClearNotification.
void observeReplace(bool turnOn=true)
Function will add/remove the observer to the ADS for when a workspace is replaced.
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::PreDeleteNotification > m_deleteObserver
Poco::NObserver for DeleteNotification.
virtual void replaceHandle(const std::string &wsName, const Workspace_sptr &ws)
If a workspace is replaced in the ADS, then this function will trigger, works by overloading this cla...
void observeAll(bool turnOn=true)
Function will turn on/off all observers for the ADS.
virtual void groupHandle(const std::string &wsName, const Workspace_sptr &ws)
If a group is created/added to the ADS, then this function will trigger, works by overloading this cl...
virtual void deleteHandle(const std::string &wsName, const Workspace_sptr &ws)
If a workspace is deleted from the ADS, then this function will trigger, works by overloading this cl...
void observeRename(bool turnOn=true)
Function will add/remove the observer to the ADS for when a workspace is renamed.
void _replaceHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::AfterReplaceNotification > &pNf)
virtual void groupUpdateHandle(const std::string &wsName, const Workspace_sptr &ws)
If a group has a workspace added/removed in the ADS, then this function will trigger,...
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::RenameNotification > m_renameObserver
Poco::NObserver for RenameNotification.
void observeUnGroup(bool turnOn=true)
Function will add/remove the observer to the ADS for when a group is removed/delete from the ADS.
void _clearHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::ClearNotification > &pNf)
void observeDelete(bool turnOn=true)
Function will add/remove the observer to the ADS for when a workspace is deleted.
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::GroupUpdatedNotification > m_groupUpdatedObserver
Poco::NObserver for GroupUpdateNotification.
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::UnGroupingWorkspaceNotification > m_unGroupObserver
Poco::NObserver for UnGroupNotification.
virtual void renameHandle(const std::string &wsName, const std::string &newName)
If a workspace is renamed in the ADS, then this function will trigger, works by overloading this clas...
void _groupUpdateHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::GroupUpdatedNotification > &pNf)
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::GroupWorkspacesNotification > m_groupObserver
Poco::NObserver for GroupNotification.
void _deleteHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::PreDeleteNotification > &pNf)
void observeClear(bool turnOn=true)
Function will add/remove the observer to the ADS for when the ADS is cleared.
void observeAdd(bool turnOn=true)
Function will add/remove the observer to the ADS for when a workspace is added to it.
virtual void anyChangeHandle()
If anyChange to the ADS occurs then this function will trigger, works by overloading this class and o...
virtual void clearHandle()
If the ADS is cleared, then this function will trigger, works by overloading this class and overridin...
void _addHandle(const Poco::AutoPtr< AnalysisDataServiceImpl::AddNotification > &pNf)
void observeGroupUpdate(bool turnOn=true)
Function will add/remove the observer to the ADS for if a workspace is added to a group or removed.
Poco::NObserver< AnalysisDataServiceObserver, AnalysisDataServiceImpl::AfterReplaceNotification > m_replaceObserver
Poco::NObserver for ReplaceNotification.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20