Mantid
Loading...
Searching...
No Matches
FileLoaderRegistry.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2013 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
15
16#ifndef Q_MOC_RUN
17#include <type_traits>
18#endif
19
20#include <array>
21#include <map>
22#include <string>
23
24namespace Mantid {
25namespace Kernel {
26
27class Logger;
28}
29namespace API {
30
31class IAlgorithm;
32
42class MANTID_API_DLL FileLoaderRegistryImpl {
43public:
45 enum LoaderFormat { LegacyNexus, Generic, Nexus };
46
47public:
49 inline size_t size() const { return m_totalSize; }
50
62 template <typename Type> void subscribe(LoaderFormat format) {
64 const auto nameVersion = AlgorithmFactory::Instance().subscribe<Type>();
65 // If the factory didn't throw then the name is valid
66 m_names[format].insert(nameVersion);
67 m_totalSize += 1;
68 m_log.debug() << "Registered '" << nameVersion.first << "' version '" << nameVersion.second << "' as file loader\n";
69 }
70
72 void unsubscribe(const std::string &name, const int version = -1);
73
75 const std::shared_ptr<IAlgorithm> chooseLoader(const std::string &filename) const;
77 bool canLoad(const std::string &algorithmName, const std::string &filename) const;
78
79private:
82
87
89 template <typename T> struct SubscriptionValidator {
90 static void check(LoaderFormat format) {
91 switch (format) {
92 case LegacyNexus:
94 throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
95 "' registered as LegacyNexus loader but it does not inherit from "
96 "API::IFileLoader<Kernel::LegacyNexusDescriptor>");
97 }
98 break;
99 case Nexus:
100 if (!std::is_base_of<IFileLoader<Nexus::NexusDescriptor>, T>::value) {
101 throw std::runtime_error(
102 std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
103 "' registered as Nexus loader but it does not inherit from API::IFileLoader<Kernel::NexusDescriptor>");
104 }
105 break;
106 case Generic:
107 if (!std::is_base_of<IFileLoader<Kernel::FileDescriptor>, T>::value) {
108 throw std::runtime_error(
109 std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
110 "' registered as Generic loader but it does not inherit from API::IFileLoader<Kernel::FileDescriptor>");
111 }
112 break;
113 default:
114 throw std::runtime_error("Invalid LoaderFormat given");
115 }
116 }
117 };
118
120 void removeAlgorithm(const std::string &name, const int version, std::multimap<std::string, int> &typedLoaders);
121
124 std::array<std::multimap<std::string, int>, 3> m_names;
127
130};
131
134
135} // namespace API
136} // namespace Mantid
137
138namespace Mantid {
139namespace Kernel {
140EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FileLoaderRegistryImpl>;
141}
142} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
Keeps a registry of algorithm's that are file loading algorithms to allow them to be searched to find...
std::array< std::multimap< std::string, int >, 3 > m_names
The list of names.
void subscribe(LoaderFormat format)
Registers a loader whose format is one of the known formats given in LoaderFormat.
LoaderFormat
Defines types of possible file.
size_t m_totalSize
Total number of names registered.
Kernel::Logger m_log
Reference to a logger.
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition IFileLoader.h:19
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
Manage the lifetime of a class intended to be a singleton.
Mantid::Kernel::SingletonHolder< FileLoaderRegistryImpl > FileLoaderRegistry
Type for the actual singleton instance.
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...