TMultiFactoryMember.h
Go to the documentation of this file.
1 #ifndef icomp_TMultiFactoryMember_included
2 #define icomp_TMultiFactoryMember_included
3 
4 
5 // ACF includes
6 #include <istd/TDelPtr.h>
7 
11 
12 
13 namespace icomp
14 {
15 
16 
21 template <class Interface>
22 class TMultiFactoryMember: public TMultiAttributeMember<CMultiFactoryAttribute>, public CInterfaceManipBase
23 {
24 public:
27  typedef Interface InterfaceType;
28 
30 
31  void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
32 
37  bool IsValid() const;
38 
42  IComponent* CreateComponent(int index) const;
43 
49  Interface* CreateInstance(int index) const;
50 
61  static Interface* ExtractInterface(IComponent* componentPtr, const QByteArray& subId = "");
62 
63 protected:
65 
66 private:
67  const IComponent* m_definitionComponentPtr;
68 };
69 
70 
71 // public methods
72 
73 template <class Interface>
75 : m_definitionComponentPtr(NULL)
76 {
77 }
78 
79 
80 template <class Interface>
82 {
83  BaseClass::InitInternal(ownerPtr, staticInfo, &m_definitionComponentPtr);
84 }
85 
86 
87 template <class Interface>
89 {
90  return (m_definitionComponentPtr != NULL) && BaseClass::IsValid();
91 }
92 
93 
94 
95 template <class Interface>
97 {
98  if ((m_definitionComponentPtr != NULL) && BaseClass::IsValid()){
99  const ICompositeComponent* parentPtr = m_definitionComponentPtr->GetParentComponent();
100  if (parentPtr != NULL){
101  const QByteArray& componentId = BaseClass::operator[](index);
102 
103  QByteArray baseId;
104  QByteArray subId;
105  BaseClass2::SplitId(componentId, baseId, subId);
106  Q_ASSERT(subId.isEmpty()); // explicit subelement ID are not implemented correctly
107 
108  return parentPtr->CreateSubcomponent(baseId);
109  }
110  else{
111  qCritical("Component %s is defined, but definition component has no parent", BaseClass::operator[](index).constData());
112  }
113  }
114 
115  return NULL;
116 }
117 
118 
119 template <class Interface>
121 {
122  istd::TDelPtr<IComponent> newComponentPtr(CreateComponent(index));
123  if (newComponentPtr.IsValid()){
124  Interface* retVal = BaseClass2::ExtractInterface<Interface>(newComponentPtr.GetPtr());
125  if (retVal != NULL){
126  newComponentPtr.PopPtr();
127 
128  return retVal;
129  }
130  }
131 
132  return NULL;
133 }
134 
135 
136 // static methods
137 
138 template <class Interface>
139 Interface* TMultiFactoryMember<Interface>::ExtractInterface(IComponent* componentPtr, const QByteArray& subId)
140 {
141  return BaseClass2::ExtractInterface<Interface>(componentPtr, subId);
142 }
143 
144 
145 // protected methods
146 
147 template <class Interface>
149 : BaseClass(ptr),
150  m_definitionComponentPtr(ptr.m_definitionComponentPtr)
151 {
152 }
153 
154 
155 } // namespace icomp
156 
157 
158 #endif // !icomp_TMultiFactoryMember_included
159 
160 
IComponent * CreateComponent(int index) const
Create component for specified index without extracting any interface.
bool IsValid() const
Check if internal pointer not NULL.
Definition: TPointerBase.h:136
Main component interface.
Definition: IComponent.h:31
Type * PopPtr()
Reset internal pointer value without deleting instance and return previos value.
Definition: TDelPtr.h:149
virtual IComponent * CreateSubcomponent(const QByteArray &componentId) const =0
Create instance of subcomponent using its ID.
virtual const ICompositeComponent * GetParentComponent(bool ownerOnly=false) const =0
Get parent of this component.
Interface adding to attribute static info functionality existing only for real attributes.
TMultiAttributeMember< CMultiFactoryAttribute > BaseClass
bool IsValid() const
Check if this factory can be resolved.
Type * GetPtr() const
Return access to internal stored pointer.
Definition: TPointerBase.h:129
#define NULL
Definition: istd.h:64
CInterfaceManipBase BaseClass2
Factory of components used as component member.
Composite component interface.
static Interface * ExtractInterface(IComponent *componentPtr, const QByteArray &subId="")
Extract interface from some component.
Interface * CreateInstance(int index) const
Create instance of interface for specified index.
Pointer wrapper providing automatic deleting pointed object during destruction.
Definition: TDelPtr.h:20
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
Pointer to component attribute.

© 2007-2017 Witold Gantzke and Kirill Lepskiy