ICF 3.1.1.10
Technical documentation of ICF Libraries
TComponentCloneWrap.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9#include <icomp/IComponent.h>
15
16
17namespace icomp
18{
19
20
21template <class Base>
22class TComponentCloneWrap: virtual public Base, protected CInterfaceManipBase
23{
24public:
25 typedef Base BaseClass;
26
27 template<typename... Args>
28 TComponentCloneWrap(Args&&... args): BaseClass(args...){}
29
30 // pseudo-reimplemented (istd::IChangeable)
31 std::unique_ptr<istd::IChangeable> CloneMe(istd::IChangeable::CompatibilityMode mode = istd::IChangeable::CM_WITHOUT_REFS) const override;
32};
33
34
35// pseudo-reimplemented (istd::IChangeable)
36
37template <class Base>
39{
40 const IComponentContext* contextPtr = Base::GetComponentContext();
41 if (contextPtr != nullptr) {
42 QByteArray contextId = contextPtr->GetContextId();
43
44 if (const ICompositeComponent* parentComponentPtr = Base::GetParentComponent()) {
46 // we have to check if our owner has a parent composite component.
47 // In this case we have to factorize not our component, but the complete parent composite component:
48 if (const auto* parentCompositeComponentPtr = dynamic_cast<const CCompositeComponent*>(parentComponentPtr->GetParentComponent())) {
49 const auto* parentContextPtr = dynamic_cast<const CCompositeComponentContext*>(parentCompositeComponentPtr->GetComponentContext());
50
51 const IRegistry& registry = parentContextPtr->GetRegistry();
52 IRegistry::Ids elementIds = registry.GetElementIds();
53
54 for (IRegistry::Ids::const_iterator elemIter = elementIds.constBegin(); elemIter != elementIds.constEnd(); ++elemIter){
55 const auto* subComponentPtr = dynamic_cast<const ICompositeComponent*>(parentCompositeComponentPtr->GetSubcomponent(*elemIter));
56 if (subComponentPtr != nullptr){
57 const IComponentContext* subComponentContextPtr = subComponentPtr->GetComponentContext();
58
59 if ((subComponentPtr->GetSubcomponent(contextId) != nullptr) && (subComponentContextPtr == parentComponentPtr->GetComponentContext())){
60 contextId = *elemIter;
61
62 parentComponentPtr = parentCompositeComponentPtr;
63 break;
64 }
65 }
66 }
67 }
68 }
69
70 auto subComponentPtr = parentComponentPtr->CreateSubcomponent(contextId);
71
72 if (istd::IChangeable* clonedPtr = ExtractInterface<istd::IChangeable>(subComponentPtr.get())) {
73 if (clonedPtr->CopyFrom(*this, mode)) {
74 subComponentPtr.release();
75
76 return std::unique_ptr<istd::IChangeable>(clonedPtr);
77 }
78 }
79 }
80 }
81
82 return nullptr;
83}
84
85
86} // namespace icomp
87
88
Provide session context of component.
virtual const QByteArray & GetContextId() const =0
Get ID of this component in the context tree.
Composite component interface.
Interface representing information stored in component registry.
Definition IRegistry.h:30
QSet< QByteArray > Ids
Definition IRegistry.h:32
virtual Ids GetElementIds() const =0
Get ID list of existing elements.
std::unique_ptr< istd::IChangeable > CloneMe(istd::IChangeable::CompatibilityMode mode=istd::IChangeable::CM_WITHOUT_REFS) const override
Common interface for data model objects, which can be changed.
Definition IChangeable.h:32
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
@ CM_WITH_REFS
External references are part of object integrity.
@ CM_CONVERT
Data of object are interpreted in context of external references.
Package with interfaces and class used for components concept.

© Witold Gantzke and Kirill Lepskiy