Skip to content
Snippets Groups Projects
Commit 4e4d5926 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

Fixed some more problems with the move sematics of EntityOwner/Module....

Fixed some more problems with the move sematics of EntityOwner/Module. Re-registration at the owner was missing and some things were done in the wrong place. Also the move assignment is now back again.
parent 78739f36
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,12 @@ namespace ChimeraTK {
ApplicationModule() : Module(nullptr, "invalid", "invalid ApplicationModule") {}
/** Move operation with the move constructor */
ApplicationModule(ApplicationModule &&other) : Module(std::move(other)) {}
ApplicationModule(ApplicationModule &&other) :
Module(other._owner, other._name, other._description, other._eliminateHierarchy, other._tags) {
assert(!moduleThread.joinable()); // if the thread is already running, moving is no longer allowed!
other._owner = nullptr;
other._name = "deleted";
}
/** Inherit assignment */
using Module::operator=;
......
......@@ -33,8 +33,14 @@ namespace ChimeraTK {
variables(std::move(other.variables))
{}
/** Inherit assignment */
using Module::operator=;
/** Move assignment */
ControlSystemModule& operator=(ControlSystemModule &&other) {
Module::operator=(std::move(other));
variableNamePrefix = std::move(other.variableNamePrefix);
subModules = std::move(other.subModules);
variables = std::move(other.variables);
return *this;
}
/** The function call operator returns a VariableNetworkNode which can be used in the Application::initialise()
* function to connect the control system variable with another variable. */
......
......@@ -35,9 +35,15 @@ namespace ChimeraTK {
registerNamePrefix(std::move(other.registerNamePrefix)),
subModules(std::move(other.subModules))
{}
/** Inherit assignment */
using Module::operator=;
/** Move assignment */
DeviceModule& operator=(DeviceModule &&other) {
Module::operator=(std::move(other));
deviceAliasOrURI = std::move(other.deviceAliasOrURI);
registerNamePrefix = std::move(other.registerNamePrefix);
subModules = std::move(other.subModules);
return *this;
}
/** The subscript operator returns a VariableNetworkNode which can be used in the Application::initialise()
* function to connect the register with another variable. */
......
......@@ -44,23 +44,9 @@ namespace ChimeraTK {
moduleList(std::move(other.moduleList)),
_eliminateHierarchy(other._eliminateHierarchy),
_tags(std::move(other._tags))
{}
/** Move operation with the assignment operator */
EntityOwner& operator=(EntityOwner &&other) {
_name = std::move(other._name);
_description = std::move(other._description);
_owner = std::move(other._owner);
accessorList = std::move(other.accessorList);
moduleList = std::move(other.moduleList);
_eliminateHierarchy = other._eliminateHierarchy;
_tags = std::move(other._tags);
return *this;
{
other._owner = nullptr;
}
/** Delete other assignment operators */
EntityOwner& operator=(EntityOwner &other) = delete;
EntityOwner& operator=(const EntityOwner &other) = delete;
/** Get the name of the module instance */
const std::string& getName() const { return _name; }
......
......@@ -36,11 +36,33 @@ namespace ChimeraTK {
/** Destructor */
virtual ~Module();
/** Move operation with the move constructor */
Module(Module &&rhs) : EntityOwner(std::move(rhs)) {}
/** Move constructor */
Module(Module &&other)
: EntityOwner(std::move(other))
{
_owner->unregisterModule(&other);
_owner->registerModule(this);
other._owner = nullptr;
}
Module& operator=(Module &&other) {
_name = std::move(other._name);
_description = std::move(other._description);
_owner = other._owner;
_owner->unregisterModule(&other);
_owner->registerModule(this);
other._owner = nullptr;
accessorList = std::move(other.accessorList);
moduleList = std::move(other.moduleList);
_eliminateHierarchy = other._eliminateHierarchy;
_tags = std::move(other._tags);
return *this;
}
/** Inherit assignment */
using EntityOwner::operator=;
/** Delete other assignment operators */
Module& operator=(Module &other) = delete;
Module& operator=(const Module &other) = delete;
/** Prepare the execution of the module. This function is called before any module is started (including internal
* modules like FanOuts) and before the initial values of the variables are pushed into the queues. */
......
......@@ -38,7 +38,11 @@ namespace ChimeraTK {
ModuleGroup() : Module(nullptr, "invalid", "invalid VariableGroup") {}
/** Move operation with the move constructor */
ModuleGroup(ModuleGroup &&other) : Module(std::move(other)) {}
ModuleGroup(ModuleGroup &&other) :
Module(other._owner, other._name, other._description, other._eliminateHierarchy, other._tags) {
other._owner = nullptr;
other._name = "deleted";
}
/** Inherit assignment */
using Module::operator=;
......
......@@ -43,7 +43,11 @@ namespace ChimeraTK {
virtual ~VariableGroup() {};
/** Move operation with the move constructor */
VariableGroup(VariableGroup &&other) : Module(std::move(other)) {}
VariableGroup(VariableGroup &&other) :
Module(other._owner, other._name, other._description, other._eliminateHierarchy, other._tags) {
other._owner = nullptr;
other._name = "deleted";
}
/** Inherit assignment */
using Module::operator=;
......
......@@ -29,7 +29,7 @@ namespace ChimeraTK {
Module& ControlSystemModule::operator[](const std::string& moduleName) const {
if(subModules.count(moduleName) == 0) {
subModules.emplace(std::pair<std::string, ControlSystemModule>(moduleName, ControlSystemModule(variableNamePrefix/moduleName)));
subModules[moduleName] = {variableNamePrefix/moduleName};
}
return subModules[moduleName];
}
......
......@@ -29,7 +29,7 @@ namespace ChimeraTK {
Module& DeviceModule::operator[](const std::string& moduleName) const {
if(subModules.count(moduleName) == 0) {
subModules.emplace(std::pair<std::string, DeviceModule>(moduleName, DeviceModule(deviceAliasOrURI, registerNamePrefix/moduleName)));
subModules[moduleName] = {deviceAliasOrURI, registerNamePrefix/moduleName};
}
return subModules[moduleName];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment