ICF 3.1.1.10
Technical documentation of ICF Libraries
TSingleFactory.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QByteArray>
11
12// ICF includes
13#include <istd/TIFactory.h>
14
15
16namespace istd
17{
18
19
23template <class Interface, class Implementation>
24class TSingleFactory: virtual public TIFactory<Interface>
25{
26public:
27 typedef Implementation ImplementationType;
29
30 explicit TSingleFactory(const QByteArray& keyId);
31
32 // reimplemented (istd::IFactoryInfo)
34
35 // reimplemented (istd::TIFactory)
36 virtual std::unique_ptr<Interface> CreateInstance(const QByteArray& keyId = "") const;
37
38private:
39 QByteArray m_keyId;
40};
41
42
43// public methods
44
45template <class Interface, class Implementation>
47: m_keyId(keyId)
48{
49
50}
51
52
53// reimplemented (istd::TIFactory)
54
55template <class Interface, class Implementation>
57{
58 typename TIFactory<Interface>::KeyList retVal;
59
60 retVal.insert(m_keyId);
61
62 return retVal;
63}
64
65
66template <class Interface, class Implementation>
67std::unique_ptr<Interface> TSingleFactory<Interface, Implementation>::CreateInstance(const QByteArray& keyId) const
68{
69 if (keyId.isEmpty() || (keyId == m_keyId)){
70 return std::unique_ptr<Interface>{new Implementation};
71 }
72
73 return nullptr;
74}
75
76
77} // namespace istd
78
79
QSet< QByteArray > KeyList
Generic interface for a factory.
Definition TIFactory.h:22
Template based object factory interface.
TSingleFactory(const QByteArray &keyId)
TIFactory< Interface > FactoryInterface
virtual IFactoryInfo::KeyList GetFactoryKeys() const
Returns all posible keys for this factory.
virtual std::unique_ptr< Interface > CreateInstance(const QByteArray &keyId="") const
Create an instance of the object, mapped to the keyId keyId.
Implementation ImplementationType
Standard library.
Definition IComponent.h:17

© Witold Gantzke and Kirill Lepskiy