ACF $AcfVersion:0$
CSimComponentContextBase.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QByteArray>
7#include <QtCore/QString>
8#include <QtCore/QMap>
9
10// ACF includes
11#include <istd/TIFactory.h>
12#include <istd/CIdManipBase.h>
14#include <iattr/TAttribute.h>
16#include <icomp/IComponent.h>
22
23
24namespace icomp
25{
26
27
29 public IComponentContext,
30 protected istd::CIdManipBase
31{
32public:
34
36
42 bool SetAttr(const QByteArray& attributeId, const iser::IObject* attributePtr);
43
47 bool SetRef(const QByteArray& referenceId, IComponentSharedPtr componentPtr, const QByteArray& subelementId = "");
48
52 bool InsertMultiRef(const QByteArray& referenceId, IComponentSharedPtr componentPtr, const QByteArray& subelementId = "");
53
57 bool SetFactory(const QByteArray& factoryId, const ComponentsFactory* factoryPtr);
58
62 bool InsertMultiFactory(const QByteArray& factoryId, const ComponentsFactory* factoryPtr);
63
67 bool SetBoolAttr(const QByteArray& attributeId, bool value);
68
72 bool SetIntAttr(const QByteArray& attributeId, int value);
73
77 bool SetDoubleAttr(const QByteArray& attributeId, double value);
78
82 bool SetStringAttr(const QByteArray& attributeId, const QString& value);
83
87 bool SetIdAttr(const QByteArray& attributeId, const QByteArray& value);
88
94 template <class Attribute>
95 bool InsertMultiAttr(const QByteArray& attributeId, const Attribute& attribute)
96 {
98
100
101 const IRegistryElement::AttributeInfo* existingInfoPtr = m_registryElement.GetAttributeInfo(attributeId);
102 if (existingInfoPtr != NULL){
103 multiAttrPtr = dynamic_cast<iattr::TMultiAttribute<Attribute>*>(existingInfoPtr->attributePtr.GetPtr());
104 }
105 else{
107 if (newInfoPtr != NULL){
108 IRegistryElement::AttributePtr& attributePtr = newInfoPtr->attributePtr;
109 if (!attributePtr.IsValid()){
111 }
112
113 multiAttrPtr = dynamic_cast<iattr::TMultiAttribute<Attribute>*>(attributePtr.GetPtr());
114 }
115 }
116
117 if (multiAttrPtr != NULL){
118 multiAttrPtr->InsertValue(attribute);
119
120 return true;
121 }
122
123 return false;
124 }
125
126 bool InsertMultiAttr(const QByteArray& attributeId, const QString& attribute);
127
128 // reimplemeted (icomp::IComponentContext)
129 virtual const IRegistryElement& GetRegistryElement() const override;
130 virtual const IComponentStaticInfo& GetStaticInfo() const override;
131 virtual const IComponentContext* GetParentContext() const override;
132 virtual const iser::IObject* GetAttribute(const QByteArray& attributeId, int* definitionLevelPtr = NULL) const override;
133
134protected:
138 template <class AttrType>
139 bool IsAttributeTypeCorrect(const QByteArray& attributeId);
140
141 typedef QMap<QByteArray, IComponentSharedPtr> ComponentsMap;
143
144 typedef QMap< QByteArray, const ComponentsFactory* > FactoriesMap;
146
147private:
148 CRegistryElement m_registryElement;
149 const IComponentStaticInfo& m_metaInfo;
150};
151
152
153// protected methods
154
155template <class AttrType>
156bool CSimComponentContextBase::IsAttributeTypeCorrect(const QByteArray& attributeId)
157{
158 const IAttributeStaticInfo* attributeInfoPtr = m_metaInfo.GetAttributeInfo(attributeId);
159 if (attributeInfoPtr != NULL){
160 QByteArray attributeType = attributeInfoPtr->GetAttributeTypeId();
161
162 return attributeType == AttrType::GetTypeName();
163 }
164
165 return false;
166}
167
168
169} // namespace icomp
170
171
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) override
Insert new attribute info object to collection of attributes.
CSimComponentContextBase(const IComponentStaticInfo *infoPtr)
virtual const IComponentContext * GetParentContext() const override
Get access to parent component context.
virtual const iser::IObject * GetAttribute(const QByteArray &attributeId, int *definitionLevelPtr=NULL) const override
Get attribute using its ID.
bool SetIdAttr(const QByteArray &attributeId, const QByteArray &value)
Set instance of QByteArray attribute.
virtual const IComponentStaticInfo & GetStaticInfo() const override
Get component static info associated with this context.
QMap< QByteArray, const ComponentsFactory * > FactoriesMap
bool InsertMultiAttr(const QByteArray &attributeId, const QString &attribute)
virtual const IRegistryElement & GetRegistryElement() const override
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 SetStringAttr(const QByteArray &attributeId, const QString &value)
Set instance of QString attribute.
QMap< QByteArray, IComponentSharedPtr > ComponentsMap
bool InsertMultiFactory(const QByteArray &factoryId, const ComponentsFactory *factoryPtr)
Insert new factory instance into multi-factory attribute.
bool SetDoubleAttr(const QByteArray &attributeId, double value)
Set instance of double attribute.
bool SetIntAttr(const QByteArray &attributeId, int value)
Set instance of int attribute.
bool SetRef(const QByteArray &referenceId, IComponentSharedPtr componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
istd::TIFactory< icomp::IComponent > ComponentsFactory
bool InsertMultiRef(const QByteArray &referenceId, IComponentSharedPtr componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
Describe component attribute static information.
Provide session context of component.
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.
Common interface for factorisable model objects.
Definition IObject.h:23
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition CClassInfo.h:154
Base implementation for operations on composed ID objects.
void SetPtr(Type *ptr)
Set new value of internal pointer.
Definition TDelPtr.h:161
Generic interface for a factory.
Definition TIFactory.h:19
bool IsValid() const
Check if internal pointer not NULL.
Type * GetPtr() const
Return access to internal stored pointer.
#define NULL
Definition istd.h:74
Package with interfaces and class used for components concept.
std::shared_ptr< IComponent > IComponentSharedPtr
Definition IComponent.h:71
Describe information stored with each attribute.