Skip to content

Commit

Permalink
Add DECLARE_FILELOADER_ALGORITHM macro. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jun 27, 2013
1 parent 886d0b0 commit b846d13
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/FileLoaderRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions Code/Mantid/Framework/API/inc/MantidAPI/FrameworkManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MANTID_KERNEL_FRAMEWORKMANAGER_H_
#define MANTID_KERNEL_FRAMEWORKMANAGER_H_
#ifndef MANTID_API_FRAMEWORKMANAGER_H_
#define MANTID_API_FRAMEWORKMANAGER_H_

//----------------------------------------------------------------------
// Includes
Expand All @@ -11,6 +11,7 @@
#endif

#include "MantidAPI/DllConfig.h"
#include "MantidAPI/FileLoaderRegistry.h"
#include "MantidKernel/SingletonHolder.h"
#include <boost/shared_ptr.hpp>

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand All @@ -137,4 +146,4 @@ namespace Mantid
} // namespace Kernel
} // namespace Mantid

#endif /*MANTID_KERNEL_FRAMEWORKMANAGER_H_*/
#endif /*MANTID_API_FRAMEWORKMANAGER_H_*/
20 changes: 20 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/RegisterFileLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#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_ */
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MantidAPI/FileLoaderRegistry.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/Logger.h"

#include <Poco/File.h>

Expand All @@ -13,7 +14,7 @@ namespace Mantid
/**
* Creates an empty registry
*/
FileLoaderRegistry::FileLoaderRegistry()
FileLoaderRegistry::FileLoaderRegistry() : m_log(Kernel::Logger::get("FileLoaderRegistry"))
{
}

Expand All @@ -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";
}

/**
Expand All @@ -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");
}

//----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit b846d13

Please sign in to comment.