ImagingTools Core SDK
TComponentFactoryComp.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// ACF includes
6#include <icomp/CComponentBase.h>
7
8
9namespace imtbase
10{
11
12
16template <typename ObjectInterface>
18 public icomp::CComponentBase,
19 public istd::TIFactory<ObjectInterface>
20{
21public:
22 typedef icomp::CComponentBase BaseClass;
23 typedef istd::TIFactory<ObjectInterface> FactoryInterface;
24
25 I_BEGIN_COMPONENT(TComponentFactoryComp);
26 I_REGISTER_INTERFACE(FactoryInterface);
27 I_ASSIGN(m_factCompPtr, "Factory", "Factory used for creation of the object instance", true, "Factory");
28 I_ASSIGN(m_typeIdAttrPtr, "TypeId", "Type-ID of the instance to be created", true, "TypeId");
29 I_END_COMPONENT;
30
31 // reimplemented (istd::TIFactory)
32 virtual istd::TUniqueInterfacePtr<ObjectInterface> CreateInstance(const QByteArray& keyId = "") const override;
33
34 // reimplemented (istd::IFactoryInfo)
35 virtual istd::IFactoryInfo::KeyList GetFactoryKeys() const override;
36
37private:
38 I_TFACT(ObjectInterface, m_factCompPtr);
39 I_ATTR(QByteArray, m_typeIdAttrPtr);
40};
41
42
43// reimplemented (istd::TIFactory)
44
45template<typename ObjectInterface>
46istd::TUniqueInterfacePtr<ObjectInterface> TComponentFactoryComp<ObjectInterface>::CreateInstance(const QByteArray& /*keyId*/) const
47{
48 auto componentPtr = m_factCompPtr.CreateInstance();
49 istd::TUniqueInterfacePtr<ObjectInterface> retVal;
50 retVal.MoveCastedPtr(std::move(componentPtr));
51 return retVal;
52}
53
54
55template<typename ObjectInterface>
56istd::IFactoryInfo::KeyList TComponentFactoryComp<ObjectInterface>::GetFactoryKeys() const
57{
58 istd::IFactoryInfo::KeyList keys;
59
60 keys.insert(*m_typeIdAttrPtr);
61
62 return keys;
63}
64
65
66} // namespace imtbase
67
68