ICF 3.1.1.10
Technical documentation of ICF Libraries
CCompositeComponent.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#include <QtCore/QMap>
12
13// ICF includes
14#include <istd/CClassInfo.h>
15
17#include <icomp/IRegistry.h>
20
21
22namespace icomp
23{
24
25
26class IMetaInfoManager;
27
28
31 virtual public ICompositeComponent
32{
33public:
34 CCompositeComponent(bool manualAutoInit);
36
40 template <class InterfaceType>
41 InterfaceType* GetComponentInterface(const QByteArray& subId = "");
42
48
49 // reimplemented (icomp::ICompositeComponent)
50 virtual IComponent* GetSubcomponent(const QByteArray& componentId) const;
51 virtual const IComponentContext* GetSubcomponentContext(const QByteArray& componentId) const;
52 virtual std::unique_ptr<IComponent> CreateSubcomponent(const QByteArray& componentId) const;
53 virtual void OnSubcomponentDeleted(const IComponent* subcomponentPtr);
54
55 // reimplemented (icomp::IComponent)
56 virtual const ICompositeComponent* GetParentComponent(bool ownerOnly = false) const;
57 virtual void* GetInterface(const istd::CClassInfo& interfaceType, const QByteArray& subId = "");
58 virtual const IComponentContext* GetComponentContext() const;
59 virtual void SetComponentContext(
60 const IComponentContext* contextPtr,
61 const ICompositeComponent* parentPtr,
62 bool isParentOwner);
63
64protected:
65 typedef std::unique_ptr<IComponent> ComponentPtr;
66 typedef std::unique_ptr<IComponentContext> ContextPtr;
67
77 const QByteArray& componentId,
78 ContextPtr& subContextPtr,
79 ComponentPtr* subComponentPtr,
80 bool isOwned) const;
81
82private:
83 struct ComponentInfo
84 {
88 ComponentPtr componentPtr;
93 bool isComponentInitialized = false;
97 ContextPtr contextPtr;
102 bool isContextInitialized = false;
103 };
104
105 typedef std::map< QByteArray, ComponentInfo> ComponentMap;
106 mutable ComponentMap m_componentMap;
107
108 const CCompositeComponentContext* m_contextPtr;
109 const ICompositeComponent* m_parentPtr;
110 bool m_isParentOwner;
111
112 bool m_manualAutoInit;
113
114 mutable bool m_autoInitialized;
115 mutable IRegistry::Ids m_autoInitComponentIds;
116};
117
118
119// inline methods
120
121template <class InterfaceType>
122inline InterfaceType* CCompositeComponent::GetComponentInterface(const QByteArray& subId)
123{
124 static istd::CClassInfo info(typeid(InterfaceType));
125
126 return static_cast<InterfaceType*>(GetInterface(info, subId));
127}
128
129
130} // namespace icomp
131
132
virtual void SetComponentContext(const IComponentContext *contextPtr, const ICompositeComponent *parentPtr, bool isParentOwner)
Set component context of this component.
std::unique_ptr< IComponentContext > ContextPtr
virtual std::unique_ptr< IComponent > CreateSubcomponent(const QByteArray &componentId) const
Create instance of subcomponent using its ID.
virtual void OnSubcomponentDeleted(const IComponent *subcomponentPtr)
Called if subcomponent is removed from memory.
virtual const IComponentContext * GetComponentContext() const
Get access to component context describing all application-specified component information loaded fro...
bool CreateSubcomponentInfo(const QByteArray &componentId, ContextPtr &subContextPtr, ComponentPtr *subComponentPtr, bool isOwned) const
Create information objects and subcomponent.
CCompositeComponent(bool manualAutoInit)
virtual void * GetInterface(const istd::CClassInfo &interfaceType, const QByteArray &subId="")
Get access to specified component interface.
bool EnsureAutoInitComponentsCreated() const
Make sure, all components with flag 'AutoInit' are initialized.
InterfaceType * GetComponentInterface(const QByteArray &subId="")
Get interface implemented by this composite component.
virtual const IComponentContext * GetSubcomponentContext(const QByteArray &componentId) const
Get access to context of subcomponent using its ID.
std::unique_ptr< IComponent > ComponentPtr
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const
Get parent of this component.
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const
Get access to subcomponent using its ID.
Provide session context of component.
Main component interface.
Definition IComponent.h:35
Composite component interface.
QSet< QByteArray > Ids
Definition IRegistry.h:32
Represents platform independent type info and provide set of static class manipulation functions.
Definition CClassInfo.h:27
Package with interfaces and class used for components concept.

© Witold Gantzke and Kirill Lepskiy