Mantid
Loading...
Searching...
No Matches
PreviewManager.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2020 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 +
7#pragma once
8
9#include "MantidAPI/DllConfig.h"
10#include "MantidAPI/IPreview.h"
13
14#include <map>
15#include <type_traits>
16#include <utility>
17#include <vector>
18
19namespace Mantid {
20namespace API {
21
22using PreviewRegister = std::map<std::string, std::map<std::string, std::map<std::string, IPreview_uptr>>>;
23
26class MANTID_API_DLL PreviewManagerImpl {
27public:
28 PreviewManagerImpl() = default;
31 std::vector<std::string> getPreviews(const std::string &facility, const std::string &technique = "") const;
32 const IPreview &getPreview(const std::string &facility, const std::string &technique,
33 const std::string &preview) const;
34 template <class T> void subscribe() {
35 static_assert(std::is_base_of<IPreview, T>::value);
36 IPreview_uptr preview = std::make_unique<T>();
37 const auto facility = preview->facility();
38 const auto technique = preview->technique();
39 const auto name = preview->name();
40 if (checkPreview(facility, technique, name)) {
41 throw std::runtime_error("Preview with the same name is already registered for the same "
42 "facility and technique.");
43 }
44 m_previews[facility][technique][name] = std::move(preview);
45 }
46
47private:
48 bool checkFacility(const std::string &facility) const;
49 bool checkTechnique(const std::string &facility, const std::string &technique) const;
50 bool checkPreview(const std::string &facility, const std::string &technique, const std::string &preview) const;
52};
53
55
56} // namespace API
57} // namespace Mantid
58
59namespace Mantid {
60namespace Kernel {
61EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::PreviewManagerImpl>;
62}
63} // namespace Mantid
64
65#define DECLARE_PREVIEW(classname) \
66 namespace { \
67 Mantid::Kernel::RegistrationHelper \
68 register_preview_##classname(((Mantid::API::PreviewManager::Instance().subscribe<classname>()), 0)); \
69 }
IPreview : This is the abstract base class of the raw data previews.
Definition: IPreview.h:24
PreviewManager : Manages the raw data previews.
PreviewManagerImpl(const PreviewManagerImpl &)=delete
PreviewManagerImpl & operator=(const PreviewManagerImpl &)=delete
Manage the lifetime of a class intended to be a singleton.
std::unique_ptr< IPreview > IPreview_uptr
Definition: IPreview.h:37
std::map< std::string, std::map< std::string, std::map< std::string, IPreview_uptr > > > PreviewRegister
Helper class which provides the Collimation Length for SANS instruments.