Mantid
|
Keeps a registry of algorithm's that are file loading algorithms to allow them to be searched to find the correct one to load a particular file. More...
#include <FileLoaderRegistry.h>
Classes | |
struct | SubscriptionValidator |
Helper for subscribe to check base class. More... | |
Public Types | |
enum | LoaderFormat { Nexus , Generic , NexusHDF5 } |
Defines types of possible file. More... | |
Public Member Functions | |
bool | canLoad (const std::string &algorithmName, const std::string &filename) const |
Checks whether the given algorithm can load the file. More... | |
const std::shared_ptr< IAlgorithm > | chooseLoader (const std::string &filename) const |
Returns the name of an Algorithm that can load the given filename. More... | |
size_t | size () const |
template<typename Type > | |
void | subscribe (LoaderFormat format) |
Registers a loader whose format is one of the known formats given in LoaderFormat. More... | |
void | unsubscribe (const std::string &name, const int version=-1) |
Unsubscribe a named algorithm and version from the loader registration. More... | |
Private Member Functions | |
FileLoaderRegistryImpl () | |
Default constructor (for singleton) More... | |
void | removeAlgorithm (const std::string &name, const int version, std::multimap< std::string, int > &typedLoaders) |
Remove a named algorithm & version from the given map. More... | |
~FileLoaderRegistryImpl () | |
Destructor. More... | |
Private Attributes | |
Kernel::Logger | m_log |
Reference to a logger. More... | |
std::array< std::multimap< std::string, int >, 3 > | m_names |
The list of names. More... | |
size_t | m_totalSize |
Total number of names registered. More... | |
Friends | |
struct | Mantid::Kernel::CreateUsingNew< FileLoaderRegistryImpl > |
Friend so that CreateUsingNew. More... | |
Keeps a registry of algorithm's that are file loading algorithms to allow them to be searched to find the correct one to load a particular file.
A macro, DECLARE_FILELOADER_ALGORITHM is defined in RegisterFileLoader.h. Use this in place of the standard DECLARE_ALGORITHM macro
Definition at line 42 of file FileLoaderRegistry.h.
Defines types of possible file.
Enumerator | |
---|---|
Nexus | |
Generic | |
NexusHDF5 |
Definition at line 45 of file FileLoaderRegistry.h.
|
private |
Default constructor (for singleton)
Creates an empty registry.
m_names is initialized in the header
Definition at line 198 of file FileLoaderRegistry.cpp.
|
privatedefault |
Destructor.
bool Mantid::API::FileLoaderRegistryImpl::canLoad | ( | const std::string & | algorithmName, |
const std::string & | filename | ||
) | const |
Checks whether the given algorithm can load the file.
Perform a check that that the given algorithm can load the file.
algorithmName | The name of the algorithm to check |
filename | The name of file to check |
std::invalid_argument | if the loader does not exist |
Definition at line 156 of file FileLoaderRegistry.cpp.
References Mantid::Kernel::Logger::debug(), Generic, Mantid::Kernel::NexusHDF5Descriptor::isReadable(), Mantid::Kernel::NexusDescriptor::isReadable(), m_log, m_names, Nexus, and NexusHDF5.
Referenced by export_FileLoaderRegistry().
const std::shared_ptr< IAlgorithm > Mantid::API::FileLoaderRegistryImpl::chooseLoader | ( | const std::string & | filename | ) | const |
Returns the name of an Algorithm that can load the given filename.
Queries each registered algorithm and asks it how confident it is that it can load the given file.
The name of the one with the highest confidence is returned.
filename | A full file path pointing to an existing file |
Exception::NotFoundError | if an algorithm cannot be found |
Definition at line 113 of file FileLoaderRegistry.cpp.
References Mantid::Kernel::Logger::debug(), Generic, Mantid::Kernel::NexusHDF5Descriptor::isReadable(), Mantid::Kernel::NexusDescriptor::isReadable(), m_log, m_names, Nexus, and NexusHDF5.
Referenced by export_FileLoaderRegistry().
|
private |
Remove a named algorithm & version from the given map.
name | A string containing the algorithm name |
version | The version to remove. -1 indicates all instances |
typedLoaders | A map of names to version numbers |
Definition at line 207 of file FileLoaderRegistry.cpp.
Referenced by unsubscribe().
|
inline |
Definition at line 49 of file FileLoaderRegistry.h.
|
inline |
Registers a loader whose format is one of the known formats given in LoaderFormat.
It also passes this registration on to the AlgorithmFactory so that it can be created. The template type should be the class being registered. The name is taken from the string returned by the name() method on the object.
format | The type of loader being subscribed, see LoaderFormat |
std::invalid_argument | if an entry with this name already exists |
Definition at line 62 of file FileLoaderRegistry.h.
void Mantid::API::FileLoaderRegistryImpl::unsubscribe | ( | const std::string & | name, |
const int | version = -1 |
||
) |
Unsubscribe a named algorithm and version from the loader registration.
If the name does not exist then it does nothing.
name | Name of the algorithm to remove from the search list |
version | An optional version to remove. -1 indicates remove all (Default=-1) |
Definition at line 98 of file FileLoaderRegistry.cpp.
References m_names, and removeAlgorithm().
|
friend |
Friend so that CreateUsingNew.
Definition at line 77 of file FileLoaderRegistry.h.
|
mutableprivate |
Reference to a logger.
Definition at line 132 of file FileLoaderRegistry.h.
Referenced by canLoad(), and chooseLoader().
|
private |
The list of names.
The index pointed to by LoaderFormat defines a set for that format. The length is equal to the length of the LoaderFormat enum
Definition at line 127 of file FileLoaderRegistry.h.
Referenced by canLoad(), chooseLoader(), and unsubscribe().
|
private |
Total number of names registered.
Definition at line 129 of file FileLoaderRegistry.h.