Skip to content
Snippets Groups Projects
Commit 9dc14084 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add DECLARE_FILELOADER_ALGORITHM macro. Refs #7263

parent c5ab6b95
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,20 @@
namespace Mantid
{
// Forward declaration
namespace Kernel
{
class Logger;
}
namespace API
{
/**
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. Uses FileLoaderPicker to do the most of the work
A macro, DECLARE_FILELOADER_ALGORITHM is defined in RegisterFileLoader.h. Use this in place of the standard
DECLARE_ALGORITHM macro
Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
......@@ -50,6 +59,8 @@ namespace Mantid
private:
/// The registered names
std::set<std::string> m_names;
/// Reference to a logger
Kernel::Logger & m_log;
};
} // namespace API
......
#ifndef MANTID_KERNEL_FRAMEWORKMANAGER_H_
#define MANTID_KERNEL_FRAMEWORKMANAGER_H_
#ifndef MANTID_API_FRAMEWORKMANAGER_H_
#define MANTID_API_FRAMEWORKMANAGER_H_
//----------------------------------------------------------------------
// Includes
......@@ -11,6 +11,7 @@
#endif
#include "MantidAPI/DllConfig.h"
#include "MantidAPI/FileLoaderRegistry.h"
#include "MantidKernel/SingletonHolder.h"
#include <boost/shared_ptr.hpp>
......@@ -89,6 +90,11 @@ namespace Mantid
/// Creates an algorithm and runs it, with variadic arguments
boost::shared_ptr<IAlgorithm> exec(const std::string& algorithmName, int count, ...);
/// Returns a const version of the main registry of file loader algorithms
inline const FileLoaderRegistry & fileLoaderRegistry() const { return m_fileLoaderRegistry; }
/// Returns a non-const version of the main registry of file loader algorithms
inline FileLoaderRegistry & fileLoaderRegistry() { return m_fileLoaderRegistry; }
/// Returns a shared pointer to the workspace requested
Workspace* getWorkspace(const std::string& wsName);
......@@ -116,9 +122,12 @@ namespace Mantid
/// Silence NeXus output
void disableNexusOutput();
Kernel::Logger& g_log; ///< Reference to the logger class
/// The registry of FileLoader algorithms
FileLoaderRegistry m_fileLoaderRegistry;
/// Reference to the logger class
Kernel::Logger& g_log;
#ifdef MPI_BUILD
#ifdef MPI_BUILD
/** Member variable that initialises the MPI environment on construction (in the
* FrameworkManager constructor) and finalises it on destruction.
* The class has no non-static member functions, so is not exposed in the class interface.
......@@ -137,4 +146,4 @@ namespace Mantid
} // namespace Kernel
} // namespace Mantid
#endif /*MANTID_KERNEL_FRAMEWORKMANAGER_H_*/
#endif /*MANTID_API_FRAMEWORKMANAGER_H_*/
#ifndef MANTID_API_REGISTERFILELOADER_H_
#define MANTID_API_REGISTERFILELOADER_H_
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/FrameworkManager.h"
/**
* DECLARE_FILELOADER_ALGORITHM should be used in place of the standard
* DECLARE_ALGORITHM macro that both registers the algorithm as usual and subscribes it to the
* registry held in the FrameworkManager
*/
#define DECLARE_FILELOADER_ALGORITHM(classname) \
DECLARE_ALGORITHM(classname) \
namespace \
{\
Mantid::Kernel::RegistrationHelper \
reg_loader_##classname((Mantid::API::FrameworkManager::Instance().fileLoaderRegistry().subscribe(#classname), 0));\
}
#endif /* MANTID_API_REGISTERFILELOADER_H_ */
#include "MantidAPI/FileLoaderRegistry.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/Logger.h"
#include <Poco/File.h>
......@@ -13,7 +14,7 @@ namespace Mantid
/**
* Creates an empty registry
*/
FileLoaderRegistry::FileLoaderRegistry()
FileLoaderRegistry::FileLoaderRegistry() : m_log(Kernel::Logger::get("FileLoaderRegistry"))
{
}
......@@ -29,6 +30,7 @@ namespace Mantid
throw std::invalid_argument("FileLoaderRegistry::subscribe - Cannot subscribe '"
+ name + "'. An entry with that name already exists");
}
m_log.debug() << "Registered '" << name << "' as file loader\n";
}
/**
......@@ -43,6 +45,8 @@ namespace Mantid
{
throw std::invalid_argument("FileLoaderRegistry::chooserLoader - Cannot open file '" + filename + "'");
}
m_log.debug() << "Attempting to find loader for '" << filename << "'\n";
throw std::runtime_error("not implemented yet");
}
//----------------------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment