CatalogFactory.h 2.83 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2013 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
10
/* Used to register Catalog classes into the factory. creates a global object in
 *an
11
12
13
14
15
16
17
 * anonymous namespace. The object itself does nothing, but the comma operator
 * is used in the call to its constructor to effect a call to the factory's
 * subscribe method.
 *
 * The second operation that this macro performs is to provide the definition
 * of the CatalogID method for the concrete Catalog.
 */
18
19
20
21
22
23
24
#define DECLARE_CATALOG(classname)                                             \
  namespace {                                                                  \
  Mantid::Kernel::RegistrationHelper                                           \
      register_alg_##classname(((Mantid::API::CatalogFactory::Instance()       \
                                     .subscribe<classname>(#classname)),       \
                                0));                                           \
  }
25
26
27
28

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
29
#include "MantidAPI/DllConfig.h"
30
31
32
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/SingletonHolder.h"

33
34
35
36
37
38
namespace Mantid {
namespace API {
//----------------------------------------------------------------------
// Forward declaration
//----------------------------------------------------------------------
class ICatalog;
39

40
41
42
/**
 The factory is a singleton that hands out shared pointers to the base Catalog
 class.
43

44
45
46
47
48
 @author Sofia Antony, ISIS Rutherford Appleton Laboratory
 @date 01/10/2010
*/
class MANTID_API_DLL CatalogFactoryImpl
    : public Kernel::DynamicFactory<ICatalog> {
49
50
51
52
public:
  CatalogFactoryImpl(const CatalogFactoryImpl &) = delete;
  CatalogFactoryImpl &operator=(const CatalogFactoryImpl &) = delete;

53
54
55
private:
  friend struct Kernel::CreateUsingNew<CatalogFactoryImpl>;
  /// Private Constructor for singleton class
56
  CatalogFactoryImpl() = default;
57
  /// Private Destructor
58
  ~CatalogFactoryImpl() override = default;
59
60
61
62
  /// Stores pointers to already created Catalog instances, with their name as
  /// the key
  mutable std::map<std::string, boost::shared_ptr<ICatalog>> m_createdCatalogs;
};
63

64
65
/// The specialisation of the SingletonHolder class that holds the
/// CatalogFactory
66
using CatalogFactory = Mantid::Kernel::SingletonHolder<CatalogFactoryImpl>;
67

68
} // namespace API
69
70
} // namespace Mantid

71
72
namespace Mantid {
namespace Kernel {
73
74
EXTERN_MANTID_API template class MANTID_API_DLL
    Mantid::Kernel::SingletonHolder<Mantid::API::CatalogFactoryImpl>;
75
}
LamarMoore's avatar
LamarMoore committed
76
} // namespace Mantid