ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
VariableGroup.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#include "VariableGroup.h"
5
6#include "ApplicationModule.h"
7#include "ModuleGroup.h"
8
9namespace ChimeraTK {
10
11 /********************************************************************************************************************/
12
13 VariableGroup::VariableGroup(VariableGroup* owner, const std::string& name, const std::string& description,
14 const std::unordered_set<std::string>& tags)
15 : Module(owner, name, description, tags) {
16 if(owner == nullptr) {
17 throw ChimeraTK::logic_error("VariableGroups: owner cannot be nullptr!");
18 }
19 if(owner->getModel().isValid()) {
20 _model = owner->getModel().add(*this);
21 }
22 else if(dynamic_cast<ApplicationModule*>(owner) && dynamic_cast<ApplicationModule*>(owner)->getModel().isValid()) {
23 _model = dynamic_cast<ApplicationModule*>(owner)->getModel().add(*this);
24 }
25 }
26
27 /********************************************************************************************************************/
28
29 VariableGroup::VariableGroup(ModuleGroup* owner, const std::string& name, const std::string& description,
30 const std::unordered_set<std::string>& tags)
31 : Module(owner, name, description, tags) {
32 // Not registering with model - this constructor will only be used in the special case of Application owning an
33 // ApplicationModule
34 }
35
36 /********************************************************************************************************************/
37
39 // Keep the model as is (except from updating the pointers to the C++ objects). To do so, we have to hide it from
40 // unregisterModule() which is executed in Module::operator=(), because it would destroy the model.
41 ChimeraTK::Model::VariableGroupProxy model = std::move(other._model);
42 other._model = {};
43
44 Module::operator=(std::move(other));
45
46 if(model.isValid()) {
47 model.informMove(*this);
48 }
49 _model = model;
50
51 return *this;
52 }
53
54 /********************************************************************************************************************/
55
59
60 /********************************************************************************************************************/
61
64 if(_model.isValid()) {
65 auto* vg = dynamic_cast<VariableGroup*>(module);
66 if(!vg) {
67 // during destruction unregisterModule is called from the base class destructor where the dynamic_cast already
68 // fails.
69 return;
70 }
71 _model.remove(*vg);
72 }
73 }
74
75 /********************************************************************************************************************/
76
77} /* namespace ChimeraTK */
virtual void unregisterModule(Module *module)
Unregister another module as a sub-module.
bool isValid() const
Check if the model is valid.
Definition Model.cc:31
std::string getFullyQualifiedPath() const
Return the fully qualified path.
Definition Model.cc:25
void remove(VariableGroup &module)
Definition Model.cc:288
VariableGroupProxy add(VariableGroup &module)
Definition Model.cc:276
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition Module.h:21
Module & operator=(Module &&other) noexcept
Move assignment operator.
Definition Module.cc:31
ChimeraTK::Model::VariableGroupProxy _model
std::string getVirtualQualifiedName() const override
VariableGroup & operator=(VariableGroup &&other) noexcept
Move assignment.
ChimeraTK::Model::VariableGroupProxy getModel()
Return the application model proxy representing this module.
void unregisterModule(Module *module) override
Unregister another module as a sub-module.
VariableGroup()=default
Default constructor: Allows late initialisation of VariableGroups (e.g.
InvalidityTracer application module.