ICF
3.1.1.10
Technical documentation of ICF Libraries
Main Page
Topics
Namespaces
Classes
Files
File List
File Members
icomp
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
>
10
#include <
icomp/CInterfaceManipBase.h
>
11
#include <
icomp/CComponentContext.h
>
12
#include <
icomp/CCompositeComponent.h
>
13
#include <
icomp/CCompositeComponentContext.h
>
14
#include <
icomp/CSimComponentContextBase.h
>
15
16
17
namespace
icomp
18
{
19
20
21
template
<
class
Base>
22
class
TComponentCloneWrap
:
virtual
public
Base,
protected
CInterfaceManipBase
23
{
24
public
:
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
37
template
<
class
Base>
38
std::unique_ptr<istd::IChangeable>
TComponentCloneWrap<Base>::CloneMe
(
istd::IChangeable::CompatibilityMode
mode)
const
39
{
40
const
IComponentContext
* contextPtr = Base::GetComponentContext();
41
if
(contextPtr !=
nullptr
) {
42
QByteArray contextId = contextPtr->
GetContextId
();
43
44
if
(
const
ICompositeComponent
* parentComponentPtr = Base::GetParentComponent()) {
45
if
((mode ==
istd::IChangeable::CM_WITH_REFS
) || (mode ==
istd::IChangeable::CM_CONVERT
)) {
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
CComponentContext.h
CCompositeComponent.h
CCompositeComponentContext.h
CInterfaceManipBase.h
CSimComponentContextBase.h
IComponent.h
icomp::CCompositeComponentContext
Definition
CCompositeComponentContext.h:22
icomp::CCompositeComponent
Definition
CCompositeComponent.h:32
icomp::CInterfaceManipBase
Definition
CInterfaceManipBase.h:24
icomp::IComponentContext
Provide session context of component.
Definition
IComponentContext.h:36
icomp::IComponentContext::GetContextId
virtual const QByteArray & GetContextId() const =0
Get ID of this component in the context tree.
icomp::ICompositeComponent
Composite component interface.
Definition
ICompositeComponent.h:23
icomp::IRegistry
Interface representing information stored in component registry.
Definition
IRegistry.h:30
icomp::IRegistry::Ids
QSet< QByteArray > Ids
Definition
IRegistry.h:32
icomp::IRegistry::GetElementIds
virtual Ids GetElementIds() const =0
Get ID list of existing elements.
icomp::TComponentCloneWrap
Definition
TComponentCloneWrap.h:23
icomp::TComponentCloneWrap::BaseClass
Base BaseClass
Definition
TComponentCloneWrap.h:25
icomp::TComponentCloneWrap::CloneMe
std::unique_ptr< istd::IChangeable > CloneMe(istd::IChangeable::CompatibilityMode mode=istd::IChangeable::CM_WITHOUT_REFS) const override
Definition
TComponentCloneWrap.h:38
icomp::TComponentCloneWrap::TComponentCloneWrap
TComponentCloneWrap(Args &&... args)
Definition
TComponentCloneWrap.h:28
istd::IChangeable
Common interface for data model objects, which can be changed.
Definition
IChangeable.h:32
istd::IChangeable::CompatibilityMode
CompatibilityMode
Control how relationship betweeen objects are interpreted.
Definition
IChangeable.h:201
istd::IChangeable::CM_WITHOUT_REFS
@ CM_WITHOUT_REFS
External references are simple ignored.
Definition
IChangeable.h:211
istd::IChangeable::CM_WITH_REFS
@ CM_WITH_REFS
External references are part of object integrity.
Definition
IChangeable.h:216
istd::IChangeable::CM_CONVERT
@ CM_CONVERT
Data of object are interpreted in context of external references.
Definition
IChangeable.h:222
icomp
Package with interfaces and class used for components concept.
Definition
CBaseComponentStaticInfo.h:14
© Witold Gantzke and Kirill Lepskiy