TComponentCloneWrap.h
Go to the documentation of this file.
1 #ifndef icomp_TComponentCloneWrap_included
2 #define icomp_TComponentCloneWrap_included
3 
4 
5 #include <icomp/IComponent.h>
11 
12 
13 namespace icomp
14 {
15 
16 
17 template <class BaseClass>
18 class TComponentCloneWrap: virtual public BaseClass, protected CInterfaceManipBase
19 {
20 public:
21  // pseudo-reimplemented (istd::IChangeable)
23 };
24 
25 
26 // pseudo-reimplemented (istd::IChangeable)
27 
28 template <class BaseClass>
30 {
31  const IComponentContext* contextPtr = BaseClass::GetComponentContext();
32  if (contextPtr != NULL){
33  QByteArray contextId = contextPtr->GetContextId();
34 
35  const ICompositeComponent* parentComponentPtr = BaseClass::GetParentComponent();
36  if (parentComponentPtr != NULL){
38  // we have to check if our owner has a parent composite component.
39  // In this case we have to factorize not our component, but the complete parent composite component:
40  const CCompositeComponent* parentCompositeComponentPtr = dynamic_cast<const CCompositeComponent*>(parentComponentPtr->GetParentComponent());
41  if (parentCompositeComponentPtr != NULL){
42  const CCompositeComponentContext* parentContextPtr = dynamic_cast<const CCompositeComponentContext*>(parentCompositeComponentPtr->GetComponentContext());
43 
44  const IRegistry& registry = parentContextPtr->GetRegistry();
45  IRegistry::Ids elementIds = registry.GetElementIds();
46 
47  for (IRegistry::Ids::ConstIterator elemIter = elementIds.constBegin(); elemIter != elementIds.constEnd(); ++elemIter){
48  const icomp::ICompositeComponent* subComponentPtr = dynamic_cast<const icomp::ICompositeComponent*>(parentCompositeComponentPtr->GetSubcomponent(*elemIter));
49  if (subComponentPtr != NULL){
50  const icomp::IComponentContext* subComponentContextPtr = subComponentPtr->GetComponentContext();
51 
52  if ((subComponentPtr->GetSubcomponent(contextId) != NULL) && (subComponentContextPtr == parentComponentPtr->GetComponentContext())){
53  contextId = *elemIter;
54 
55  parentComponentPtr = parentCompositeComponentPtr;
56  break;
57  }
58  }
59  }
60  }
61  }
62 
64 
65  clonedPtr.SetCastedOrRemove(ExtractInterface<istd::IChangeable>(parentComponentPtr->CreateSubcomponent(contextId)));
66 
67  if (clonedPtr.IsValid()){
68  if (clonedPtr->CopyFrom(*this, mode)){
69  return clonedPtr.PopPtr();
70  }
71  }
72  }
73  }
74 
75  return NULL;
76 }
77 
78 
79 } // namespace icomp
80 
81 
82 #endif
83 
84 
External references are simple ignored.
Definition: IChangeable.h:197
CompatibilityMode
Control how relationship betweeen objects are interpreted.
Definition: IChangeable.h:186
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const =0
Get access to subcomponent using its ID.
bool IsValid() const
Check if internal pointer not NULL.
Definition: TPointerBase.h:136
virtual const IComponentContext * GetComponentContext() const =0
Get access to component context describing all application-specified component information loaded fro...
Interface representing information stored in component registry.
Definition: IRegistry.h:30
Provide session context of component.
virtual const QByteArray & GetContextId() const =0
Get ID of this component in the context tree.
Data of object are interpreted in context of external references.
Definition: IChangeable.h:208
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.
virtual const IComponentContext * GetComponentContext() const
Get access to component context describing all application-specified component information loaded fro...
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
#define NULL
Definition: istd.h:64
External references are part of object integrity.
Definition: IChangeable.h:202
QSet< QByteArray > Ids
Definition: IRegistry.h:33
virtual IComponent * GetSubcomponent(const QByteArray &componentId) const
Get access to subcomponent using its ID.
virtual Ids GetElementIds() const =0
Get ID list of existing elements.
Composite component interface.
virtual istd::IChangeable * CloneMe(istd::IChangeable::CompatibilityMode mode=istd::IChangeable::CM_WITHOUT_REFS) const
bool SetCastedOrRemove(SourceType *ptr)
Set internal pointer using casted pointer of other type.
Definition: TDelPtr.h:83

© 2007-2017 Witold Gantzke and Kirill Lepskiy