ICF 3.0.5.47
Technical documentation of ICF Libraries
TSimComponentsFactory.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// ICF includes
10#include <istd/TIFactory.h>
11#include <istd/CClassInfo.h>
12
13#include <icomp/IComponent.h>
16
17
18namespace icomp
19{
20
21
26template <class Base>
27class TSimComponentsFactory: public TSimComponentWrap<Base>, public istd::TIFactory<IComponent>
28{
29public:
31
33
34 // reimplemented (istd::IFactoryInfo)
36
37 // reimplemented (istd::TIFactory<icomp::IComponent>)
38 virtual std::unique_ptr<IComponent> CreateInstance(const QByteArray& keyId = "") const;
39
40 // reimplemented (icomp::ICompositeComponent)
41 virtual std::unique_ptr<IComponent> CreateSubcomponent(const QByteArray& componentId) const;
42
43private:
44 KeyList m_factoryKeys;
45};
46
47
48// public methods
49
50template <class Base>
55
56
57// reimplemented (istd::IFactoryInfo)
58
59template <class Base>
64
65
66// reimplemented (istd::TIFactory<icomp::IComponent>)
67
68template <class Base>
69std::unique_ptr<IComponent> TSimComponentsFactory<Base>::CreateInstance(const QByteArray& keyId) const
70{
71 if (keyId.isEmpty() || m_factoryKeys.contains(keyId)){
72 auto* retVal = new TComponentWrap<Base>();
73 if (retVal != nullptr){
74 retVal->SetComponentContext(this, this, false);
75 return std::unique_ptr<IComponent>{retVal};
76 }
77 }
78
79 return nullptr;
80}
81
82
83// reimplemented (icomp::ICompositeComponent)
84
85template <class Base>
86std::unique_ptr<IComponent> TSimComponentsFactory<Base>::CreateSubcomponent(const QByteArray& componentId) const
87{
88 auto componentPtr = BaseClass::CreateSubcomponent(componentId);
89 if (componentPtr != nullptr){
90 return componentPtr;
91 }
92
93 return CreateInstance(componentId);
94}
95
96
97} // namespace icomp
98
99
Wrapper of end component implementation used to correct control of component life-cycle.
Simulation wrapper of component.
Simulation wrapper of component.
virtual std::unique_ptr< IComponent > CreateSubcomponent(const QByteArray &componentId) const
Create instance of subcomponent using its ID.
virtual istd::IFactoryInfo::KeyList GetFactoryKeys() const
Returns all posible keys for this factory.
TSimComponentWrap< Base > BaseClass
virtual std::unique_ptr< IComponent > CreateInstance(const QByteArray &keyId="") const
Create an instance of the object, mapped to the keyId keyId.
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition CClassInfo.h:150
QSet< QByteArray > KeyList
Generic interface for a factory.
Definition TIFactory.h:22
Package with interfaces and class used for components concept.

© Witold Gantzke and Kirill Lepskiy