ACF $AcfVersion:0$
TSingleFactory.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QByteArray>
7
8// ACF includes
9#include <istd/TIFactory.h>
10
11
12namespace istd
13{
14
15
19template <class Interface, class Implementation>
20class TSingleFactory: virtual public TIFactory<Interface>
21{
22public:
23 typedef Implementation ImplementationType;
25
26 explicit TSingleFactory(const QByteArray& keyId);
27
28 // reimplemented (istd::IFactoryInfo)
29 virtual IFactoryInfo::KeyList GetFactoryKeys() const override;
30
31 // reimplemented (istd::TIFactory)
32 virtual istd::TUniqueInterfacePtr<Interface> CreateInstance(const QByteArray& keyId = "") const override;
33
34private:
35 QByteArray m_keyId;
36};
37
38
39// public methods
40
41template <class Interface, class Implementation>
43: m_keyId(keyId)
44{
45
46}
47
48
49// reimplemented (istd::TIFactory)
50
51template <class Interface, class Implementation>
53{
54 typename TIFactory<Interface>::KeyList retVal;
55
56 retVal.insert(m_keyId);
57
58 return retVal;
59}
60
61
62template <class Interface, class Implementation>
64{
65 if (keyId.isEmpty() || (keyId == m_keyId)){
66 return istd::TUniqueInterfacePtr<Interface>(new Implementation);
67 }
68
70}
71
72
73} // namespace istd
74
75
76
77
QSet< QByteArray > KeyList
Generic interface for a factory.
Definition TIFactory.h:19
Template based object factory interface.
virtual IFactoryInfo::KeyList GetFactoryKeys() const override
Returns all possible keys for this factory.
TSingleFactory(const QByteArray &keyId)
Implementation ImplementationType
virtual istd::TUniqueInterfacePtr< Interface > CreateInstance(const QByteArray &keyId="") const override
Create an instance of the object, mapped to the keyId keyId.
TIFactory< Interface > FactoryInterface
Unique ownership smart pointer for interface types.
Standard library.
Definition IComponent.h:17