Skip to content
Snippets Groups Projects
  • Nick Draper's avatar
    ef3ccb58
    Merge pull request #23693 from mantidproject/23488_update_file_headers · ef3ccb58
    Nick Draper authored
    Update copyright headers in all files
    
    Squashed commit of the following:
    
    * First version of a script to manage copyright statements
    
    re #23468
    
    * Neatened up script, added comments
    
    re #23488
    
    * move script to tools directory
    
    re #23488
    
    * small script changes and a couple of manual file changes
    
    re #23488
    
    * Minor chnage to whitespace detection in regex
    
    re #23488
    
    * Add an excluded directory
    
    re #23488
    
    * remove a repeasted copyright statement in a file
    
    re #23488
    
    * Don't comsume the comment end if it is on the same line
    
    re #23488
    
    * fix error in new copright parsing
    
    re #23488
    
    * remove double copyrifght entry
    
    re #23488
    
    * Improve handling of old copyrights at the start of comments
    
    re #23488
    
    * remove empty comments re #23488
    
    * exclude gsoapgenerated directories
    
    re #23488
    
    * Sort out greedy line matching re #23488
    
    * improve empty comment removal
    
    re #23488
    
    * improve false positives
    
    re #23488
    
    * impressive speedup by limiting regex matching length
    
    re #23488
    
    * remove evil invisible non ascii character
    
    Also upadte the copyright at the same time
    
    re #23488
    
    * resolve multiple copyrights in a single file
    
    re #23488
    
    * resolve an issue with new statement detection
    
    re #23488
    
    * another unprintable unicode character
    
    re #23488
    
    * pep updates and cmake the new copyright fit clang format
    
    re #23488
    
    * update already done new format headers
    
    re #23488
    
    * wrong type of bracket
    
    re #23488
    
    * Update class_maker and friends
    
    re #23488
    
    * Update all copyright statements
    
    re #23488
    
    * clang format re #23488
    
    * flake8 warnings re #23488
    
    * Flake8 warnings re #23488
    
    * Exclude .cmake.in and rb.in files
    
    re #23488
    
    * replace missing line re #23488
    
    * exclude .py.in files as they are flasely recognized as C++
    
    re #23488
    
    * another setp.py.in re #23488
    
    * another .py.in correction re #23488
    
    * Hopefully the last of the .py.in files re #23488
    
    * resolve utf-8 encoding of python files and changed ABINS checksum
    
    re #23488
    
    * updates to unit tests that reference line numbers
    
    re #23488
    
    * remaining unit test files and other fixes
    
    re #23488
    ef3ccb58
    History
    Merge pull request #23693 from mantidproject/23488_update_file_headers
    Nick Draper authored
    Update copyright headers in all files
    
    Squashed commit of the following:
    
    * First version of a script to manage copyright statements
    
    re #23468
    
    * Neatened up script, added comments
    
    re #23488
    
    * move script to tools directory
    
    re #23488
    
    * small script changes and a couple of manual file changes
    
    re #23488
    
    * Minor chnage to whitespace detection in regex
    
    re #23488
    
    * Add an excluded directory
    
    re #23488
    
    * remove a repeasted copyright statement in a file
    
    re #23488
    
    * Don't comsume the comment end if it is on the same line
    
    re #23488
    
    * fix error in new copright parsing
    
    re #23488
    
    * remove double copyrifght entry
    
    re #23488
    
    * Improve handling of old copyrights at the start of comments
    
    re #23488
    
    * remove empty comments re #23488
    
    * exclude gsoapgenerated directories
    
    re #23488
    
    * Sort out greedy line matching re #23488
    
    * improve empty comment removal
    
    re #23488
    
    * improve false positives
    
    re #23488
    
    * impressive speedup by limiting regex matching length
    
    re #23488
    
    * remove evil invisible non ascii character
    
    Also upadte the copyright at the same time
    
    re #23488
    
    * resolve multiple copyrights in a single file
    
    re #23488
    
    * resolve an issue with new statement detection
    
    re #23488
    
    * another unprintable unicode character
    
    re #23488
    
    * pep updates and cmake the new copyright fit clang format
    
    re #23488
    
    * update already done new format headers
    
    re #23488
    
    * wrong type of bracket
    
    re #23488
    
    * Update class_maker and friends
    
    re #23488
    
    * Update all copyright statements
    
    re #23488
    
    * clang format re #23488
    
    * flake8 warnings re #23488
    
    * Flake8 warnings re #23488
    
    * Exclude .cmake.in and rb.in files
    
    re #23488
    
    * replace missing line re #23488
    
    * exclude .py.in files as they are flasely recognized as C++
    
    re #23488
    
    * another setp.py.in re #23488
    
    * another .py.in correction re #23488
    
    * Hopefully the last of the .py.in files re #23488
    
    * resolve utf-8 encoding of python files and changed ABINS checksum
    
    re #23488
    
    * updates to unit tests that reference line numbers
    
    re #23488
    
    * remaining unit test files and other fixes
    
    re #23488
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
FileLoaderRegistry.h 4.75 KiB
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2013 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef MANTID_API_FILELOADERREGISTRY_H_
#define MANTID_API_FILELOADERREGISTRY_H_

#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidKernel/SingletonHolder.h"

#ifndef Q_MOC_RUN
#include <type_traits>
#endif

#include <map>
#include <string>
#include <vector>

namespace Mantid {
namespace Kernel {

class Logger;
}
namespace API {

class IAlgorithm;

/**
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
 */
class MANTID_API_DLL FileLoaderRegistryImpl {
public:
  /// Defines types of possible file
  enum LoaderFormat { Nexus, Generic };

public:
  /// @returns the number of entries in the registry
  inline size_t size() const { return m_totalSize; }

  /**
   * 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.
   * @param format The type of loader being subscribed, see LoaderFormat
   * @throws std::invalid_argument if an entry with this name already exists
   */
  template <typename Type> void subscribe(LoaderFormat format) {
    SubscriptionValidator<Type>::check(format);
    const auto nameVersion = AlgorithmFactory::Instance().subscribe<Type>();
    // If the factory didn't throw then the name is valid
    m_names[format].insert(nameVersion);
    m_totalSize += 1;
    m_log.debug() << "Registered '" << nameVersion.first << "' version '"
                  << nameVersion.second << "' as file loader\n";
  }

  /// Unsubscribe a named algorithm and version from the loader registration
  void unsubscribe(const std::string &name, const int version = -1);

  /// Returns the name of an Algorithm that can load the given filename
  const boost::shared_ptr<IAlgorithm>
  chooseLoader(const std::string &filename) const;
  /// Checks whether the given algorithm can load the file
  bool canLoad(const std::string &algorithmName,
               const std::string &filename) const;

private:
  /// Friend so that CreateUsingNew
  friend struct Mantid::Kernel::CreateUsingNew<FileLoaderRegistryImpl>;

  /// Default constructor (for singleton)
  FileLoaderRegistryImpl();
  /// Destructor
  ~FileLoaderRegistryImpl();

  /// Helper for subscribe to check base class
  template <typename T> struct SubscriptionValidator {
    static void check(LoaderFormat format) {
      switch (format) {
      case Nexus:
        if (!std::is_base_of<IFileLoader<Kernel::NexusDescriptor>, T>::value) {
          throw std::runtime_error(
              std::string("FileLoaderRegistryImpl::subscribe - Class '") +
              typeid(T).name() +
              "' registered as Nexus loader but it does not "
              "inherit from "
              "API::IFileLoader<Kernel::NexusDescriptor>");
        }
        break;
      case Generic:
        if (!std::is_base_of<IFileLoader<Kernel::FileDescriptor>, T>::value) {
          throw std::runtime_error(
              std::string("FileLoaderRegistryImpl::subscribe - Class '") +
              typeid(T).name() +
              "' registered as Generic loader but it does "
              "not inherit from "
              "API::IFileLoader<Kernel::FileDescriptor>");
        }
        break;
      default:
        throw std::runtime_error("Invalid LoaderFormat given");
      }
    }
  };

  /// Remove a named algorithm & version from the given map
  void removeAlgorithm(const std::string &name, const int version,
                       std::multimap<std::string, int> &typedLoaders);

  /// The list of names. The index pointed to by LoaderFormat defines a set for
  /// that format
  std::vector<std::multimap<std::string, int>> m_names;
  /// Total number of names registered
  size_t m_totalSize;

  /// Reference to a logger
  mutable Kernel::Logger m_log;
};

/// Type for the actual singleton instance
using FileLoaderRegistry =
    Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl>;

} // namespace API
} // namespace Mantid

namespace Mantid {
namespace Kernel {
EXTERN_MANTID_API template class MANTID_API_DLL
    Mantid::Kernel::SingletonHolder<Mantid::API::FileLoaderRegistryImpl>;
}
} // namespace Mantid

#endif /* MANTID_API_FILELOADERREGISTRY_H_ */