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 { Nexus, Generic, NexusHDF5 };
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 Nexus:
93 if (!std::is_base_of<IFileLoader<Kernel::NexusDescriptor>, T>::value) {
94 throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
95 "' registered as Nexus loader but it does not "
96 "inherit from "
97 "API::IFileLoader<Kernel::NexusDescriptor>");
98 }
99 break;
100 case NexusHDF5:
101 if (!std::is_base_of<IFileLoader<Kernel::NexusHDF5Descriptor>, T>::value) {
102 throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
103 "' registered as NexusHDF5 loader but it does not "
104 "inherit from "
105 "API::IFileLoader<Kernel::NexusHDF5Descriptor>");
106 }
107 break;
108 case Generic:
109 if (!std::is_base_of<IFileLoader<Kernel::FileDescriptor>, T>::value) {
110 throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
111 "' registered as Generic loader but it does "
112 "not inherit from "
113 "API::IFileLoader<Kernel::FileDescriptor>");
114 }
115 break;
116 default:
117 throw std::runtime_error("Invalid LoaderFormat given");
118 }
119 }
120 };
121
123 void removeAlgorithm(const std::string &name, const int version, std::multimap<std::string, int> &typedLoaders);
124
127 std::array<std::multimap<std::string, int>, 3> m_names;
130
133};
134
137
138} // namespace API
139} // namespace Mantid
140
141namespace Mantid {
142namespace Kernel {
143EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FileLoaderRegistryImpl>;
144}
145} // namespace Mantid
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:52
Manage the lifetime of a class intended to be a singleton.
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...