Mantid
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Mantid::API::FileLoaderRegistryImpl Class Reference

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< IAlgorithmchooseLoader (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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ LoaderFormat

Defines types of possible file.

Enumerator
Nexus 
Generic 
NexusHDF5 

Definition at line 45 of file FileLoaderRegistry.h.

Constructor & Destructor Documentation

◆ FileLoaderRegistryImpl()

Mantid::API::FileLoaderRegistryImpl::FileLoaderRegistryImpl ( )
private

Default constructor (for singleton)

Creates an empty registry.

m_names is initialized in the header

Definition at line 198 of file FileLoaderRegistry.cpp.

◆ ~FileLoaderRegistryImpl()

Mantid::API::FileLoaderRegistryImpl::~FileLoaderRegistryImpl ( )
privatedefault

Destructor.

Member Function Documentation

◆ canLoad()

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.

Parameters
algorithmNameThe name of the algorithm to check
filenameThe name of file to check
Returns
True if the algorithm can load the file, false otherwise
Exceptions
std::invalid_argumentif 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().

◆ chooseLoader()

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.

Parameters
filenameA full file path pointing to an existing file
Returns
A string containing the name of an algorithm to load the file
Exceptions
Exception::NotFoundErrorif 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().

◆ removeAlgorithm()

void Mantid::API::FileLoaderRegistryImpl::removeAlgorithm ( const std::string &  name,
const int  version,
std::multimap< std::string, int > &  typedLoaders 
)
private

Remove a named algorithm & version from the given map.

Parameters
nameA string containing the algorithm name
versionThe version to remove. -1 indicates all instances
typedLoadersA map of names to version numbers

Definition at line 207 of file FileLoaderRegistry.cpp.

Referenced by unsubscribe().

◆ size()

size_t Mantid::API::FileLoaderRegistryImpl::size ( ) const
inline
Returns
the number of entries in the registry

Definition at line 49 of file FileLoaderRegistry.h.

◆ subscribe()

template<typename Type >
void Mantid::API::FileLoaderRegistryImpl::subscribe ( LoaderFormat  format)
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.

Parameters
formatThe type of loader being subscribed, see LoaderFormat
Exceptions
std::invalid_argumentif an entry with this name already exists

Definition at line 62 of file FileLoaderRegistry.h.

◆ unsubscribe()

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.

Parameters
nameName of the algorithm to remove from the search list
versionAn optional version to remove. -1 indicates remove all (Default=-1)

Definition at line 98 of file FileLoaderRegistry.cpp.

References m_names, and removeAlgorithm().

Friends And Related Function Documentation

◆ Mantid::Kernel::CreateUsingNew< FileLoaderRegistryImpl >

Friend so that CreateUsingNew.

Definition at line 77 of file FileLoaderRegistry.h.

Member Data Documentation

◆ m_log

Kernel::Logger Mantid::API::FileLoaderRegistryImpl::m_log
mutableprivate

Reference to a logger.

Definition at line 132 of file FileLoaderRegistry.h.

Referenced by canLoad(), and chooseLoader().

◆ m_names

std::array<std::multimap<std::string, int>, 3> Mantid::API::FileLoaderRegistryImpl::m_names
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().

◆ m_totalSize

size_t Mantid::API::FileLoaderRegistryImpl::m_totalSize
private

Total number of names registered.

Definition at line 129 of file FileLoaderRegistry.h.


The documentation for this class was generated from the following files: