TMultiReferenceMember.h
Go to the documentation of this file.
1 #ifndef icomp_TMultiReferenceMember_included
2 #define icomp_TMultiReferenceMember_included
3 
4 
5 // ACF includes
9 
10 
11 namespace icomp
12 {
13 
14 
19 template <class Interface>
20 class TMultiReferenceMember: public TMultiAttributeMember<CMultiReferenceAttribute>, public CInterfaceManipBase
21 {
22 public:
25  typedef Interface InterfaceType;
26 
28 
29  void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
30 
35  bool IsValid() const;
36 
41  bool EnsureInitialized() const;
42 
47  Interface* operator[](int index) const;
48 
49 protected:
51 
52 private:
53  const IComponent* m_definitionComponentPtr;
54 
55  typedef QVector<Interface*> Components;
56  mutable Components m_components;
57  mutable bool m_isInitialized;
58 };
59 
60 
61 // public methods
62 
63 template <class Interface>
65 : m_definitionComponentPtr(NULL), m_isInitialized(false)
66 {
67 }
68 
69 
70 template <class Interface>
72 {
73  BaseClass::InitInternal(ownerPtr, staticInfo, &m_definitionComponentPtr);
74 
75  m_components.clear();
76 }
77 
78 
79 template <class Interface>
81 {
82  return EnsureInitialized();
83 }
84 
85 
86 template <class Interface>
88 {
89  if (!m_isInitialized && (m_definitionComponentPtr != NULL) && BaseClass::IsValid()){
90  const ICompositeComponent* parentPtr = m_definitionComponentPtr->GetParentComponent();
91  if (parentPtr != NULL){
92  int attributesCount = BaseClass::GetCount();
93 
94  m_components.resize(attributesCount);
95 
96  for (int i = 0; i < attributesCount; ++i){
97  const QByteArray& componentId = BaseClass::operator[](i);
98 
99  QByteArray baseId;
100  QByteArray subId;
101  BaseClass2::SplitId(componentId, baseId, subId);
102 
103  IComponent* componentPtr = parentPtr->GetSubcomponent(baseId);
104 
105  m_components[i] = BaseClass2::ExtractInterface<Interface>(componentPtr, subId);
106  }
107 
108  m_isInitialized = true;
109  }
110  else{
111  qCritical("Components are is defined, but definition component has no parent");
112  }
113  }
114 
115  return m_isInitialized;
116 }
117 
118 
119 template <class Interface>
121 {
122  Q_ASSERT(index >= 0);
123 
124  if (EnsureInitialized()){
125  Q_ASSERT(index < int(m_components.size()));
126 
127  return m_components[index];
128  }
129 
130  return NULL;
131 }
132 
133 
134 // protected methods
135 
136 template <class Interface>
138 : BaseClass(ptr),
139  m_definitionComponentPtr(ptr.m_definitionComponentPtr),
140  m_components(ptr.m_components),
141  m_isInitialized(ptr.m_isInitialized)
142 {
143 }
144 
145 
146 } // namespace icomp
147 
148 
149 #endif // !icomp_TMultiReferenceMember_included
150 
151 
bool IsValid() const
Check if this reference can be resolved.
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const =0
Get access to subcomponent using its ID.
Pointer to list of referenced component objects.
Main component interface.
Definition: IComponent.h:31
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< CMultiReferenceAttribute > BaseClass
Interface * operator[](int index) const
Access to interface of component at specified index.
#define NULL
Definition: istd.h:64
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
Composite component interface.
bool EnsureInitialized() const
Ensure that initlization process is closed.
Pointer to component attribute.

© 2007-2017 Witold Gantzke and Kirill Lepskiy