TReferenceMember.h
Go to the documentation of this file.
1 #ifndef icomp_TReferenceMember_included
2 #define icomp_TReferenceMember_included
3 
4 
5 // ACF includes
6 #include <icomp/IComponent.h>
10 
11 
12 namespace icomp
13 {
14 
15 
20 template <class Interface>
22  public TAttributeMember<CReferenceAttribute>,
23  protected CInterfaceManipBase
24 {
25 public:
28  typedef Interface InterfaceType;
29 
31 
32  void Init(const IComponent* ownerPtr, const IRealAttributeStaticInfo& staticInfo);
33 
38  bool IsValid() const;
39 
44  bool EnsureInitialized() const;
45 
49  Interface* GetPtr() const;
50 
54  Interface* operator->() const;
55 
56 protected:
58 
59 private:
60  const IComponent* m_definitionComponentPtr;
61 
62  mutable Interface* m_componentPtr;
63  mutable bool m_isInitialized;
64 };
65 
66 
67 // public methods
68 
69 template <class Interface>
71 : m_definitionComponentPtr(NULL), m_componentPtr(NULL), m_isInitialized(false)
72 {
73 }
74 
75 
76 template <class Interface>
78 {
79  BaseClass::InitInternal(ownerPtr, staticInfo, &m_definitionComponentPtr);
80 
81  m_componentPtr = NULL;
82 }
83 
84 
85 template <class Interface>
87 {
88  return EnsureInitialized();
89 }
90 
91 
92 template <class Interface>
94 {
95  if (!m_isInitialized && (m_definitionComponentPtr != NULL) && BaseClass::IsValid()){
96  const ICompositeComponent* parentPtr = m_definitionComponentPtr->GetParentComponent();
97  if (parentPtr != NULL){
98  const QByteArray& componentId = BaseClass::operator*();
99 
100  QByteArray baseId;
101  QByteArray subId;
102  BaseClass2::SplitId(componentId, baseId, subId);
103 
104  IComponent* componentPtr = parentPtr->GetSubcomponent(baseId);
105  if (componentPtr != NULL){
106  m_componentPtr = BaseClass2::ExtractInterface<Interface>(componentPtr, subId);
107  }
108 
109  m_isInitialized = true;
110  }
111  else{
112  qCritical("Component %s is defined, but definition component has no parent", BaseClass::operator*().constData());
113  }
114  }
115 
116  return (m_componentPtr != NULL);
117 }
118 
119 
120 template <class Interface>
122 {
123  EnsureInitialized();
124 
125  return m_componentPtr;
126 }
127 
128 
129 template <class Interface>
131 {
132  EnsureInitialized();
133  Q_ASSERT(m_componentPtr != NULL);
134 
135  return GetPtr();
136 }
137 
138 
139 // protected methods
140 
141 template <class Interface>
143 : BaseClass(ptr),
144  m_definitionComponentPtr(ptr.m_definitionComponentPtr),
145  m_componentPtr(ptr.m_componentPtr),
146  m_isInitialized(ptr.m_isInitialized)
147 {
148 }
149 
150 
151 } // namespace icomp
152 
153 
154 inline void operator*(const icomp::TReferenceMember<void>& /*ref*/)
155 {
156 }
157 
158 
159 template <class Interface>
160 inline Interface& operator*(const icomp::TReferenceMember<Interface>& ref)
161 {
162  return *ref.GetPtr();
163 }
164 
165 
166 #endif // !icomp_TReferenceMember_included
167 
168 
void Init(const IComponent *ownerPtr, const IRealAttributeStaticInfo &staticInfo)
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const =0
Get access to subcomponent using its ID.
Main component interface.
Definition: IComponent.h:31
Interface * operator->() const
Access to internal pointer.
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.
bool EnsureInitialized() const
Ensure that initlization process is closed.
Pointer to referenced component object.
void operator*(const icomp::TReferenceMember< void > &)
#define NULL
Definition: istd.h:64
Pointer to component attribute.
CInterfaceManipBase BaseClass2
Interface * GetPtr() const
Direct cccess to internal pointer.
TAttributeMember< CReferenceAttribute > BaseClass
Composite component interface.
bool IsValid() const
Check if this reference can be resolved.

© 2007-2017 Witold Gantzke and Kirill Lepskiy