CSimComponentContextBase.h
Go to the documentation of this file.
1 #ifndef icomp_CSimComponentContextBase_included
2 #define icomp_CSimComponentContextBase_included
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>
15 #include <iattr/TMultiAttribute.h>
16 #include <icomp/IComponent.h>
19 #include <icomp/TAttributeMember.h>
21 #include <icomp/CRegistryElement.h>
22 
23 
24 namespace icomp
25 {
26 
27 
29  public IComponentContext,
30  protected istd::CIdManipBase
31 {
32 public:
34 
35  explicit CSimComponentContextBase(const IComponentStaticInfo* infoPtr);
36 
42  bool SetAttr(const QByteArray& attributeId, const iser::IObject* attributePtr);
43 
47  bool SetRef(const QByteArray& referenceId, IComponent* componentPtr, const QByteArray& subelementId = "");
48 
52  bool InsertMultiRef(const QByteArray& referenceId, IComponent* 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()){
110  attributePtr.SetPtr(new iattr::TMultiAttribute<Attribute>);
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;
130  virtual const IComponentStaticInfo& GetStaticInfo() const;
131  virtual const IComponentContext* GetParentContext() const;
132  virtual const iser::IObject* GetAttribute(const QByteArray& attributeId, int* definitionLevelPtr = NULL) const;
133 
134 protected:
138  template <class AttrType>
139  bool IsAttributeTypeCorrect(const QByteArray& attributeId);
140 
141  typedef QMap<QByteArray, IComponent*> ComponentsMap;
143 
144  typedef QMap< QByteArray, const ComponentsFactory* > FactoriesMap;
146 
147 private:
148  CRegistryElement m_registryElement;
149  const IComponentStaticInfo& m_metaInfo;
150 };
151 
152 
153 // protected methods
154 
155 template <class AttrType>
156 bool 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 
172 #endif // !icomp_CSimComponentContextBase_included
173 
174 
virtual const IComponentContext * GetParentContext() const
Get access to parent component context.
CSimComponentContextBase(const IComponentStaticInfo *infoPtr)
virtual const iser::IObject * GetAttribute(const QByteArray &attributeId, int *definitionLevelPtr=NULL) const
Get attribute using its ID.
Template implementation of multiple component attribute.
bool SetFactory(const QByteArray &factoryId, const ComponentsFactory *factoryPtr)
Set factory of component instance.
bool IsValid() const
Check if internal pointer not NULL.
Definition: TPointerBase.h:136
bool SetRef(const QByteArray &referenceId, IComponent *componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
bool SetIdAttr(const QByteArray &attributeId, const QByteArray &value)
Set instance of QByteArray attribute.
Main component interface.
Definition: IComponent.h:31
QMap< QByteArray, IComponent * > ComponentsMap
const QByteArray & GetName() const
Get undecorated and platform undependent class name.
Definition: CClassInfo.h:146
Provide session context of component.
Common interface for factorisable model objects.
Definition: IObject.h:19
virtual AttributeInfo * InsertAttributeInfo(const QByteArray &attributeId, const QByteArray &attributeType)
Insert new attribute info object to collection of attributes.
bool InsertMultiFactory(const QByteArray &factoryId, const ComponentsFactory *factoryPtr)
Insert new factory instance into multi-factory attribute.
istd::TIFactory< icomp::IComponent > ComponentsFactory
bool SetIntAttr(const QByteArray &attributeId, int value)
Set instance of int attribute.
bool InsertMultiAttr(const QByteArray &attributeId, const Attribute &attribute)
Insert new attribute to multi attributes.
bool SetBoolAttr(const QByteArray &attributeId, bool value)
Set instance of bool attribute.
virtual QByteArray GetAttributeTypeId() const =0
Return attribute type ID.
QMap< QByteArray, const ComponentsFactory * > FactoriesMap
Type * GetPtr() const
Return access to internal stored pointer.
Definition: TPointerBase.h:129
virtual const IComponentStaticInfo & GetStaticInfo() const
Get component static info associated with this context.
Represents element of registry describing component parameters.
#define NULL
Definition: istd.h:64
Base implementation for operations on composed ID objects.
Definition: CIdManipBase.h:19
bool SetAttr(const QByteArray &attributeId, const iser::IObject *attributePtr)
Set named attribute.
Describe information stored with each attribute.
bool SetStringAttr(const QByteArray &attributeId, const QString &value)
Set instance of QString attribute.
virtual const IAttributeStaticInfo * GetAttributeInfo(const QByteArray &attributeId) const =0
Get set of attributes.
virtual void InsertValue(const Value &value)
Describe component attribute static information.
bool InsertMultiRef(const QByteArray &referenceId, IComponent *componentPtr, const QByteArray &subelementId="")
Set named reference to some component.
This interface provide static information about component meta info.
virtual const IRegistryElement & GetRegistryElement() const
Get access to component registry element object.
bool IsAttributeTypeCorrect(const QByteArray &attributeId)
Check if attribute type is corrected.
virtual AttributeInfo * GetAttributeInfo(const QByteArray &attributeId)
bool SetDoubleAttr(const QByteArray &attributeId, double value)
Set instance of double attribute.
void SetPtr(Type *ptr)
Set new value of internal pointer.
Definition: TDelPtr.h:140

© 2007-2017 Witold Gantzke and Kirill Lepskiy