Mantid
Loading...
Searching...
No Matches
UnitFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9/* Used to register unit classes into the factory. creates a global object in an
10 * anonymous namespace. The object itself does nothing, but the comma operator
11 * is used in the call to its constructor to effect a call to the factory's
12 * subscribe method.
13 *
14 * The second operation that this macro performs is to provide the definition
15 * of the unitID method for the concrete unit.
16 */
17#define DECLARE_UNIT(classname) \
18 namespace { \
19 Mantid::Kernel::RegistrationHelper \
20 register_unit_##classname(((Mantid::Kernel::UnitFactory::Instance().subscribe<classname>(#classname)), 0)); \
21 } \
22 const std::string Mantid::Kernel::Units::classname::unitID() const { return #classname; }
23
24//----------------------------------------------------------------------
25// Includes
26//----------------------------------------------------------------------
27#include "MantidKernel/DllConfig.h"
30#include "MantidKernel/Unit.h"
31
32namespace Mantid {
33namespace Kernel {
34
47class MANTID_KERNEL_DLL UnitFactoryImpl final : public DynamicFactory<Unit> {
48public:
51
54 const std::vector<std::string> getConvertibleUnits() const {
55 std::vector<std::string> convertibleUnits;
56
57 for (const auto &unitKey : getKeys()) {
58 const auto unit_sptr = create(unitKey);
59 if (unit_sptr->isConvertible()) {
60 convertibleUnits.emplace_back(unitKey);
61 }
62 }
63
64 return convertibleUnits;
65 }
66
67private:
68 friend struct CreateUsingNew<UnitFactoryImpl>;
69
71 UnitFactoryImpl() = default;
72
74 ~UnitFactoryImpl() override = default;
75};
76
77EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<UnitFactoryImpl>;
78
80
81} // namespace Kernel
82} // namespace Mantid
The dynamic factory is a base dynamic factory for serving up objects in response to requests from oth...
Manage the lifetime of a class intended to be a singleton.
Creates instances of concrete units.
Definition: UnitFactory.h:47
UnitFactoryImpl()=default
Private Constructor for singleton class.
UnitFactoryImpl & operator=(const UnitFactoryImpl &)=delete
~UnitFactoryImpl() override=default
Private Destructor.
UnitFactoryImpl(const UnitFactoryImpl &)=delete
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...