ICF 3.1.1.10
Technical documentation of ICF Libraries
CSimComponentContextBase.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/QString>
12#include <QtCore/QMap>
13
14// ICF includes
15#include <istd/TIFactory.h>
16#include <istd/CIdManipBase.h>
18#include <iattr/TAttribute.h>
20#include <icomp/IComponent.h>
26
27
28namespace icomp
29{
30
31
33 public IComponentContext,
34 protected istd::CIdManipBase
35{
36public:
38
40
46 bool SetAttr(const QByteArray& attributeId, const iser::IObject* attributePtr);
47
51 bool SetRef(const QByteArray& referenceId, IComponent* componentPtr, const QByteArray& subelementId = "");
52
56 bool InsertMultiRef(const QByteArray& referenceId, IComponent* componentPtr, const QByteArray& subelementId = "");
57
61 bool SetFactory(const QByteArray& factoryId, const ComponentsFactory* factoryPtr);
62
66 bool InsertMultiFactory(const QByteArray& factoryId, const ComponentsFactory* factoryPtr);
67
71 bool SetBoolAttr(const QByteArray& attributeId, bool value);
72
76 bool SetIntAttr(const QByteArray& attributeId, int value);
77
81 bool SetDoubleAttr(const QByteArray& attributeId, double value);
82
86 bool SetStringAttr(const QByteArray& attributeId, const QString& value);
87
91 bool SetIdAttr(const QByteArray& attributeId, const QByteArray& value);
92
98 template <class Attribute>
99 bool InsertMultiAttr(const QByteArray& attributeId, const Attribute& attribute)
100 {
102
103 iattr::TMultiAttribute<Attribute>* multiAttrPtr = nullptr;
104
105 const IRegistryElement::AttributeInfo* existingInfoPtr = m_registryElement.GetAttributeInfo(attributeId);
106 if (existingInfoPtr != nullptr){
107 multiAttrPtr = dynamic_cast<iattr::TMultiAttribute<Attribute>*>(existingInfoPtr->attributePtr.get());
108 }
109 else{
111 if (newInfoPtr != nullptr){
112 IRegistryElement::AttributePtr& attributePtr = newInfoPtr->attributePtr;
113 if (attribute == nullptr){
114 attributePtr = std::make_unique<iattr::TMultiAttribute<Attribute>>();
115 }
116
117 multiAttrPtr = dynamic_cast<iattr::TMultiAttribute<Attribute>*>(attributePtr.get());
118 }
119 }
120
121 if (multiAttrPtr != nullptr){
122 multiAttrPtr->InsertValue(attribute);
123
124 return true;
125 }
126
127 return false;
128 }
129
130 bool InsertMultiAttr(const QByteArray& attributeId, const QString& attribute);
131
132 // reimplemeted (icomp::IComponentContext)
133 virtual const IRegistryElement& GetRegistryElement() const;
134 virtual const IComponentStaticInfo& GetStaticInfo() const;
135 virtual const IComponentContext* GetParentContext() const;
136 virtual const iser::IObject* GetAttribute(const QByteArray& attributeId, int* definitionLevelPtr = nullptr) const;
137
138protected:
142 template <class AttrType>
143 bool IsAttributeTypeCorrect(const QByteArray& attributeId);
144
145 typedef QMap<QByteArray, IComponent*> ComponentsMap;
147
148 typedef QMap< QByteArray, const ComponentsFactory* > FactoriesMap;
150
151private:
152 CRegistryElement m_registryElement;
153 const IComponentStaticInfo& m_metaInfo;
154};
155
156
157// protected methods
158
159template <class AttrType>
160bool CSimComponentContextBase::IsAttributeTypeCorrect(const QByteArray& attributeId)
161{
162 const IAttributeStaticInfo* attributeInfoPtr = m_metaInfo.GetAttributeInfo(attributeId);
163 if (attributeInfoPtr != nullptr){
164 QByteArray attributeType = attributeInfoPtr->GetAttributeTypeId();
165
166 return attributeType == AttrType::GetTypeName();
167 }
168
169 return false;
170}
171
172
173} // namespace icomp
174
175
virtual QByteArray GetAttributeTypeId() const =0
Return attribute type ID.
Template implementation of multiple component attribute.
virtual void InsertValue(const Value &value)
virtual AttributeInfo * GetAttributeInfo(const QByteArray &attributeId)
virtual AttributeInfo * InsertAttributeInfo(const QByteArray &attributeId, const QByteArray &attributeType)
Insert new attribute info object to collection of attributes.
CSimComponentContextBase(const IComponentStaticInfo *infoPtr)
QMap< QByteArray, IComponent * > ComponentsMap
bool SetIdAttr(const QByteArray &attributeId, const QByteArray &value)
Set instance of QByteArray attribute.
istd::TIFactory< IComponent > ComponentsFactory
bool InsertMultiAttr(const QByteArray &attributeId, const QString &attribute)
virtual const iser::IObject * GetAttribute(const QByteArray &attributeId, int *definitionLevelPtr=nullptr) const
Get attribute using its ID.
virtual const IRegistryElement & GetRegistryElement() const
Get access to component registry element object.
bool InsertMultiAttr(const QByteArray &attributeId, const Attribute &attribute)
Insert new attribute to multi attributes.
bool SetFactory(const QByteArray &factoryId, const ComponentsFactory *factoryPtr)
Set factory of component instance.
bool SetBoolAttr(const QByteArray &attributeId, bool value)
Set instance of bool attribute.
bool SetAttr(const QByteArray &attributeId, const iser::IObject *attributePtr)
Set named attribute.
bool IsAttributeTypeCorrect(const QByteArray &attributeId)
Check if attribute type is corrected.
bool InsertMultiRef(const QByteArray &referenceId, IComponent *componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
bool SetStringAttr(const QByteArray &attributeId, const QString &value)
Set instance of QString attribute.
bool SetRef(const QByteArray &referenceId, IComponent *componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
QMap< QByteArray, const ComponentsFactory * > FactoriesMap
bool InsertMultiFactory(const QByteArray &factoryId, const ComponentsFactory *factoryPtr)
Insert new factory instance into multi-factory attribute.
virtual const IComponentStaticInfo & GetStaticInfo() const
Get component static info associated with this context.
bool SetDoubleAttr(const QByteArray &attributeId, double value)
Set instance of double attribute.
bool SetIntAttr(const QByteArray &attributeId, int value)
Set instance of int attribute.
virtual const IComponentContext * GetParentContext() const
Get access to parent component context.
Describe component attribute static information.
Provide session context of component.
Main component interface.
Definition IComponent.h:35
This interface provide static information about component meta info.
virtual const IAttributeStaticInfo * GetAttributeInfo(const QByteArray &attributeId) const =0
Get set of attributes.
Represents element of registry describing component parameters.
std::unique_ptr< iser::IObject > AttributePtr
Common interface for factorisable model objects.
Definition IObject.h:25
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition CClassInfo.h:150
Base implementation for operations on composed ID objects.
Generic interface for a factory.
Definition TIFactory.h:22
Package with interfaces and class used for components concept.
Describe information stored with each attribute.

© Witold Gantzke and Kirill Lepskiy